Mercurial > vim
annotate src/ex_getln.c @ 17779:87a8760babec v8.1.1886
patch 8.1.1886: command line expansion code is spread out
commit https://github.com/vim/vim/commit/66b51420e0c8d49bcf6786b792c938d6099e3393
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 18 21:44:12 2019 +0200
patch 8.1.1886: command line expansion code is spread out
Problem: Command line expansion code is spread out.
Solution: Move the code to cmdexpand.c. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4831)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Aug 2019 21:45:03 +0200 |
parents | 9efb4dda9720 |
children | 04245f071792 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9990
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 * ex_getln.c: Functions for entering and editing an Ex command line. | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
14548
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
16 #ifndef MAX |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
17 # define MAX(x,y) ((x) > (y) ? (x) : (y)) |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
18 #endif |
806e1a2648c6
patch 8.1.0287: MAX is not defined everywhere
Christian Brabandt <cb@256bit.org>
parents:
14546
diff
changeset
|
19 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
20 // The current cmdline_info. It is initialized in getcmdline() and after that |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
21 // used by other functions. When invoking getcmdline() recursively it needs |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
22 // to be saved with save_cmdline() and restored with restore_cmdline(). |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
23 static cmdline_info_T ccline; |
7 | 24 |
25 #ifdef FEAT_EVAL | |
26 static int new_cmdpos; /* position set by set_cmdline_pos() */ | |
27 #endif | |
28 | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
29 static int extra_char = NUL; /* extra character to display when redrawing |
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
30 * the command line */ |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
31 static int extra_char_shift; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
32 |
7 | 33 #ifdef FEAT_RIGHTLEFT |
34 static int cmd_hkmap = 0; /* Hebrew mapping during command line */ | |
35 #endif | |
36 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
37 static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
38 static int cmdline_charsize(int idx); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
39 static void set_cmdspos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
40 static void set_cmdspos_cursor(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
41 static void correct_cmdspos(int idx, int cells); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
42 static void alloc_cmdbuff(int len); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
43 static void draw_cmdline(int start, int len); |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
44 static void save_cmdline(cmdline_info_T *ccp); |
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
45 static void restore_cmdline(cmdline_info_T *ccp); |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
46 static int cmdline_paste(int regname, int literally, int remcr); |
7 | 47 #ifdef FEAT_WILDMENU |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
48 static void cmdline_del(int from); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
49 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
50 static void redrawcmdprompt(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
51 static int ccheck_abbr(int); |
7 | 52 |
53 #ifdef FEAT_CMDWIN | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
54 static int open_cmdwin(void); |
7 | 55 #endif |
56 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
57 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
58 static void |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
59 trigger_cmd_autocmd(int typechar, int evt) |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
60 { |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
61 char_u typestr[2]; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
62 |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
63 typestr[0] = typechar; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
64 typestr[1] = NUL; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
65 apply_autocmds(evt, typestr, typestr, FALSE, curbuf); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
66 } |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
67 |
7 | 68 /* |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
69 * Abandon the command line. |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
70 */ |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
71 static void |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
72 abandon_cmdline(void) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
73 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
74 VIM_CLEAR(ccline.cmdbuff); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
75 if (msg_scrolled == 0) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
76 compute_cmdrow(); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
77 msg(""); |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
78 redraw_cmdline = TRUE; |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
79 } |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
80 |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13041
diff
changeset
|
81 #ifdef FEAT_SEARCH_EXTRA |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
82 /* |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
83 * Guess that the pattern matches everything. Only finds specific cases, such |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
84 * as a trailing \|, which can happen while typing a pattern. |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
85 */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
86 static int |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
87 empty_pattern(char_u *p) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
88 { |
13107
fe7d576a3d3f
patch 8.0.1428: compiler warning on 64 bit MS-Windows system
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
89 size_t n = STRLEN(p); |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
90 |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
91 /* remove trailing \v and the like */ |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
92 while (n >= 2 && p[n - 2] == '\\' |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
93 && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
94 n -= 2; |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
95 return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|'); |
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
96 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
97 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
98 // Struct to store the viewstate during 'incsearch' highlighting. |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
99 typedef struct { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
100 colnr_T vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
101 colnr_T vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
102 linenr_T vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
103 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
104 int vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
105 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
106 linenr_T vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
107 linenr_T vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
108 } viewstate_T; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
109 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
110 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
111 save_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
112 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
113 vs->vs_curswant = curwin->w_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
114 vs->vs_leftcol = curwin->w_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
115 vs->vs_topline = curwin->w_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
116 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
117 vs->vs_topfill = curwin->w_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
118 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
119 vs->vs_botline = curwin->w_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
120 vs->vs_empty_rows = curwin->w_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
121 } |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
122 |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
123 static void |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
124 restore_viewstate(viewstate_T *vs) |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
125 { |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
126 curwin->w_curswant = vs->vs_curswant; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
127 curwin->w_leftcol = vs->vs_leftcol; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
128 curwin->w_topline = vs->vs_topline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
129 # ifdef FEAT_DIFF |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
130 curwin->w_topfill = vs->vs_topfill; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
131 # endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
132 curwin->w_botline = vs->vs_botline; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
133 curwin->w_empty_rows = vs->vs_empty_rows; |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
134 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
135 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
136 // Struct to store the state of 'incsearch' highlighting. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
137 typedef struct { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
138 pos_T search_start; // where 'incsearch' starts searching |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
139 pos_T save_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
140 viewstate_T init_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
141 viewstate_T old_viewstate; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
142 pos_T match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
143 pos_T match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
144 int did_incsearch; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
145 int incsearch_postponed; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
146 int magic_save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
147 } incsearch_state_T; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
148 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
149 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
150 init_incsearch_state(incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
151 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
152 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
153 is_state->did_incsearch = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
154 is_state->incsearch_postponed = FALSE; |
14546
35e7ead872db
patch 8.1.0286: 'incsearch' does not apply to :smagic and :snomagic
Christian Brabandt <cb@256bit.org>
parents:
14544
diff
changeset
|
155 is_state->magic_save = p_magic; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
156 CLEAR_POS(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
157 is_state->save_cursor = curwin->w_cursor; // may be restored later |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
158 is_state->search_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
159 save_viewstate(&is_state->init_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
160 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
161 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
162 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
163 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
164 * First move cursor to end of match, then to the start. This |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
165 * moves the whole match onto the screen when 'nowrap' is set. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
166 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
167 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
168 set_search_match(pos_T *t) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
169 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
170 t->lnum += search_match_lines; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
171 t->col = search_match_endcol; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
172 if (t->lnum > curbuf->b_ml.ml_line_count) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
173 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
174 t->lnum = curbuf->b_ml.ml_line_count; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
175 coladvance((colnr_T)MAXCOL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
176 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
177 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
178 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
179 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
180 * Return TRUE when 'incsearch' highlighting is to be done. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
181 * Sets search_first_line and search_last_line to the address range. |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
182 * May change the last search pattern. |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
183 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
184 static int |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
185 do_incsearch_highlighting(int firstc, incsearch_state_T *is_state, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
186 int *skiplen, int *patlen) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
187 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
188 char_u *cmd; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
189 cmdmod_T save_cmdmod = cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
190 char_u *p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
191 int delim_optional = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
192 int delim; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
193 char_u *end; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
194 char *dummy; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
195 exarg_T ea; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
196 pos_T save_cursor; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
197 int use_last_pat; |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
198 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
199 *skiplen = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
200 *patlen = ccline.cmdlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
201 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
202 if (!p_is || cmd_silent) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
203 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
204 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
205 // by default search all lines |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
206 search_first_line = 0; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
207 search_last_line = MAXLNUM; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
208 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
209 if (firstc == '/' || firstc == '?') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
210 return TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
211 if (firstc != ':') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
212 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
213 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
214 vim_memset(&ea, 0, sizeof(ea)); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
215 ea.line1 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
216 ea.line2 = 1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
217 ea.cmd = ccline.cmdbuff; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
218 ea.addr_type = ADDR_LINES; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
219 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
220 parse_command_modifiers(&ea, &dummy, TRUE); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
221 cmdmod = save_cmdmod; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
222 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
223 cmd = skip_range(ea.cmd, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
224 if (vim_strchr((char_u *)"sgvl", *cmd) == NULL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
225 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
226 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
227 // Skip over "substitute" to find the pattern separator. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
228 for (p = cmd; ASCII_ISALPHA(*p); ++p) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
229 ; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
230 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
231 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
232 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
233 if (STRNCMP(cmd, "substitute", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
234 || STRNCMP(cmd, "smagic", p - cmd) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
235 || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
236 || STRNCMP(cmd, "vglobal", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
237 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
238 if (*cmd == 's' && cmd[1] == 'm') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
239 p_magic = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
240 else if (*cmd == 's' && cmd[1] == 'n') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
241 p_magic = FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
242 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
243 else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
244 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
245 // skip over flags |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
246 while (ASCII_ISALPHA(*(p = skipwhite(p)))) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
247 ++p; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
248 if (*p == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
249 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
250 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
251 else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
252 || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
253 || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
254 || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
255 || STRNCMP(cmd, "global", p - cmd) == 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
256 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
257 // skip over "!" |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
258 if (*p == '!') |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
259 { |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
260 p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
261 if (*skipwhite(p) == NUL) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
262 return FALSE; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
263 } |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
264 if (*cmd != 'g') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
265 delim_optional = TRUE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
266 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
267 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
268 return FALSE; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
269 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
270 p = skipwhite(p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
271 delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
272 end = skip_regexp(p, delim, p_magic, NULL); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
273 |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
274 use_last_pat = end == p && *end == delim; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
275 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
276 if (end == p && !use_last_pat) |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
277 return FALSE; |
14613
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
278 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
279 // Don't do 'hlsearch' highlighting if the pattern matches everything. |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
280 if (!use_last_pat) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
281 { |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
282 char c = *end; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
283 int empty; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
284 |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
285 *end = NUL; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
286 empty = empty_pattern(p); |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
287 *end = c; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
288 if (empty) |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
289 return FALSE; |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
290 } |
3f9b73cc8adb
patch 8.1.0320: too much 'incsearch' highlight for pat matching everything
Christian Brabandt <cb@256bit.org>
parents:
14565
diff
changeset
|
291 |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
292 // found a non-empty pattern or // |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
293 *skiplen = (int)(p - ccline.cmdbuff); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
294 *patlen = (int)(end - p); |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
295 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
296 // parse the address range |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
297 save_cursor = curwin->w_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
298 curwin->w_cursor = is_state->search_start; |
14760
fd69edd2c67e
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled
Christian Brabandt <cb@256bit.org>
parents:
14700
diff
changeset
|
299 parse_cmd_address(&ea, &dummy, TRUE); |
14565
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
300 if (ea.addr_count > 0) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
301 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
302 // Allow for reverse match. |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
303 if (ea.line2 < ea.line1) |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
304 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
305 search_first_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
306 search_last_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
307 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
308 else |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
309 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
310 search_first_line = ea.line1; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
311 search_last_line = ea.line2; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
312 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
313 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
314 else if (cmd[0] == 's' && cmd[1] != 'o') |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
315 { |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
316 // :s defaults to the current line |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
317 search_first_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
318 search_last_line = curwin->w_cursor.lnum; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
319 } |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
320 |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
321 curwin->w_cursor = save_cursor; |
5e038972cafa
patch 8.1.0296: command parsing for 'incsearch' is a bit ugly
Christian Brabandt <cb@256bit.org>
parents:
14563
diff
changeset
|
322 return TRUE; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
323 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
324 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
325 static void |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
326 finish_incsearch_highlighting( |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
327 int gotesc, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
328 incsearch_state_T *is_state, |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
329 int call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
330 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
331 if (is_state->did_incsearch) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
332 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
333 is_state->did_incsearch = FALSE; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
334 if (gotesc) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
335 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
336 else |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
337 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
338 if (!EQUAL_POS(is_state->save_cursor, is_state->search_start)) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
339 { |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
340 // put the '" mark at the original position |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
341 curwin->w_cursor = is_state->save_cursor; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
342 setpcmark(); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
343 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
344 curwin->w_cursor = is_state->search_start; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
345 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
346 restore_viewstate(&is_state->old_viewstate); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
347 highlight_match = FALSE; |
14652
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
348 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
349 // by default search all lines |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
350 search_first_line = 0; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
351 search_last_line = MAXLNUM; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
352 |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
353 p_magic = is_state->magic_save; |
f3b183c3d3e2
patch 8.1.0339: wrong highlight when 'incsearch' set and cancelling :s
Christian Brabandt <cb@256bit.org>
parents:
14615
diff
changeset
|
354 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
355 validate_cursor(); /* needed for TAB */ |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
356 redraw_all_later(SOME_VALID); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
357 if (call_update_screen) |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
358 update_screen(SOME_VALID); |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
359 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
360 } |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
361 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
362 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
363 * Do 'incsearch' highlighting if desired. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
364 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
365 static void |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
366 may_do_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
367 int firstc, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
368 long count, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
369 incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
370 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
371 int skiplen, patlen; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
372 int found; // do_search() result |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
373 pos_T end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
374 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
375 proftime_T tm; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
376 #endif |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
377 int next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
378 int use_last_pat; |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
379 int did_do_incsearch = is_state->did_incsearch; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
380 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
381 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
382 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
383 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
384 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
385 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
386 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
387 restore_last_search_pattern(); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
388 finish_incsearch_highlighting(FALSE, is_state, TRUE); |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
389 if (did_do_incsearch && vpeekc() == NUL) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
390 // may have skipped a redraw, do it now |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
391 redrawcmd(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
392 return; |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
393 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
394 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
395 // If there is a character waiting, search and redraw later. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
396 if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
397 { |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
398 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
399 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
400 return; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
401 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
402 is_state->incsearch_postponed = FALSE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
403 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
404 if (search_first_line == 0) |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
405 // start at the original cursor position |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
406 curwin->w_cursor = is_state->search_start; |
14976
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
407 else if (search_first_line > curbuf->b_ml.ml_line_count) |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
408 { |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
409 // start after the last line |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
410 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
411 curwin->w_cursor.col = MAXCOL; |
676db1b7fc35
patch 8.1.0499: :2vimgrep causes an ml_get error
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
412 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
413 else |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
414 { |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
415 // start at the first line in the range |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
416 curwin->w_cursor.lnum = search_first_line; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
417 curwin->w_cursor.col = 0; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
418 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
419 |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
420 // Use the previous pattern for ":s//". |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
421 next_char = ccline.cmdbuff[skiplen + patlen]; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
422 use_last_pat = patlen == 0 && skiplen > 0 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
423 && ccline.cmdbuff[skiplen - 1] == next_char; |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
424 |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
425 // If there is no pattern, don't do anything. |
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
426 if (patlen == 0 && !use_last_pat) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
427 { |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
428 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
429 set_no_hlsearch(TRUE); // turn off previous highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
430 redraw_all_later(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
431 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
432 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
433 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
434 int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
435 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
436 cursor_off(); // so the user knows we're busy |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
437 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
438 ++emsg_off; // so it doesn't beep if bad expr |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
439 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
440 // Set the time limit to half a second. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
441 profile_setlimit(500L, &tm); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
442 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
443 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
444 search_flags += SEARCH_KEEP; |
14524
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
445 if (search_first_line != 0) |
e36d6e01708c
patch 8.1.0275: 'incsearch' with :s doesn't start at cursor line
Christian Brabandt <cb@256bit.org>
parents:
14522
diff
changeset
|
446 search_flags += SEARCH_START; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
447 ccline.cmdbuff[skiplen + patlen] = NUL; |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
448 found = do_search(NULL, firstc == ':' ? '/' : firstc, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
449 ccline.cmdbuff + skiplen, count, search_flags, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
450 #ifdef FEAT_RELTIME |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
451 &tm, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
452 #else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
453 NULL, NULL |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
454 #endif |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
455 ); |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
456 ccline.cmdbuff[skiplen + patlen] = next_char; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
457 --emsg_off; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
458 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
459 if (curwin->w_cursor.lnum < search_first_line |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
460 || curwin->w_cursor.lnum > search_last_line) |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
461 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
462 // match outside of address range |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
463 found = 0; |
14542
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
464 curwin->w_cursor = is_state->search_start; |
116a01c73fd8
patch 8.1.0284: 'cursorline' highlighting wrong with 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14538
diff
changeset
|
465 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
466 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
467 // if interrupted while searching, behave like it failed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
468 if (got_int) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
469 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
470 (void)vpeekc(); // remove <C-C> from input stream |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
471 got_int = FALSE; // don't abandon the command line |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
472 found = 0; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
473 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
474 else if (char_avail()) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
475 // cancelled searching because a char was typed |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
476 is_state->incsearch_postponed = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
477 } |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
478 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
479 highlight_match = TRUE; // highlight position |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
480 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
481 highlight_match = FALSE; // remove highlight |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
482 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
483 // First restore the old curwin values, so the screen is positioned in the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
484 // same way as the actual search command. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
485 restore_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
486 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
487 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
488 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
489 if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
490 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
491 pos_T save_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
492 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
493 is_state->match_start = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
494 set_search_match(&curwin->w_cursor); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
495 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
496 end_pos = curwin->w_cursor; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
497 is_state->match_end = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
498 curwin->w_cursor = save_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
499 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
500 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
501 end_pos = curwin->w_cursor; // shutup gcc 4 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
502 |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
503 // Disable 'hlsearch' highlighting if the pattern matches everything. |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
504 // Avoids a flash when typing "foo\|". |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
505 if (!use_last_pat) |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
506 { |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
507 next_char = ccline.cmdbuff[skiplen + patlen]; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
508 ccline.cmdbuff[skiplen + patlen] = NUL; |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
509 if (empty_pattern(ccline.cmdbuff) && !no_hlsearch) |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
510 { |
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
511 redraw_all_later(SOME_VALID); |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
512 set_no_hlsearch(TRUE); |
14774
5e5f2d824189
patch 8.1.0399: 'hlsearch' highlight remains in other window
Christian Brabandt <cb@256bit.org>
parents:
14760
diff
changeset
|
513 } |
14615
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
514 ccline.cmdbuff[skiplen + patlen] = next_char; |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
515 } |
c6b41d47bac1
patch 8.1.0321: 'incsearch' regression: / highlights everything
Christian Brabandt <cb@256bit.org>
parents:
14613
diff
changeset
|
516 |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
517 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
518 // May redraw the status line to show the cursor position. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
519 if (p_ru && curwin->w_status_height > 0) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
520 curwin->w_redr_status = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
521 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
522 update_screen(SOME_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
523 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
524 |
14687
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
525 // Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
526 // end of the pattern, e.g. for ":s/pat/". |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
527 if (ccline.cmdbuff[skiplen + patlen] != NUL) |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
528 curwin->w_cursor = is_state->search_start; |
2982a54aa304
patch 8.1.0356: using :s with 'incsearch' prevents CTRL-R CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
14677
diff
changeset
|
529 else if (found != 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
530 curwin->w_cursor = end_pos; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
531 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
532 msg_starthere(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
533 redrawcmdline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
534 is_state->did_incsearch = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
535 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
536 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
537 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
538 * May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
539 * or previous match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
540 * Returns FAIL when jumping to cmdline_not_changed; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
541 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
542 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
543 may_adjust_incsearch_highlighting( |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
544 int firstc, |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
545 long count, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
546 incsearch_state_T *is_state, |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
547 int c) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
548 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
549 int skiplen, patlen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
550 pos_T t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
551 char_u *pat; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
552 int search_flags = SEARCH_NOOF; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
553 int i; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
554 int save; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
555 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
556 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
557 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
558 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
559 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
560 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
561 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
562 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
563 return OK; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
564 } |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
565 if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
566 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
567 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
568 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
569 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
570 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
571 if (firstc == ccline.cmdbuff[skiplen]) |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
572 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
573 pat = last_search_pattern(); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
574 skiplen = 0; |
14544
2b2d7ae42fb8
patch 8.1.0285: compiler warning for conversion
Christian Brabandt <cb@256bit.org>
parents:
14542
diff
changeset
|
575 patlen = (int)STRLEN(pat); |
14520
20866abc790b
patch 8.1.0273: invalid memory access when using 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
14515
diff
changeset
|
576 } |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
577 else |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
578 pat = ccline.cmdbuff + skiplen; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
579 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
580 cursor_off(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
581 out_flush(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
582 if (c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
583 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
584 t = is_state->match_end; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
585 if (LT_POS(is_state->match_start, is_state->match_end)) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
586 // Start searching at the end of the match not at the beginning of |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
587 // the next column. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
588 (void)decl(&t); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
589 search_flags += SEARCH_COL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
590 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
591 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
592 t = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
593 if (!p_hls) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
594 search_flags += SEARCH_KEEP; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
595 ++emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
596 save = pat[patlen]; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
597 pat[patlen] = NUL; |
15239
db5d2429bda3
patch 8.1.0629: "gn" selects the wrong text with a multi-line match
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
598 i = searchit(curwin, curbuf, &t, NULL, |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
599 c == Ctrl_G ? FORWARD : BACKWARD, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
600 pat, count, search_flags, |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
601 RE_SEARCH, 0, NULL, NULL); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
602 --emsg_off; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
603 pat[patlen] = save; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
604 if (i) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
605 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
606 is_state->search_start = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
607 is_state->match_end = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
608 is_state->match_start = t; |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
609 if (c == Ctrl_T && firstc != '?') |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
610 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
611 // Move just before the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
612 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
613 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
614 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
615 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
616 else if (c == Ctrl_G && firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
617 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
618 // Move just after the current match, so that when nv_search |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
619 // finishes the cursor will be put back on the match. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
620 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
621 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
622 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
623 if (LT_POS(t, is_state->search_start) && c == Ctrl_G) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
624 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
625 // wrap around |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
626 is_state->search_start = t; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
627 if (firstc == '?') |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
628 (void)incl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
629 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
630 (void)decl(&is_state->search_start); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
631 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
632 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
633 set_search_match(&is_state->match_end); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
634 curwin->w_cursor = is_state->match_start; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
635 changed_cline_bef_curs(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
636 update_topline(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
637 validate_cursor(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
638 highlight_match = TRUE; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
639 save_viewstate(&is_state->old_viewstate); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
640 update_screen(NOT_VALID); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
641 redrawcmdline(); |
17411
9c4ddc78df74
patch 8.1.1704: C-R C-W does not work after C-G when using 'incsearch'
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
642 curwin->w_cursor = is_state->match_end; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
643 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
644 else |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
645 vim_beep(BO_ERROR); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
646 restore_last_search_pattern(); |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
647 return FAIL; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
648 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
649 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
650 /* |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
651 * When CTRL-L typed: add character from the match to the pattern. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
652 * May set "*c" to the added character. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
653 * Return OK when jumping to cmdline_not_changed. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
654 */ |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
655 static int |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
656 may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
657 { |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
658 int skiplen, patlen; |
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
659 |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
660 // Parsing range may already set the last search pattern. |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
661 // NOTE: must call restore_last_search_pattern() before returning! |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
662 save_last_search_pattern(); |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
663 |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
664 if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen)) |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
665 { |
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
666 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
667 return FAIL; |
14677
7771a1ff8b99
patch 8.1.0351: 'incsearch' for :/foo/s//<Esc> changes last search pattern
Christian Brabandt <cb@256bit.org>
parents:
14652
diff
changeset
|
668 } |
15083
70aa5caa9f0d
patch 8.1.0552: saved last search pattern may not be restored
Bram Moolenaar <Bram@vim.org>
parents:
15064
diff
changeset
|
669 restore_last_search_pattern(); |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
670 |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
671 // Add a character from under the cursor for 'incsearch'. |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
672 if (is_state->did_incsearch) |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
673 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
674 curwin->w_cursor = is_state->match_end; |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
675 *c = gchar_cursor(); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
676 if (*c != NUL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
677 { |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
678 // If 'ignorecase' and 'smartcase' are set and the |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
679 // command line has no uppercase characters, convert |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
680 // the character to lowercase. |
14515
3648e74dd523
patch 8.1.0271: 'incsearch' doesn't work for :s, :g or :v
Christian Brabandt <cb@256bit.org>
parents:
14503
diff
changeset
|
681 if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen)) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
682 *c = MB_TOLOWER(*c); |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
683 if (*c == firstc || vim_strchr((char_u *)( |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
684 p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
685 { |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
686 // put a backslash before special characters |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
687 stuffcharReadbuff(*c); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
688 *c = '\\'; |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
689 } |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
690 // add any composing characters |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
691 if (mb_char2len(*c) != mb_ptr2len(ml_get_cursor())) |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
692 { |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
693 int save_c = *c; |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
694 |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
695 while (mb_char2len(*c) != mb_ptr2len(ml_get_cursor())) |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15083
diff
changeset
|
696 { |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
697 curwin->w_cursor.col += mb_char2len(*c); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
698 *c = gchar_cursor(); |
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
699 stuffcharReadbuff(*c); |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15083
diff
changeset
|
700 } |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
701 *c = save_c; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
702 } |
16287
a6cffc232b9d
patch 8.1.1148: CTRL-L with 'incsearch' does not pick up char under cursor
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
703 return FAIL; |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
704 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
705 } |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
706 return OK; |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
707 } |
13794
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
708 #endif |
530a6b894ae2
patch 8.0.1769: repeated saving and restoring viewstate for 'incsearch'
Christian Brabandt <cb@256bit.org>
parents:
13792
diff
changeset
|
709 |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
710 #ifdef FEAT_ARABIC |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
711 /* |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
712 * Return TRUE if the command line has an Arabic character at or after "start" |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
713 * for "len" bytes. |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
714 */ |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
715 static int |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
716 cmdline_has_arabic(int start, int len) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
717 { |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
718 int j; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
719 int mb_l; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
720 int u8c; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
721 char_u *p; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
722 int u8cc[MAX_MCO]; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
723 |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
724 if (!enc_utf8) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
725 return FALSE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
726 |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
727 for (j = start; j < start + len; j += mb_l) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
728 { |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
729 p = ccline.cmdbuff + j; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
730 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
731 mb_l = utfc_ptr2len_len(p, start + len - j); |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
732 if (ARABIC_CHAR(u8c)) |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
733 return TRUE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
734 } |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
735 return FALSE; |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
736 } |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
737 #endif |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
738 |
14858
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
739 void |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
740 cmdline_init(void) |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
741 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
742 vim_memset(&ccline, 0, sizeof(cmdline_info_T)); |
14858
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
743 } |
49b3bdf774ad
patch 8.1.0441: build failure without command line history
Christian Brabandt <cb@256bit.org>
parents:
14854
diff
changeset
|
744 |
13035
89e191a2a8a7
patch 8.0.1393: too much highlighting with 'hlsearch' and 'incsearch' set
Christian Brabandt <cb@256bit.org>
parents:
12960
diff
changeset
|
745 /* |
7 | 746 * getcmdline() - accept a command line starting with firstc. |
747 * | |
748 * firstc == ':' get ":" command line. | |
749 * firstc == '/' or '?' get search pattern | |
750 * firstc == '=' get expression | |
751 * firstc == '@' get text for input() function | |
752 * firstc == '>' get text for debug mode | |
753 * firstc == NUL get text for :insert command | |
754 * firstc == -1 like NUL, and break on CTRL-C | |
755 * | |
756 * The line is collected in ccline.cmdbuff, which is reallocated to fit the | |
757 * command line. | |
758 * | |
759 * Careful: getcmdline() can be called recursively! | |
760 * | |
761 * Return pointer to allocated string if there is a commandline, NULL | |
762 * otherwise. | |
763 */ | |
764 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
765 getcmdline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
766 int firstc, |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
767 long count, // only used for incremental search |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
768 int indent, // indent for inside conditionals |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
769 int do_concat UNUSED) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
770 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
771 return getcmdline_int(firstc, count, indent, TRUE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
772 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
773 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
774 static char_u * |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
775 getcmdline_int( |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
776 int firstc, |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
777 long count UNUSED, // only used for incremental search |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
778 int indent, // indent for inside conditionals |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
779 int init_ccline) // clear ccline first |
7 | 780 { |
781 int c; | |
782 int i; | |
783 int j; | |
784 int gotesc = FALSE; /* TRUE when <ESC> just typed */ | |
785 int do_abbr; /* when TRUE check for abbr. */ | |
786 char_u *lookfor = NULL; /* string to match */ | |
787 int hiscnt; /* current history line in use */ | |
788 int histype; /* history type to be used */ | |
789 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
790 incsearch_state_T is_state; |
7 | 791 #endif |
792 int did_wild_list = FALSE; /* did wild_list() recently */ | |
793 int wim_index = 0; /* index in wim_flags[] */ | |
794 int res; | |
795 int save_msg_scroll = msg_scroll; | |
796 int save_State = State; /* remember State when called */ | |
797 int some_key_typed = FALSE; /* one of the keys was typed */ | |
798 #ifdef FEAT_MOUSE | |
799 /* mouse drag and release events are ignored, unless they are | |
800 * preceded with a mouse down event */ | |
801 int ignore_drag_release = TRUE; | |
802 #endif | |
803 #ifdef FEAT_EVAL | |
804 int break_ctrl_c = FALSE; | |
805 #endif | |
806 expand_T xpc; | |
807 long *b_im_ptr = NULL; | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
808 cmdline_info_T save_ccline; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
809 int did_save_ccline = FALSE; |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
810 int cmdline_type; |
7 | 811 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
812 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
813 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
814 // Being called recursively. Since ccline is global, we need to save |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
815 // the current buffer and restore it when returning. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
816 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
817 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
818 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
819 if (init_ccline) |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
820 vim_memset(&ccline, 0, sizeof(cmdline_info_T)); |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
821 |
7 | 822 #ifdef FEAT_EVAL |
823 if (firstc == -1) | |
824 { | |
825 firstc = NUL; | |
826 break_ctrl_c = TRUE; | |
827 } | |
828 #endif | |
829 #ifdef FEAT_RIGHTLEFT | |
830 /* start without Hebrew mapping for a command line */ | |
831 if (firstc == ':' || firstc == '=' || firstc == '>') | |
832 cmd_hkmap = 0; | |
833 #endif | |
834 | |
835 ccline.overstrike = FALSE; /* always start in insert mode */ | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
836 |
7 | 837 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
838 init_incsearch_state(&is_state); |
7 | 839 #endif |
840 | |
841 /* | |
842 * set some variables for redrawcmd() | |
843 */ | |
844 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | |
164 | 845 ccline.cmdindent = (firstc > 0 ? indent : 0); |
846 | |
847 /* alloc initial ccline.cmdbuff */ | |
848 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
7 | 849 if (ccline.cmdbuff == NULL) |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
850 goto theend; // out of memory |
7 | 851 ccline.cmdlen = ccline.cmdpos = 0; |
852 ccline.cmdbuff[0] = NUL; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
853 sb_text_start_cmdline(); |
7 | 854 |
164 | 855 /* autoindent for :insert and :append */ |
856 if (firstc <= 0) | |
857 { | |
6929 | 858 vim_memset(ccline.cmdbuff, ' ', indent); |
164 | 859 ccline.cmdbuff[indent] = NUL; |
860 ccline.cmdpos = indent; | |
861 ccline.cmdspos = indent; | |
862 ccline.cmdlen = indent; | |
863 } | |
864 | |
7 | 865 ExpandInit(&xpc); |
1718 | 866 ccline.xpc = &xpc; |
7 | 867 |
868 #ifdef FEAT_RIGHTLEFT | |
869 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
870 && (firstc == '/' || firstc == '?')) | |
871 cmdmsg_rl = TRUE; | |
872 else | |
873 cmdmsg_rl = FALSE; | |
874 #endif | |
875 | |
876 redir_off = TRUE; /* don't redirect the typed command */ | |
877 if (!cmd_silent) | |
878 { | |
879 i = msg_scrolled; | |
880 msg_scrolled = 0; /* avoid wait_return message */ | |
881 gotocmdline(TRUE); | |
882 msg_scrolled += i; | |
883 redrawcmdprompt(); /* draw prompt or indent */ | |
884 set_cmdspos(); | |
885 } | |
886 xpc.xp_context = EXPAND_NOTHING; | |
887 xpc.xp_backslash = XP_BS_NONE; | |
632 | 888 #ifndef BACKSLASH_IN_FILENAME |
889 xpc.xp_shell = FALSE; | |
890 #endif | |
7 | 891 |
531 | 892 #if defined(FEAT_EVAL) |
893 if (ccline.input_fn) | |
894 { | |
895 xpc.xp_context = ccline.xp_context; | |
896 xpc.xp_pattern = ccline.cmdbuff; | |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16287
diff
changeset
|
897 # if defined(FEAT_CMDL_COMPL) |
531 | 898 xpc.xp_arg = ccline.xp_arg; |
1322 | 899 # endif |
531 | 900 } |
901 #endif | |
902 | |
7 | 903 /* |
904 * Avoid scrolling when called by a recursive do_cmdline(), e.g. when | |
905 * doing ":@0" when register 0 doesn't contain a CR. | |
906 */ | |
907 msg_scroll = FALSE; | |
908 | |
909 State = CMDLINE; | |
910 | |
911 if (firstc == '/' || firstc == '?' || firstc == '@') | |
912 { | |
913 /* Use ":lmap" mappings for search pattern and input(). */ | |
914 if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) | |
915 b_im_ptr = &curbuf->b_p_iminsert; | |
916 else | |
917 b_im_ptr = &curbuf->b_p_imsearch; | |
918 if (*b_im_ptr == B_IMODE_LMAP) | |
919 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
920 #ifdef HAVE_INPUT_METHOD |
7 | 921 im_set_active(*b_im_ptr == B_IMODE_IM); |
922 #endif | |
923 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
924 #ifdef HAVE_INPUT_METHOD |
7 | 925 else if (p_imcmdline) |
926 im_set_active(TRUE); | |
927 #endif | |
928 | |
929 #ifdef FEAT_MOUSE | |
930 setmouse(); | |
931 #endif | |
932 #ifdef CURSOR_SHAPE | |
933 ui_cursor_shape(); /* may show different cursor shape */ | |
934 #endif | |
935 | |
571 | 936 /* When inside an autocommand for writing "exiting" may be set and |
937 * terminal mode set to cooked. Need to set raw mode here then. */ | |
938 settmode(TMODE_RAW); | |
939 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
940 /* Trigger CmdlineEnter autocommands. */ |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
941 cmdline_type = firstc == NUL ? '-' : firstc; |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
942 trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINEENTER); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
943 |
7 | 944 init_history(); |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
945 hiscnt = get_hislen(); /* set hiscnt to impossible history value */ |
7 | 946 histype = hist_char2type(firstc); |
947 | |
948 #ifdef FEAT_DIGRAPHS | |
1868 | 949 do_digraph(-1); /* init digraph typeahead */ |
7 | 950 #endif |
951 | |
5993 | 952 /* If something above caused an error, reset the flags, we do want to type |
953 * and execute commands. Display may be messed up a bit. */ | |
954 if (did_emsg) | |
955 redrawcmd(); | |
956 did_emsg = FALSE; | |
957 got_int = FALSE; | |
958 | |
7 | 959 /* |
960 * Collect the command string, handling editing keys. | |
961 */ | |
962 for (;;) | |
963 { | |
972 | 964 redir_off = TRUE; /* Don't redirect the typed command. |
965 Repeated, because a ":redir" inside | |
966 completion may switch it on. */ | |
7 | 967 #ifdef USE_ON_FLY_SCROLL |
968 dont_scroll = FALSE; /* allow scrolling here */ | |
969 #endif | |
970 quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ | |
971 | |
13600
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
972 did_emsg = FALSE; /* There can't really be a reason why an error |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
973 that occurs while typing a command should |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
974 cause the command not to be executed. */ |
75e35ebdb7a4
patch 8.0.1672: error during completion causes command to be cancelled
Christian Brabandt <cb@256bit.org>
parents:
13551
diff
changeset
|
975 |
7 | 976 cursorcmd(); /* set the cursor on the right spot */ |
1472 | 977 |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
978 /* Get a character. Ignore K_IGNORE and K_NOP, they should not do |
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
979 * anything, such as stop completion. */ |
1472 | 980 do |
981 c = safe_vgetc(); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
982 while (c == K_IGNORE || c == K_NOP); |
1472 | 983 |
7 | 984 if (KeyTyped) |
985 { | |
986 some_key_typed = TRUE; | |
987 #ifdef FEAT_RIGHTLEFT | |
988 if (cmd_hkmap) | |
989 c = hkmap(c); | |
990 if (cmdmsg_rl && !KeyStuffed) | |
991 { | |
992 /* Invert horizontal movements and operations. Only when | |
993 * typed by the user directly, not when the result of a | |
994 * mapping. */ | |
995 switch (c) | |
996 { | |
997 case K_RIGHT: c = K_LEFT; break; | |
998 case K_S_RIGHT: c = K_S_LEFT; break; | |
999 case K_C_RIGHT: c = K_C_LEFT; break; | |
1000 case K_LEFT: c = K_RIGHT; break; | |
1001 case K_S_LEFT: c = K_S_RIGHT; break; | |
1002 case K_C_LEFT: c = K_C_RIGHT; break; | |
1003 } | |
1004 } | |
1005 #endif | |
1006 } | |
1007 | |
1008 /* | |
1009 * Ignore got_int when CTRL-C was typed here. | |
1010 * Don't ignore it in :global, we really need to break then, e.g., for | |
1011 * ":g/pat/normal /pat" (without the <CR>). | |
1012 * Don't ignore it for the input() function. | |
1013 */ | |
1014 if ((c == Ctrl_C | |
1015 #ifdef UNIX | |
1016 || c == intr_char | |
1017 #endif | |
1018 ) | |
1019 #if defined(FEAT_EVAL) || defined(FEAT_CRYPT) | |
1020 && firstc != '@' | |
1021 #endif | |
1022 #ifdef FEAT_EVAL | |
1023 && !break_ctrl_c | |
1024 #endif | |
1025 && !global_busy) | |
1026 got_int = FALSE; | |
1027 | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
1028 // free old command line when finished moving around in the history |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
1029 // list |
7 | 1030 if (lookfor != NULL |
180 | 1031 && c != K_S_DOWN && c != K_S_UP |
230 | 1032 && c != K_DOWN && c != K_UP |
7 | 1033 && c != K_PAGEDOWN && c != K_PAGEUP |
1034 && c != K_KPAGEDOWN && c != K_KPAGEUP | |
230 | 1035 && c != K_LEFT && c != K_RIGHT |
7 | 1036 && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N))) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1037 VIM_CLEAR(lookfor); |
7 | 1038 |
1039 /* | |
1718 | 1040 * When there are matching completions to select <S-Tab> works like |
1041 * CTRL-P (unless 'wc' is <S-Tab>). | |
7 | 1042 */ |
1718 | 1043 if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) |
7 | 1044 c = Ctrl_P; |
1045 | |
1046 #ifdef FEAT_WILDMENU | |
1047 /* Special translations for 'wildmenu' */ | |
1048 if (did_wild_list && p_wmnu) | |
1049 { | |
230 | 1050 if (c == K_LEFT) |
7 | 1051 c = Ctrl_P; |
230 | 1052 else if (c == K_RIGHT) |
7 | 1053 c = Ctrl_N; |
1054 } | |
1055 /* Hitting CR after "emenu Name.": complete submenu */ | |
1056 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu | |
1057 && ccline.cmdpos > 1 | |
1058 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' | |
1059 && ccline.cmdbuff[ccline.cmdpos - 2] != '\\' | |
1060 && (c == '\n' || c == '\r' || c == K_KENTER)) | |
1061 c = K_DOWN; | |
1062 #endif | |
1063 | |
1064 /* free expanded names when finished walking through matches */ | |
1065 if (xpc.xp_numfiles != -1 | |
1066 && !(c == p_wc && KeyTyped) && c != p_wcm | |
1067 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A | |
1068 && c != Ctrl_L) | |
1069 { | |
1070 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1071 did_wild_list = FALSE; | |
1072 #ifdef FEAT_WILDMENU | |
230 | 1073 if (!p_wmnu || (c != K_UP && c != K_DOWN)) |
7 | 1074 #endif |
1075 xpc.xp_context = EXPAND_NOTHING; | |
1076 wim_index = 0; | |
1077 #ifdef FEAT_WILDMENU | |
1078 if (p_wmnu && wild_menu_showing != 0) | |
1079 { | |
1080 int skt = KeyTyped; | |
532 | 1081 int old_RedrawingDisabled = RedrawingDisabled; |
531 | 1082 |
1083 if (ccline.input_fn) | |
1084 RedrawingDisabled = 0; | |
7 | 1085 |
1086 if (wild_menu_showing == WM_SCROLLED) | |
1087 { | |
1088 /* Entered command line, move it up */ | |
1089 cmdline_row--; | |
1090 redrawcmd(); | |
1091 } | |
1092 else if (save_p_ls != -1) | |
1093 { | |
1094 /* restore 'laststatus' and 'winminheight' */ | |
1095 p_ls = save_p_ls; | |
1096 p_wmh = save_p_wmh; | |
1097 last_status(FALSE); | |
1098 update_screen(VALID); /* redraw the screen NOW */ | |
1099 redrawcmd(); | |
1100 save_p_ls = -1; | |
1101 } | |
1102 else | |
1103 { | |
1104 win_redraw_last_status(topframe); | |
1105 redraw_statuslines(); | |
1106 } | |
532 | 1107 KeyTyped = skt; |
1108 wild_menu_showing = 0; | |
531 | 1109 if (ccline.input_fn) |
1110 RedrawingDisabled = old_RedrawingDisabled; | |
7 | 1111 } |
1112 #endif | |
1113 } | |
1114 | |
1115 #ifdef FEAT_WILDMENU | |
1116 /* Special translations for 'wildmenu' */ | |
1117 if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) | |
1118 { | |
1119 /* Hitting <Down> after "emenu Name.": complete submenu */ | |
1318 | 1120 if (c == K_DOWN && ccline.cmdpos > 0 |
1121 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') | |
7 | 1122 c = p_wc; |
230 | 1123 else if (c == K_UP) |
7 | 1124 { |
1125 /* Hitting <Up>: Remove one submenu name in front of the | |
1126 * cursor */ | |
1127 int found = FALSE; | |
1128 | |
1129 j = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1130 i = 0; | |
1131 while (--j > 0) | |
1132 { | |
1133 /* check for start of menu name */ | |
1134 if (ccline.cmdbuff[j] == ' ' | |
1135 && ccline.cmdbuff[j - 1] != '\\') | |
1136 { | |
1137 i = j + 1; | |
1138 break; | |
1139 } | |
1140 /* check for start of submenu name */ | |
1141 if (ccline.cmdbuff[j] == '.' | |
1142 && ccline.cmdbuff[j - 1] != '\\') | |
1143 { | |
1144 if (found) | |
1145 { | |
1146 i = j + 1; | |
1147 break; | |
1148 } | |
1149 else | |
1150 found = TRUE; | |
1151 } | |
1152 } | |
1153 if (i > 0) | |
1154 cmdline_del(i); | |
1155 c = p_wc; | |
1156 xpc.xp_context = EXPAND_NOTHING; | |
1157 } | |
1158 } | |
714 | 1159 if ((xpc.xp_context == EXPAND_FILES |
1621 | 1160 || xpc.xp_context == EXPAND_DIRECTORIES |
714 | 1161 || xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu) |
7 | 1162 { |
1163 char_u upseg[5]; | |
1164 | |
1165 upseg[0] = PATHSEP; | |
1166 upseg[1] = '.'; | |
1167 upseg[2] = '.'; | |
1168 upseg[3] = PATHSEP; | |
1169 upseg[4] = NUL; | |
1170 | |
1318 | 1171 if (c == K_DOWN |
1172 && ccline.cmdpos > 0 | |
1173 && ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP | |
1174 && (ccline.cmdpos < 3 | |
1175 || ccline.cmdbuff[ccline.cmdpos - 2] != '.' | |
7 | 1176 || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) |
1177 { | |
1178 /* go down a directory */ | |
1179 c = p_wc; | |
1180 } | |
230 | 1181 else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) |
7 | 1182 { |
1183 /* If in a direct ancestor, strip off one ../ to go down */ | |
1184 int found = FALSE; | |
1185 | |
1186 j = ccline.cmdpos; | |
1187 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1188 while (--j > i) | |
1189 { | |
39 | 1190 if (has_mbyte) |
1191 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
7 | 1192 if (vim_ispathsep(ccline.cmdbuff[j])) |
1193 { | |
1194 found = TRUE; | |
1195 break; | |
1196 } | |
1197 } | |
1198 if (found | |
1199 && ccline.cmdbuff[j - 1] == '.' | |
1200 && ccline.cmdbuff[j - 2] == '.' | |
1201 && (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2)) | |
1202 { | |
1203 cmdline_del(j - 2); | |
1204 c = p_wc; | |
1205 } | |
1206 } | |
230 | 1207 else if (c == K_UP) |
7 | 1208 { |
1209 /* go up a directory */ | |
1210 int found = FALSE; | |
1211 | |
1212 j = ccline.cmdpos - 1; | |
1213 i = (int)(xpc.xp_pattern - ccline.cmdbuff); | |
1214 while (--j > i) | |
1215 { | |
1216 if (has_mbyte) | |
1217 j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j); | |
1218 if (vim_ispathsep(ccline.cmdbuff[j]) | |
1219 #ifdef BACKSLASH_IN_FILENAME | |
8080
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1220 && vim_strchr((char_u *)" *?[{`$%#", |
b6cb94ad97a4
commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
1221 ccline.cmdbuff[j + 1]) == NULL |
7 | 1222 #endif |
1223 ) | |
1224 { | |
1225 if (found) | |
1226 { | |
1227 i = j + 1; | |
1228 break; | |
1229 } | |
1230 else | |
1231 found = TRUE; | |
1232 } | |
1233 } | |
1234 | |
1235 if (!found) | |
1236 j = i; | |
1237 else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0) | |
1238 j += 4; | |
1239 else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0 | |
1240 && j == i) | |
1241 j += 3; | |
1242 else | |
1243 j = 0; | |
1244 if (j > 0) | |
1245 { | |
1246 /* TODO this is only for DOS/UNIX systems - need to put in | |
1247 * machine-specific stuff here and in upseg init */ | |
1248 cmdline_del(j); | |
1249 put_on_cmdline(upseg + 1, 3, FALSE); | |
1250 } | |
1251 else if (ccline.cmdpos > i) | |
1252 cmdline_del(i); | |
3204 | 1253 |
1254 /* Now complete in the new directory. Set KeyTyped in case the | |
1255 * Up key came from a mapping. */ | |
7 | 1256 c = p_wc; |
3204 | 1257 KeyTyped = TRUE; |
7 | 1258 } |
1259 } | |
1260 | |
1261 #endif /* FEAT_WILDMENU */ | |
1262 | |
1263 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert | |
1264 * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ | |
1265 if (c == Ctrl_BSL) | |
1266 { | |
1267 ++no_mapping; | |
1268 ++allow_keys; | |
1389 | 1269 c = plain_vgetc(); |
7 | 1270 --no_mapping; |
1271 --allow_keys; | |
3859 | 1272 /* CTRL-\ e doesn't work when obtaining an expression, unless it |
1273 * is in a mapping. */ | |
1274 if (c != Ctrl_N && c != Ctrl_G && (c != 'e' | |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1275 || (ccline.cmdfirstc == '=' && KeyTyped) |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1276 #ifdef FEAT_EVAL |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1277 || cmdline_star > 0 |
14842
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1278 #endif |
7379bc1c3498
patch 8.1.0433: mapping can obtain text from inputsecret()
Christian Brabandt <cb@256bit.org>
parents:
14774
diff
changeset
|
1279 )) |
7 | 1280 { |
1281 vungetc(c); | |
1282 c = Ctrl_BSL; | |
1283 } | |
1284 #ifdef FEAT_EVAL | |
1285 else if (c == 'e') | |
1286 { | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1287 char_u *p = NULL; |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
1288 int len; |
7 | 1289 |
1290 /* | |
1291 * Replace the command line with the result of an expression. | |
625 | 1292 * Need to save and restore the current command line, to be |
1293 * able to enter a new one... | |
7 | 1294 */ |
1295 if (ccline.cmdpos == ccline.cmdlen) | |
1296 new_cmdpos = 99999; /* keep it at the end */ | |
1297 else | |
1298 new_cmdpos = ccline.cmdpos; | |
95 | 1299 |
7 | 1300 c = get_expr_register(); |
1301 if (c == '=') | |
1302 { | |
634 | 1303 /* Need to save and restore ccline. And set "textlock" |
632 | 1304 * to avoid nasty things like going to another buffer when |
1305 * evaluating an expression. */ | |
634 | 1306 ++textlock; |
7 | 1307 p = get_expr_line(); |
634 | 1308 --textlock; |
2617 | 1309 |
1310 if (p != NULL) | |
7 | 1311 { |
2617 | 1312 len = (int)STRLEN(p); |
1313 if (realloc_cmdbuff(len + 1) == OK) | |
1314 { | |
1315 ccline.cmdlen = len; | |
1316 STRCPY(ccline.cmdbuff, p); | |
1317 vim_free(p); | |
1318 | |
1319 /* Restore the cursor or use the position set with | |
1320 * set_cmdline_pos(). */ | |
1321 if (new_cmdpos > ccline.cmdlen) | |
1322 ccline.cmdpos = ccline.cmdlen; | |
1323 else | |
1324 ccline.cmdpos = new_cmdpos; | |
1325 | |
1326 KeyTyped = FALSE; /* Don't do p_wc completion. */ | |
1327 redrawcmd(); | |
1328 goto cmdline_changed; | |
1329 } | |
15064
7b2dcca9e0c1
patch 8.1.0543: Coverity warns for leaking memory and using wrong struct
Bram Moolenaar <Bram@vim.org>
parents:
14976
diff
changeset
|
1330 vim_free(p); |
7 | 1331 } |
1332 } | |
1333 beep_flush(); | |
2636 | 1334 got_int = FALSE; /* don't abandon the command line */ |
1335 did_emsg = FALSE; | |
1336 emsg_on_display = FALSE; | |
1337 redrawcmd(); | |
1338 goto cmdline_not_changed; | |
7 | 1339 } |
1340 #endif | |
1341 else | |
1342 { | |
1343 if (c == Ctrl_G && p_im && restart_edit == 0) | |
1344 restart_edit = 'a'; | |
1345 gotesc = TRUE; /* will free ccline.cmdbuff after putting it | |
1346 in history */ | |
1347 goto returncmd; /* back to Normal mode */ | |
1348 } | |
1349 } | |
1350 | |
1351 #ifdef FEAT_CMDWIN | |
1352 if (c == cedit_key || c == K_CMDWIN) | |
1353 { | |
6211 | 1354 if (ex_normal_busy == 0 && got_int == FALSE) |
1355 { | |
1356 /* | |
1357 * Open a window to edit the command line (and history). | |
1358 */ | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1359 c = open_cmdwin(); |
6211 | 1360 some_key_typed = TRUE; |
1361 } | |
7 | 1362 } |
1363 # ifdef FEAT_DIGRAPHS | |
1364 else | |
1365 # endif | |
1366 #endif | |
1367 #ifdef FEAT_DIGRAPHS | |
1368 c = do_digraph(c); | |
1369 #endif | |
1370 | |
1371 if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC | |
1372 && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) | |
1373 { | |
168 | 1374 /* In Ex mode a backslash escapes a newline. */ |
1375 if (exmode_active | |
1376 && c != ESC | |
1318 | 1377 && ccline.cmdpos == ccline.cmdlen |
168 | 1378 && ccline.cmdpos > 0 |
1379 && ccline.cmdbuff[ccline.cmdpos - 1] == '\\') | |
1380 { | |
1381 if (c == K_KENTER) | |
1382 c = '\n'; | |
1383 } | |
1384 else | |
7 | 1385 { |
168 | 1386 gotesc = FALSE; /* Might have typed ESC previously, don't |
1387 truncate the cmdline now. */ | |
1388 if (ccheck_abbr(c + ABBR_OFF)) | |
1389 goto cmdline_changed; | |
1390 if (!cmd_silent) | |
1391 { | |
1392 windgoto(msg_row, 0); | |
1393 out_flush(); | |
1394 } | |
1395 break; | |
7 | 1396 } |
1397 } | |
1398 | |
1399 /* | |
1400 * Completion for 'wildchar' or 'wildcharm' key. | |
1401 * - hitting <ESC> twice means: abandon command line. | |
1402 * - wildcard expansion is only done when the 'wildchar' key is really | |
1403 * typed, not when it comes from a macro | |
1404 */ | |
1405 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm) | |
1406 { | |
1407 if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ | |
1408 { | |
1409 /* if 'wildmode' contains "list" may still need to list */ | |
1410 if (xpc.xp_numfiles > 1 | |
1411 && !did_wild_list | |
1412 && (wim_flags[wim_index] & WIM_LIST)) | |
1413 { | |
1414 (void)showmatches(&xpc, FALSE); | |
1415 redrawcmd(); | |
1416 did_wild_list = TRUE; | |
1417 } | |
1418 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1419 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1420 firstc != '@'); | |
7 | 1421 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1422 res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1423 firstc != '@'); | |
7 | 1424 else |
1425 res = OK; /* don't insert 'wildchar' now */ | |
1426 } | |
1427 else /* typed p_wc first time */ | |
1428 { | |
1429 wim_index = 0; | |
1430 j = ccline.cmdpos; | |
1431 /* if 'wildmode' first contains "longest", get longest | |
1432 * common part */ | |
1433 if (wim_flags[0] & WIM_LONGEST) | |
3961 | 1434 res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1435 firstc != '@'); | |
7 | 1436 else |
3961 | 1437 res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP, |
1438 firstc != '@'); | |
7 | 1439 |
1440 /* if interrupted while completing, behave like it failed */ | |
1441 if (got_int) | |
1442 { | |
1443 (void)vpeekc(); /* remove <C-C> from input stream */ | |
1444 got_int = FALSE; /* don't abandon the command line */ | |
1445 (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); | |
1446 #ifdef FEAT_WILDMENU | |
1447 xpc.xp_context = EXPAND_NOTHING; | |
1448 #endif | |
1449 goto cmdline_changed; | |
1450 } | |
1451 | |
1452 /* when more than one match, and 'wildmode' first contains | |
1453 * "list", or no change and 'wildmode' contains "longest,list", | |
1454 * list all matches */ | |
1455 if (res == OK && xpc.xp_numfiles > 1) | |
1456 { | |
1457 /* a "longest" that didn't do anything is skipped (but not | |
1458 * "list:longest") */ | |
1459 if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) | |
1460 wim_index = 1; | |
1461 if ((wim_flags[wim_index] & WIM_LIST) | |
1462 #ifdef FEAT_WILDMENU | |
1463 || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0) | |
1464 #endif | |
1465 ) | |
1466 { | |
1467 if (!(wim_flags[0] & WIM_LONGEST)) | |
1468 { | |
1469 #ifdef FEAT_WILDMENU | |
1470 int p_wmnu_save = p_wmnu; | |
1471 p_wmnu = 0; | |
1472 #endif | |
3961 | 1473 /* remove match */ |
1474 nextwild(&xpc, WILD_PREV, 0, firstc != '@'); | |
7 | 1475 #ifdef FEAT_WILDMENU |
1476 p_wmnu = p_wmnu_save; | |
1477 #endif | |
1478 } | |
1479 #ifdef FEAT_WILDMENU | |
1480 (void)showmatches(&xpc, p_wmnu | |
1481 && ((wim_flags[wim_index] & WIM_LIST) == 0)); | |
1482 #else | |
1483 (void)showmatches(&xpc, FALSE); | |
1484 #endif | |
1485 redrawcmd(); | |
1486 did_wild_list = TRUE; | |
1487 if (wim_flags[wim_index] & WIM_LONGEST) | |
3961 | 1488 nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP, |
1489 firstc != '@'); | |
7 | 1490 else if (wim_flags[wim_index] & WIM_FULL) |
3961 | 1491 nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP, |
1492 firstc != '@'); | |
7 | 1493 } |
1494 else | |
6949 | 1495 vim_beep(BO_WILD); |
7 | 1496 } |
1497 #ifdef FEAT_WILDMENU | |
1498 else if (xpc.xp_numfiles == -1) | |
1499 xpc.xp_context = EXPAND_NOTHING; | |
1500 #endif | |
1501 } | |
1502 if (wim_index < 3) | |
1503 ++wim_index; | |
1504 if (c == ESC) | |
1505 gotesc = TRUE; | |
1506 if (res == OK) | |
1507 goto cmdline_changed; | |
1508 } | |
1509 | |
1510 gotesc = FALSE; | |
1511 | |
1512 /* <S-Tab> goes to last match, in a clumsy way */ | |
1513 if (c == K_S_TAB && KeyTyped) | |
1514 { | |
3961 | 1515 if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK |
1516 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK | |
1517 && nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK) | |
7 | 1518 goto cmdline_changed; |
1519 } | |
1520 | |
1521 if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ | |
1522 c = NL; | |
1523 | |
1524 do_abbr = TRUE; /* default: check for abbreviation */ | |
1525 | |
1526 /* | |
1527 * Big switch for a typed command line character. | |
1528 */ | |
1529 switch (c) | |
1530 { | |
1531 case K_BS: | |
1532 case Ctrl_H: | |
1533 case K_DEL: | |
1534 case K_KDEL: | |
1535 case Ctrl_W: | |
1536 if (c == K_KDEL) | |
1537 c = K_DEL; | |
1538 | |
1539 /* | |
1540 * delete current character is the same as backspace on next | |
1541 * character, except at end of line | |
1542 */ | |
1543 if (c == K_DEL && ccline.cmdpos != ccline.cmdlen) | |
1544 ++ccline.cmdpos; | |
1545 if (has_mbyte && c == K_DEL) | |
1546 ccline.cmdpos += mb_off_next(ccline.cmdbuff, | |
1547 ccline.cmdbuff + ccline.cmdpos); | |
1548 if (ccline.cmdpos > 0) | |
1549 { | |
1550 char_u *p; | |
1551 | |
1552 j = ccline.cmdpos; | |
1553 p = ccline.cmdbuff + j; | |
1554 if (has_mbyte) | |
1555 { | |
1556 p = mb_prevptr(ccline.cmdbuff, p); | |
1557 if (c == Ctrl_W) | |
1558 { | |
1559 while (p > ccline.cmdbuff && vim_isspace(*p)) | |
1560 p = mb_prevptr(ccline.cmdbuff, p); | |
1561 i = mb_get_class(p); | |
1562 while (p > ccline.cmdbuff && mb_get_class(p) == i) | |
1563 p = mb_prevptr(ccline.cmdbuff, p); | |
1564 if (mb_get_class(p) != i) | |
474 | 1565 p += (*mb_ptr2len)(p); |
7 | 1566 } |
1567 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
1568 else if (c == Ctrl_W) |
7 | 1569 { |
1570 while (p > ccline.cmdbuff && vim_isspace(p[-1])) | |
1571 --p; | |
1572 i = vim_iswordc(p[-1]); | |
1573 while (p > ccline.cmdbuff && !vim_isspace(p[-1]) | |
1574 && vim_iswordc(p[-1]) == i) | |
1575 --p; | |
1576 } | |
1577 else | |
1578 --p; | |
1579 ccline.cmdpos = (int)(p - ccline.cmdbuff); | |
1580 ccline.cmdlen -= j - ccline.cmdpos; | |
1581 i = ccline.cmdpos; | |
1582 while (i < ccline.cmdlen) | |
1583 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1584 | |
1585 /* Truncate at the end, required for multi-byte chars. */ | |
1586 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1587 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1588 if (ccline.cmdlen == 0) |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1589 { |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1590 is_state.search_start = is_state.save_cursor; |
10098
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1591 /* save view settings, so that the screen |
72e4b7f90465
commit https://github.com/vim/vim/commit/dda933d06c06c2792bd686d059f6ad19191ad30b
Christian Brabandt <cb@256bit.org>
parents:
10094
diff
changeset
|
1592 * won't be restored at the wrong position */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1593 is_state.old_viewstate = is_state.init_viewstate; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1594 } |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1595 #endif |
7 | 1596 redrawcmd(); |
1597 } | |
1598 else if (ccline.cmdlen == 0 && c != Ctrl_W | |
1599 && ccline.cmdprompt == NULL && indent == 0) | |
1600 { | |
1601 /* In ex and debug mode it doesn't make sense to return. */ | |
1602 if (exmode_active | |
1603 #ifdef FEAT_EVAL | |
1604 || ccline.cmdfirstc == '>' | |
1605 #endif | |
1606 ) | |
1607 goto cmdline_not_changed; | |
1608 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13142
diff
changeset
|
1609 VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ |
7 | 1610 if (!cmd_silent) |
1611 { | |
1612 #ifdef FEAT_RIGHTLEFT | |
1613 if (cmdmsg_rl) | |
1614 msg_col = Columns; | |
1615 else | |
1616 #endif | |
1617 msg_col = 0; | |
1618 msg_putchar(' '); /* delete ':' */ | |
1619 } | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1620 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1621 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1622 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1623 #endif |
7 | 1624 redraw_cmdline = TRUE; |
1625 goto returncmd; /* back to cmd mode */ | |
1626 } | |
1627 goto cmdline_changed; | |
1628 | |
1629 case K_INS: | |
1630 case K_KINS: | |
1631 ccline.overstrike = !ccline.overstrike; | |
1632 #ifdef CURSOR_SHAPE | |
1633 ui_cursor_shape(); /* may show different cursor shape */ | |
1634 #endif | |
1635 goto cmdline_not_changed; | |
1636 | |
1637 case Ctrl_HAT: | |
782 | 1638 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
7 | 1639 { |
1640 /* ":lmap" mappings exists, toggle use of mappings. */ | |
1641 State ^= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1642 #ifdef HAVE_INPUT_METHOD |
7 | 1643 im_set_active(FALSE); /* Disable input method */ |
1644 #endif | |
1645 if (b_im_ptr != NULL) | |
1646 { | |
1647 if (State & LANGMAP) | |
1648 *b_im_ptr = B_IMODE_LMAP; | |
1649 else | |
1650 *b_im_ptr = B_IMODE_NONE; | |
1651 } | |
1652 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
1653 #ifdef HAVE_INPUT_METHOD |
7 | 1654 else |
1655 { | |
1656 /* There are no ":lmap" mappings, toggle IM. When | |
1657 * 'imdisable' is set don't try getting the status, it's | |
1658 * always off. */ | |
1659 if ((p_imdisable && b_im_ptr != NULL) | |
1660 ? *b_im_ptr == B_IMODE_IM : im_get_status()) | |
1661 { | |
1662 im_set_active(FALSE); /* Disable input method */ | |
1663 if (b_im_ptr != NULL) | |
1664 *b_im_ptr = B_IMODE_NONE; | |
1665 } | |
1666 else | |
1667 { | |
1668 im_set_active(TRUE); /* Enable input method */ | |
1669 if (b_im_ptr != NULL) | |
1670 *b_im_ptr = B_IMODE_IM; | |
1671 } | |
1672 } | |
1673 #endif | |
1674 if (b_im_ptr != NULL) | |
1675 { | |
1676 if (b_im_ptr == &curbuf->b_p_iminsert) | |
1677 set_iminsert_global(); | |
1678 else | |
1679 set_imsearch_global(); | |
1680 } | |
1681 #ifdef CURSOR_SHAPE | |
1682 ui_cursor_shape(); /* may show different cursor shape */ | |
1683 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12293
diff
changeset
|
1684 #if defined(FEAT_KEYMAP) |
7 | 1685 /* Show/unshow value of 'keymap' in status lines later. */ |
1686 status_redraw_curbuf(); | |
1687 #endif | |
1688 goto cmdline_not_changed; | |
1689 | |
1690 /* case '@': only in very old vi */ | |
1691 case Ctrl_U: | |
1692 /* delete all characters left of the cursor */ | |
1693 j = ccline.cmdpos; | |
1694 ccline.cmdlen -= j; | |
1695 i = ccline.cmdpos = 0; | |
1696 while (i < ccline.cmdlen) | |
1697 ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; | |
1698 /* Truncate at the end, required for multi-byte chars. */ | |
1699 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1700 #ifdef FEAT_SEARCH_EXTRA |
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1701 if (ccline.cmdlen == 0) |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
1702 is_state.search_start = is_state.save_cursor; |
9971
98b39d2eb895
commit https://github.com/vim/vim/commit/4d6f32cbfbaf324ac4a25c0206a5db0e9f7a48f7
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1703 #endif |
7 | 1704 redrawcmd(); |
1705 goto cmdline_changed; | |
1706 | |
1707 #ifdef FEAT_CLIPBOARD | |
1708 case Ctrl_Y: | |
1709 /* Copy the modeless selection, if there is one. */ | |
1710 if (clip_star.state != SELECT_CLEARED) | |
1711 { | |
1712 if (clip_star.state == SELECT_DONE) | |
1713 clip_copy_modeless_selection(TRUE); | |
1714 goto cmdline_not_changed; | |
1715 } | |
1716 break; | |
1717 #endif | |
1718 | |
1719 case ESC: /* get here if p_wc != ESC or when ESC typed twice */ | |
1720 case Ctrl_C: | |
571 | 1721 /* In exmode it doesn't make sense to return. Except when |
161 | 1722 * ":normal" runs out of characters. */ |
1723 if (exmode_active | |
7850
10f17a228661
commit https://github.com/vim/vim/commit/e2c3810c2ae290bbc2cba18eb47cc2d44e4b9797
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
1724 && (ex_normal_busy == 0 || typebuf.tb_len > 0)) |
7 | 1725 goto cmdline_not_changed; |
1726 | |
1727 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1728 putting it in history */ | |
1729 goto returncmd; /* back to cmd mode */ | |
1730 | |
1731 case Ctrl_R: /* insert register */ | |
1732 #ifdef USE_ON_FLY_SCROLL | |
1733 dont_scroll = TRUE; /* disallow scrolling here */ | |
1734 #endif | |
1735 putcmdline('"', TRUE); | |
1736 ++no_mapping; | |
1389 | 1737 i = c = plain_vgetc(); /* CTRL-R <char> */ |
7 | 1738 if (i == Ctrl_O) |
1739 i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ | |
1740 if (i == Ctrl_R) | |
1389 | 1741 c = plain_vgetc(); /* CTRL-R CTRL-R <char> */ |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
1742 extra_char = NUL; |
7 | 1743 --no_mapping; |
1744 #ifdef FEAT_EVAL | |
1745 /* | |
1746 * Insert the result of an expression. | |
1747 * Need to save the current command line, to be able to enter | |
1748 * a new one... | |
1749 */ | |
1750 new_cmdpos = -1; | |
1751 if (c == '=') | |
1752 { | |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1753 if (ccline.cmdfirstc == '=' // can't do this recursively |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
1754 || cmdline_star > 0) // or when typing a password |
7 | 1755 { |
1756 beep_flush(); | |
1757 c = ESC; | |
1758 } | |
1759 else | |
1760 c = get_expr_register(); | |
1761 } | |
1762 #endif | |
1763 if (c != ESC) /* use ESC to cancel inserting register */ | |
1764 { | |
1015 | 1765 cmdline_paste(c, i == Ctrl_R, FALSE); |
606 | 1766 |
613 | 1767 #ifdef FEAT_EVAL |
606 | 1768 /* When there was a serious error abort getting the |
1769 * command line. */ | |
1770 if (aborting()) | |
1771 { | |
1772 gotesc = TRUE; /* will free ccline.cmdbuff after | |
1773 putting it in history */ | |
1774 goto returncmd; /* back to cmd mode */ | |
1775 } | |
613 | 1776 #endif |
7 | 1777 KeyTyped = FALSE; /* Don't do p_wc completion. */ |
1778 #ifdef FEAT_EVAL | |
1779 if (new_cmdpos >= 0) | |
1780 { | |
1781 /* set_cmdline_pos() was used */ | |
1782 if (new_cmdpos > ccline.cmdlen) | |
1783 ccline.cmdpos = ccline.cmdlen; | |
1784 else | |
1785 ccline.cmdpos = new_cmdpos; | |
1786 } | |
1787 #endif | |
1788 } | |
1789 redrawcmd(); | |
1790 goto cmdline_changed; | |
1791 | |
1792 case Ctrl_D: | |
1793 if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) | |
1794 break; /* Use ^D as normal char instead */ | |
1795 | |
1796 redrawcmd(); | |
1797 continue; /* don't do incremental search now */ | |
1798 | |
1799 case K_RIGHT: | |
1800 case K_S_RIGHT: | |
1801 case K_C_RIGHT: | |
1802 do | |
1803 { | |
1804 if (ccline.cmdpos >= ccline.cmdlen) | |
1805 break; | |
1806 i = cmdline_charsize(ccline.cmdpos); | |
1807 if (KeyTyped && ccline.cmdspos + i >= Columns * Rows) | |
1808 break; | |
1809 ccline.cmdspos += i; | |
1810 if (has_mbyte) | |
474 | 1811 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1812 + ccline.cmdpos); |
1813 else | |
1814 ++ccline.cmdpos; | |
1815 } | |
180 | 1816 while ((c == K_S_RIGHT || c == K_C_RIGHT |
1817 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) | |
7 | 1818 && ccline.cmdbuff[ccline.cmdpos] != ' '); |
1819 if (has_mbyte) | |
1820 set_cmdspos_cursor(); | |
1821 goto cmdline_not_changed; | |
1822 | |
1823 case K_LEFT: | |
1824 case K_S_LEFT: | |
1825 case K_C_LEFT: | |
1456 | 1826 if (ccline.cmdpos == 0) |
1827 goto cmdline_not_changed; | |
7 | 1828 do |
1829 { | |
1830 --ccline.cmdpos; | |
1831 if (has_mbyte) /* move to first byte of char */ | |
1832 ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, | |
1833 ccline.cmdbuff + ccline.cmdpos); | |
1834 ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); | |
1835 } | |
1456 | 1836 while (ccline.cmdpos > 0 |
1837 && (c == K_S_LEFT || c == K_C_LEFT | |
180 | 1838 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) |
7 | 1839 && ccline.cmdbuff[ccline.cmdpos - 1] != ' '); |
1840 if (has_mbyte) | |
1841 set_cmdspos_cursor(); | |
1842 goto cmdline_not_changed; | |
1843 | |
1844 case K_IGNORE: | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
1845 /* Ignore mouse event or open_cmdwin() result. */ |
1472 | 1846 goto cmdline_not_changed; |
7 | 1847 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1848 #ifdef FEAT_GUI_MSWIN |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1849 /* On MS-Windows ignore <M-F4>, we get it when closing the window |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1850 * was cancelled. */ |
625 | 1851 case K_F4: |
1852 if (mod_mask == MOD_MASK_ALT) | |
1853 { | |
1854 redrawcmd(); /* somehow the cmdline is cleared */ | |
1855 goto cmdline_not_changed; | |
1856 } | |
1857 break; | |
1858 #endif | |
1859 | |
7 | 1860 #ifdef FEAT_MOUSE |
1861 case K_MIDDLEDRAG: | |
1862 case K_MIDDLERELEASE: | |
1863 goto cmdline_not_changed; /* Ignore mouse */ | |
1864 | |
1865 case K_MIDDLEMOUSE: | |
1866 # ifdef FEAT_GUI | |
1867 /* When GUI is active, also paste when 'mouse' is empty */ | |
1868 if (!gui.in_use) | |
1869 # endif | |
1870 if (!mouse_has(MOUSE_COMMAND)) | |
1871 goto cmdline_not_changed; /* Ignore mouse */ | |
692 | 1872 # ifdef FEAT_CLIPBOARD |
7 | 1873 if (clip_star.available) |
1015 | 1874 cmdline_paste('*', TRUE, TRUE); |
7 | 1875 else |
692 | 1876 # endif |
1015 | 1877 cmdline_paste(0, TRUE, TRUE); |
7 | 1878 redrawcmd(); |
1879 goto cmdline_changed; | |
1880 | |
692 | 1881 # ifdef FEAT_DND |
7 | 1882 case K_DROP: |
1015 | 1883 cmdline_paste('~', TRUE, FALSE); |
7 | 1884 redrawcmd(); |
1885 goto cmdline_changed; | |
692 | 1886 # endif |
7 | 1887 |
1888 case K_LEFTDRAG: | |
1889 case K_LEFTRELEASE: | |
1890 case K_RIGHTDRAG: | |
1891 case K_RIGHTRELEASE: | |
1892 /* Ignore drag and release events when the button-down wasn't | |
1893 * seen before. */ | |
1894 if (ignore_drag_release) | |
1895 goto cmdline_not_changed; | |
1896 /* FALLTHROUGH */ | |
1897 case K_LEFTMOUSE: | |
1898 case K_RIGHTMOUSE: | |
1899 if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) | |
1900 ignore_drag_release = TRUE; | |
1901 else | |
1902 ignore_drag_release = FALSE; | |
1903 # ifdef FEAT_GUI | |
1904 /* When GUI is active, also move when 'mouse' is empty */ | |
1905 if (!gui.in_use) | |
1906 # endif | |
1907 if (!mouse_has(MOUSE_COMMAND)) | |
1908 goto cmdline_not_changed; /* Ignore mouse */ | |
1909 # ifdef FEAT_CLIPBOARD | |
1910 if (mouse_row < cmdline_row && clip_star.available) | |
1911 { | |
1912 int button, is_click, is_drag; | |
1913 | |
1914 /* | |
1915 * Handle modeless selection. | |
1916 */ | |
1917 button = get_mouse_button(KEY2TERMCAP1(c), | |
1918 &is_click, &is_drag); | |
1919 if (mouse_model_popup() && button == MOUSE_LEFT | |
1920 && (mod_mask & MOD_MASK_SHIFT)) | |
1921 { | |
1922 /* Translate shift-left to right button. */ | |
1923 button = MOUSE_RIGHT; | |
1924 mod_mask &= ~MOD_MASK_SHIFT; | |
1925 } | |
1926 clip_modeless(button, is_click, is_drag); | |
1927 goto cmdline_not_changed; | |
1928 } | |
1929 # endif | |
1930 | |
1931 set_cmdspos(); | |
1932 for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen; | |
1933 ++ccline.cmdpos) | |
1934 { | |
1935 i = cmdline_charsize(ccline.cmdpos); | |
1936 if (mouse_row <= cmdline_row + ccline.cmdspos / Columns | |
1937 && mouse_col < ccline.cmdspos % Columns + i) | |
1938 break; | |
1939 if (has_mbyte) | |
1940 { | |
1941 /* Count ">" for double-wide char that doesn't fit. */ | |
1942 correct_cmdspos(ccline.cmdpos, i); | |
474 | 1943 ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff |
7 | 1944 + ccline.cmdpos) - 1; |
1945 } | |
1946 ccline.cmdspos += i; | |
1947 } | |
1948 goto cmdline_not_changed; | |
1949 | |
1950 /* Mouse scroll wheel: ignored here */ | |
1951 case K_MOUSEDOWN: | |
1952 case K_MOUSEUP: | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1953 case K_MOUSELEFT: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1954 case K_MOUSERIGHT: |
7 | 1955 /* Alternate buttons ignored here */ |
1956 case K_X1MOUSE: | |
1957 case K_X1DRAG: | |
1958 case K_X1RELEASE: | |
1959 case K_X2MOUSE: | |
1960 case K_X2DRAG: | |
1961 case K_X2RELEASE: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12855
diff
changeset
|
1962 case K_MOUSEMOVE: |
7 | 1963 goto cmdline_not_changed; |
1964 | |
1965 #endif /* FEAT_MOUSE */ | |
1966 | |
1967 #ifdef FEAT_GUI | |
1968 case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ | |
1969 case K_LEFTRELEASE_NM: | |
1970 goto cmdline_not_changed; | |
1971 | |
1972 case K_VER_SCROLLBAR: | |
540 | 1973 if (msg_scrolled == 0) |
7 | 1974 { |
1975 gui_do_scroll(); | |
1976 redrawcmd(); | |
1977 } | |
1978 goto cmdline_not_changed; | |
1979 | |
1980 case K_HOR_SCROLLBAR: | |
540 | 1981 if (msg_scrolled == 0) |
7 | 1982 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1983 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 1984 redrawcmd(); |
1985 } | |
1986 goto cmdline_not_changed; | |
1987 #endif | |
692 | 1988 #ifdef FEAT_GUI_TABLINE |
1989 case K_TABLINE: | |
1990 case K_TABMENU: | |
1991 /* Don't want to change any tabs here. Make sure the same tab | |
1992 * is still selected. */ | |
1993 if (gui_use_tabline()) | |
1994 gui_mch_set_curtab(tabpage_index(curtab)); | |
1995 goto cmdline_not_changed; | |
1996 #endif | |
1997 | |
7 | 1998 case K_SELECT: /* end of Select mode mapping - ignore */ |
1999 goto cmdline_not_changed; | |
2000 | |
2001 case Ctrl_B: /* begin of command line */ | |
2002 case K_HOME: | |
2003 case K_KHOME: | |
2004 case K_S_HOME: | |
2005 case K_C_HOME: | |
2006 ccline.cmdpos = 0; | |
2007 set_cmdspos(); | |
2008 goto cmdline_not_changed; | |
2009 | |
2010 case Ctrl_E: /* end of command line */ | |
2011 case K_END: | |
2012 case K_KEND: | |
2013 case K_S_END: | |
2014 case K_C_END: | |
2015 ccline.cmdpos = ccline.cmdlen; | |
2016 set_cmdspos_cursor(); | |
2017 goto cmdline_not_changed; | |
2018 | |
2019 case Ctrl_A: /* all matches */ | |
3961 | 2020 if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) |
7 | 2021 break; |
2022 goto cmdline_changed; | |
2023 | |
772 | 2024 case Ctrl_L: |
2025 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2026 if (may_add_char_to_search(firstc, &c, &is_state) == OK) |
772 | 2027 goto cmdline_not_changed; |
2028 #endif | |
2029 | |
2030 /* completion: longest common part */ | |
3961 | 2031 if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) |
7 | 2032 break; |
2033 goto cmdline_changed; | |
2034 | |
2035 case Ctrl_N: /* next match */ | |
2036 case Ctrl_P: /* previous match */ | |
9976
e448370630b2
commit https://github.com/vim/vim/commit/7df0f6313a46b80d760c9a80241922544333351c
Christian Brabandt <cb@256bit.org>
parents:
9971
diff
changeset
|
2037 if (xpc.xp_numfiles > 0) |
7 | 2038 { |
3961 | 2039 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, |
2040 0, firstc != '@') == FAIL) | |
7 | 2041 break; |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2042 goto cmdline_not_changed; |
7 | 2043 } |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2044 /* FALLTHROUGH */ |
7 | 2045 case K_UP: |
2046 case K_DOWN: | |
2047 case K_S_UP: | |
2048 case K_S_DOWN: | |
2049 case K_PAGEUP: | |
2050 case K_KPAGEUP: | |
2051 case K_PAGEDOWN: | |
2052 case K_KPAGEDOWN: | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2053 if (get_hislen() == 0 || firstc == NUL) /* no history */ |
7 | 2054 goto cmdline_not_changed; |
2055 | |
2056 i = hiscnt; | |
2057 | |
2058 /* save current command string so it can be restored later */ | |
2059 if (lookfor == NULL) | |
2060 { | |
2061 if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) | |
2062 goto cmdline_not_changed; | |
2063 lookfor[ccline.cmdpos] = NUL; | |
2064 } | |
2065 | |
2066 j = (int)STRLEN(lookfor); | |
2067 for (;;) | |
2068 { | |
2069 /* one step backwards */ | |
230 | 2070 if (c == K_UP|| c == K_S_UP || c == Ctrl_P |
180 | 2071 || c == K_PAGEUP || c == K_KPAGEUP) |
7 | 2072 { |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2073 if (hiscnt == get_hislen()) /* first time */ |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2074 hiscnt = *get_hisidx(histype); |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2075 else if (hiscnt == 0 && *get_hisidx(histype) != get_hislen() - 1) |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2076 hiscnt = get_hislen() - 1; |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2077 else if (hiscnt != *get_hisidx(histype) + 1) |
7 | 2078 --hiscnt; |
2079 else /* at top of list */ | |
2080 { | |
2081 hiscnt = i; | |
2082 break; | |
2083 } | |
2084 } | |
2085 else /* one step forwards */ | |
2086 { | |
2087 /* on last entry, clear the line */ | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2088 if (hiscnt == *get_hisidx(histype)) |
7 | 2089 { |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2090 hiscnt = get_hislen(); |
7 | 2091 break; |
2092 } | |
2093 | |
2094 /* not on a history line, nothing to do */ | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2095 if (hiscnt == get_hislen()) |
7 | 2096 break; |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2097 if (hiscnt == get_hislen() - 1) /* wrap around */ |
7 | 2098 hiscnt = 0; |
2099 else | |
2100 ++hiscnt; | |
2101 } | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2102 if (hiscnt < 0 || get_histentry(histype)[hiscnt].hisstr == NULL) |
7 | 2103 { |
2104 hiscnt = i; | |
2105 break; | |
2106 } | |
230 | 2107 if ((c != K_UP && c != K_DOWN) |
180 | 2108 || hiscnt == i |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2109 || STRNCMP(get_histentry(histype)[hiscnt].hisstr, |
7 | 2110 lookfor, (size_t)j) == 0) |
2111 break; | |
2112 } | |
2113 | |
2114 if (hiscnt != i) /* jumped to other entry */ | |
2115 { | |
2116 char_u *p; | |
2117 int len; | |
2118 int old_firstc; | |
2119 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2120 VIM_CLEAR(ccline.cmdbuff); |
1718 | 2121 xpc.xp_context = EXPAND_NOTHING; |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2122 if (hiscnt == get_hislen()) |
7 | 2123 p = lookfor; /* back to the old one */ |
2124 else | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
2125 p = get_histentry(histype)[hiscnt].hisstr; |
7 | 2126 |
2127 if (histype == HIST_SEARCH | |
2128 && p != lookfor | |
2129 && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
2130 { | |
2131 /* Correct for the separator character used when | |
2132 * adding the history entry vs the one used now. | |
2133 * First loop: count length. | |
2134 * Second loop: copy the characters. */ | |
2135 for (i = 0; i <= 1; ++i) | |
2136 { | |
2137 len = 0; | |
2138 for (j = 0; p[j] != NUL; ++j) | |
2139 { | |
2140 /* Replace old sep with new sep, unless it is | |
2141 * escaped. */ | |
2142 if (p[j] == old_firstc | |
2143 && (j == 0 || p[j - 1] != '\\')) | |
2144 { | |
2145 if (i > 0) | |
2146 ccline.cmdbuff[len] = firstc; | |
2147 } | |
2148 else | |
2149 { | |
2150 /* Escape new sep, unless it is already | |
2151 * escaped. */ | |
2152 if (p[j] == firstc | |
2153 && (j == 0 || p[j - 1] != '\\')) | |
2154 { | |
2155 if (i > 0) | |
2156 ccline.cmdbuff[len] = '\\'; | |
2157 ++len; | |
2158 } | |
2159 if (i > 0) | |
2160 ccline.cmdbuff[len] = p[j]; | |
2161 } | |
2162 ++len; | |
2163 } | |
2164 if (i == 0) | |
2165 { | |
2166 alloc_cmdbuff(len); | |
2167 if (ccline.cmdbuff == NULL) | |
2168 goto returncmd; | |
2169 } | |
2170 } | |
2171 ccline.cmdbuff[len] = NUL; | |
2172 } | |
2173 else | |
2174 { | |
2175 alloc_cmdbuff((int)STRLEN(p)); | |
2176 if (ccline.cmdbuff == NULL) | |
2177 goto returncmd; | |
2178 STRCPY(ccline.cmdbuff, p); | |
2179 } | |
2180 | |
2181 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
2182 redrawcmd(); | |
2183 goto cmdline_changed; | |
2184 } | |
2185 beep_flush(); | |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2186 goto cmdline_not_changed; |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2187 |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2188 #ifdef FEAT_SEARCH_EXTRA |
9990
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2189 case Ctrl_G: /* next match */ |
6a1793d9c895
commit https://github.com/vim/vim/commit/1195669f9e434fa9ab8b57ee9470bf951e4990b8
Christian Brabandt <cb@256bit.org>
parents:
9976
diff
changeset
|
2190 case Ctrl_T: /* previous match */ |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2191 if (may_adjust_incsearch_highlighting( |
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2192 firstc, count, &is_state, c) == FAIL) |
10094
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2193 goto cmdline_not_changed; |
61dc69646af6
commit https://github.com/vim/vim/commit/349e7d94e6bbb253bb87adad9039f095128ab543
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
2194 break; |
7 | 2195 #endif |
2196 | |
2197 case Ctrl_V: | |
2198 case Ctrl_Q: | |
2199 #ifdef FEAT_MOUSE | |
2200 ignore_drag_release = TRUE; | |
2201 #endif | |
2202 putcmdline('^', TRUE); | |
2203 c = get_literal(); /* get next (two) character(s) */ | |
2204 do_abbr = FALSE; /* don't do abbreviation now */ | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
2205 extra_char = NUL; |
7 | 2206 /* may need to remove ^ when composing char was typed */ |
2207 if (enc_utf8 && utf_iscomposing(c) && !cmd_silent) | |
2208 { | |
2209 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
2210 msg_putchar(' '); | |
2211 cursorcmd(); | |
2212 } | |
2213 break; | |
2214 | |
2215 #ifdef FEAT_DIGRAPHS | |
2216 case Ctrl_K: | |
2217 #ifdef FEAT_MOUSE | |
2218 ignore_drag_release = TRUE; | |
2219 #endif | |
2220 putcmdline('?', TRUE); | |
2221 #ifdef USE_ON_FLY_SCROLL | |
2222 dont_scroll = TRUE; /* disallow scrolling here */ | |
2223 #endif | |
2224 c = get_digraph(TRUE); | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
2225 extra_char = NUL; |
7 | 2226 if (c != NUL) |
2227 break; | |
2228 | |
2229 redrawcmd(); | |
2230 goto cmdline_not_changed; | |
2231 #endif /* FEAT_DIGRAPHS */ | |
2232 | |
2233 #ifdef FEAT_RIGHTLEFT | |
2234 case Ctrl__: /* CTRL-_: switch language mode */ | |
2235 if (!p_ari) | |
2236 break; | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2237 cmd_hkmap = !cmd_hkmap; |
7 | 2238 goto cmdline_not_changed; |
2239 #endif | |
2240 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2241 case K_PS: |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2242 bracketed_paste(PASTE_CMDLINE, FALSE, NULL); |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2243 goto cmdline_changed; |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2244 |
7 | 2245 default: |
2246 #ifdef UNIX | |
2247 if (c == intr_char) | |
2248 { | |
2249 gotesc = TRUE; /* will free ccline.cmdbuff after | |
2250 putting it in history */ | |
2251 goto returncmd; /* back to Normal mode */ | |
2252 } | |
2253 #endif | |
2254 /* | |
2255 * Normal character with no special meaning. Just set mod_mask | |
2256 * to 0x0 so that typing Shift-Space in the GUI doesn't enter | |
2257 * the string <S-Space>. This should only happen after ^V. | |
2258 */ | |
2259 if (!IS_SPECIAL(c)) | |
2260 mod_mask = 0x0; | |
2261 break; | |
2262 } | |
2263 /* | |
2264 * End of switch on command line character. | |
2265 * We come here if we have a normal character. | |
2266 */ | |
2267 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2268 if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c)) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2269 && (ccheck_abbr( |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2270 // Add ABBR_OFF for characters above 0x100, this is |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2271 // what check_abbr() expects. |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2272 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : c) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
2273 || c == Ctrl_RSB)) |
7 | 2274 goto cmdline_changed; |
2275 | |
2276 /* | |
2277 * put the character in the command line | |
2278 */ | |
2279 if (IS_SPECIAL(c) || mod_mask != 0) | |
2280 put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE); | |
2281 else | |
2282 { | |
2283 if (has_mbyte) | |
2284 { | |
2285 j = (*mb_char2bytes)(c, IObuff); | |
2286 IObuff[j] = NUL; /* exclude composing chars */ | |
2287 put_on_cmdline(IObuff, j, TRUE); | |
2288 } | |
2289 else | |
2290 { | |
2291 IObuff[0] = c; | |
2292 put_on_cmdline(IObuff, 1, TRUE); | |
2293 } | |
2294 } | |
2295 goto cmdline_changed; | |
2296 | |
2297 /* | |
2298 * This part implements incremental searches for "/" and "?" | |
2299 * Jump to cmdline_not_changed when a character has been read but the command | |
2300 * line did not change. Then we only search and redraw if something changed in | |
2301 * the past. | |
2302 * Jump to cmdline_changed when the command line did change. | |
2303 * (Sorry for the goto's, I know it is ugly). | |
2304 */ | |
2305 cmdline_not_changed: | |
2306 #ifdef FEAT_SEARCH_EXTRA | |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2307 if (!is_state.incsearch_postponed) |
7 | 2308 continue; |
2309 #endif | |
2310 | |
2311 cmdline_changed: | |
13142
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2312 /* Trigger CmdlineChanged autocommands. */ |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2313 trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); |
59a16624400a
patch 8.0.1445: cannot act on edits in the command line
Christian Brabandt <cb@256bit.org>
parents:
13107
diff
changeset
|
2314 |
7 | 2315 #ifdef FEAT_SEARCH_EXTRA |
14503
4825955cb706
patch 8.1.0265: the getcmdline() function is way too big
Christian Brabandt <cb@256bit.org>
parents:
14439
diff
changeset
|
2316 may_do_incsearch_highlighting(firstc, count, &is_state); |
7 | 2317 #endif |
2318 | |
2319 #ifdef FEAT_RIGHTLEFT | |
2320 if (cmdmsg_rl | |
2321 # ifdef FEAT_ARABIC | |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2322 || (p_arshape && !p_tbidi |
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2323 && cmdline_has_arabic(0, ccline.cmdlen)) |
7 | 2324 # endif |
2325 ) | |
2326 /* Always redraw the whole command line to fix shaping and | |
3374 | 2327 * right-left typing. Not efficient, but it works. |
2328 * Do it only when there are no characters left to read | |
2329 * to avoid useless intermediate redraws. */ | |
2330 if (vpeekc() == NUL) | |
2331 redrawcmd(); | |
7 | 2332 #endif |
2333 } | |
2334 | |
2335 returncmd: | |
2336 | |
2337 #ifdef FEAT_RIGHTLEFT | |
2338 cmdmsg_rl = FALSE; | |
2339 #endif | |
2340 | |
2341 ExpandCleanup(&xpc); | |
1718 | 2342 ccline.xpc = NULL; |
7 | 2343 |
2344 #ifdef FEAT_SEARCH_EXTRA | |
14528
58ca11610819
patch 8.1.0277: 'incsearch' highlighting wrong in a few cases
Christian Brabandt <cb@256bit.org>
parents:
14524
diff
changeset
|
2345 finish_incsearch_highlighting(gotesc, &is_state, FALSE); |
7 | 2346 #endif |
2347 | |
2348 if (ccline.cmdbuff != NULL) | |
2349 { | |
2350 /* | |
2351 * Put line in history buffer (":" and "=" only when it was typed). | |
2352 */ | |
2353 if (ccline.cmdlen && firstc != NUL | |
2354 && (some_key_typed || histype == HIST_SEARCH)) | |
2355 { | |
2356 add_to_history(histype, ccline.cmdbuff, TRUE, | |
2357 histype == HIST_SEARCH ? firstc : NUL); | |
2358 if (firstc == ':') | |
2359 { | |
2360 vim_free(new_last_cmdline); | |
2361 new_last_cmdline = vim_strsave(ccline.cmdbuff); | |
2362 } | |
2363 } | |
2364 | |
12664
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2365 if (gotesc) |
42cd1f315e8b
patch 8.0.1210: CTRL-G and CTRL-T are ignored with typeahead
Christian Brabandt <cb@256bit.org>
parents:
12656
diff
changeset
|
2366 abandon_cmdline(); |
7 | 2367 } |
2368 | |
2369 /* | |
2370 * If the screen was shifted up, redraw the whole screen (later). | |
2371 * If the line is too long, clear it, so ruler and shown command do | |
2372 * not get printed in the middle of it. | |
2373 */ | |
2374 msg_check(); | |
2375 msg_scroll = save_msg_scroll; | |
2376 redir_off = FALSE; | |
2377 | |
2378 /* When the command line was typed, no need for a wait-return prompt. */ | |
2379 if (some_key_typed) | |
2380 need_wait_return = FALSE; | |
2381 | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2382 /* Trigger CmdlineLeave autocommands. */ |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2383 trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE); |
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2384 |
7 | 2385 State = save_State; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
2386 #ifdef HAVE_INPUT_METHOD |
7 | 2387 if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP) |
2388 im_save_status(b_im_ptr); | |
2389 im_set_active(FALSE); | |
2390 #endif | |
2391 #ifdef FEAT_MOUSE | |
2392 setmouse(); | |
2393 #endif | |
2394 #ifdef CURSOR_SHAPE | |
2395 ui_cursor_shape(); /* may show different cursor shape */ | |
2396 #endif | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2397 sb_text_end_cmdline(); |
7 | 2398 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2399 theend: |
95 | 2400 { |
2401 char_u *p = ccline.cmdbuff; | |
2402 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2403 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2404 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2405 else |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2406 ccline.cmdbuff = NULL; |
95 | 2407 return p; |
2408 } | |
7 | 2409 } |
2410 | |
2411 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
2412 /* | |
2413 * Get a command line with a prompt. | |
2414 * This is prepared to be called recursively from getcmdline() (e.g. by | |
2415 * f_input() when evaluating an expression from CTRL-R =). | |
2416 * Returns the command line in allocated memory, or NULL. | |
2417 */ | |
2418 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2419 getcmdline_prompt( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2420 int firstc, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2421 char_u *prompt, /* command line prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2422 int attr, /* attributes for prompt */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2423 int xp_context, /* type of expansion */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2424 char_u *xp_arg) /* user-defined expansion argument */ |
7 | 2425 { |
2426 char_u *s; | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
2427 cmdline_info_T save_ccline; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2428 int did_save_ccline = FALSE; |
7 | 2429 int msg_col_save = msg_col; |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2430 int msg_silent_save = msg_silent; |
7 | 2431 |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2432 if (ccline.cmdbuff != NULL) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2433 { |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2434 // Save the values of the current cmdline and restore them below. |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2435 save_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2436 did_save_ccline = TRUE; |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2437 } |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2438 |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
2439 vim_memset(&ccline, 0, sizeof(cmdline_info_T)); |
7 | 2440 ccline.cmdprompt = prompt; |
2441 ccline.cmdattr = attr; | |
531 | 2442 # ifdef FEAT_EVAL |
2443 ccline.xp_context = xp_context; | |
2444 ccline.xp_arg = xp_arg; | |
2445 ccline.input_fn = (firstc == '@'); | |
2446 # endif | |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2447 msg_silent = 0; |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2448 s = getcmdline_int(firstc, 1L, 0, FALSE); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2449 |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2450 if (did_save_ccline) |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2451 restore_cmdline(&save_ccline); |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
2452 |
8694
f2e81ae5ab48
commit https://github.com/vim/vim/commit/6135d0d803084f6c2dd8672df1bef4c6e58f9e19
Christian Brabandt <cb@256bit.org>
parents:
8647
diff
changeset
|
2453 msg_silent = msg_silent_save; |
3020 | 2454 /* Restore msg_col, the prompt from input() may have changed it. |
2455 * But only if called recursively and the commandline is therefore being | |
2456 * restored to an old one; if not, the input() prompt stays on the screen, | |
2457 * so we need its modified msg_col left intact. */ | |
2458 if (ccline.cmdbuff != NULL) | |
2459 msg_col = msg_col_save; | |
7 | 2460 |
2461 return s; | |
2462 } | |
2463 #endif | |
2464 | |
632 | 2465 /* |
634 | 2466 * Return TRUE when the text must not be changed and we can't switch to |
2467 * another window or buffer. Used when editing the command line, evaluating | |
2468 * 'balloonexpr', etc. | |
632 | 2469 */ |
2470 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2471 text_locked(void) |
632 | 2472 { |
2473 #ifdef FEAT_CMDWIN | |
2474 if (cmdwin_type != 0) | |
2475 return TRUE; | |
2476 #endif | |
634 | 2477 return textlock != 0; |
632 | 2478 } |
2479 | |
2480 /* | |
2481 * Give an error message for a command that isn't allowed while the cmdline | |
2482 * window is open or editing the cmdline in another way. | |
2483 */ | |
2484 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2485 text_locked_msg(void) |
632 | 2486 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2487 emsg(_(get_text_locked_msg())); |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2488 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2489 |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2490 char * |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2491 get_text_locked_msg(void) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2492 { |
632 | 2493 #ifdef FEAT_CMDWIN |
2494 if (cmdwin_type != 0) | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2495 return e_cmdwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2496 #endif |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2497 return e_secure; |
632 | 2498 } |
2499 | |
819 | 2500 /* |
1834 | 2501 * Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is |
2502 * and give an error message. | |
819 | 2503 */ |
2504 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2505 curbuf_locked(void) |
819 | 2506 { |
2507 if (curbuf_lock > 0) | |
2508 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2509 emsg(_("E788: Not allowed to edit another buffer now")); |
819 | 2510 return TRUE; |
2511 } | |
1834 | 2512 return allbuf_locked(); |
2513 } | |
2514 | |
2515 /* | |
2516 * Check if "allbuf_lock" is set and return TRUE when it is and give an error | |
2517 * message. | |
2518 */ | |
2519 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2520 allbuf_locked(void) |
1834 | 2521 { |
2522 if (allbuf_lock > 0) | |
2523 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
2524 emsg(_("E811: Not allowed to change buffer information now")); |
1834 | 2525 return TRUE; |
2526 } | |
819 | 2527 return FALSE; |
2528 } | |
2529 | |
7 | 2530 static int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2531 cmdline_charsize(int idx) |
7 | 2532 { |
2533 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
2534 if (cmdline_star > 0) /* showing '*', always 1 position */ | |
2535 return 1; | |
2536 #endif | |
2537 return ptr2cells(ccline.cmdbuff + idx); | |
2538 } | |
2539 | |
2540 /* | |
2541 * Compute the offset of the cursor on the command line for the prompt and | |
2542 * indent. | |
2543 */ | |
2544 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2545 set_cmdspos(void) |
7 | 2546 { |
531 | 2547 if (ccline.cmdfirstc != NUL) |
7 | 2548 ccline.cmdspos = 1 + ccline.cmdindent; |
2549 else | |
2550 ccline.cmdspos = 0 + ccline.cmdindent; | |
2551 } | |
2552 | |
2553 /* | |
2554 * Compute the screen position for the cursor on the command line. | |
2555 */ | |
2556 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2557 set_cmdspos_cursor(void) |
7 | 2558 { |
2559 int i, m, c; | |
2560 | |
2561 set_cmdspos(); | |
2562 if (KeyTyped) | |
534 | 2563 { |
7 | 2564 m = Columns * Rows; |
534 | 2565 if (m < 0) /* overflow, Columns or Rows at weird value */ |
2566 m = MAXCOL; | |
2567 } | |
7 | 2568 else |
2569 m = MAXCOL; | |
2570 for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) | |
2571 { | |
2572 c = cmdline_charsize(i); | |
2573 /* Count ">" for double-wide multi-byte char that doesn't fit. */ | |
2574 if (has_mbyte) | |
2575 correct_cmdspos(i, c); | |
1612 | 2576 /* If the cmdline doesn't fit, show cursor on last visible char. |
2577 * Don't move the cursor itself, so we can still append. */ | |
7 | 2578 if ((ccline.cmdspos += c) >= m) |
2579 { | |
2580 ccline.cmdspos -= c; | |
2581 break; | |
2582 } | |
2583 if (has_mbyte) | |
474 | 2584 i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1; |
7 | 2585 } |
2586 } | |
2587 | |
2588 /* | |
2589 * Check if the character at "idx", which is "cells" wide, is a multi-byte | |
2590 * character that doesn't fit, so that a ">" must be displayed. | |
2591 */ | |
2592 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2593 correct_cmdspos(int idx, int cells) |
7 | 2594 { |
474 | 2595 if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1 |
7 | 2596 && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1 |
2597 && ccline.cmdspos % Columns + cells > Columns) | |
2598 ccline.cmdspos++; | |
2599 } | |
2600 | |
2601 /* | |
2602 * Get an Ex command line for the ":" command. | |
2603 */ | |
2604 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2605 getexline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2606 int c, /* normally ':', NUL for ":append" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2607 void *cookie UNUSED, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2608 int indent, /* indent for inside conditionals */ |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2609 int do_concat) |
7 | 2610 { |
2611 /* When executing a register, remove ':' that's in front of each line. */ | |
2612 if (exec_from_reg && vpeekc() == ':') | |
2613 (void)vgetc(); | |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2614 return getcmdline(c, 1L, indent, do_concat); |
7 | 2615 } |
2616 | |
2617 /* | |
2618 * Get an Ex command line for Ex mode. | |
2619 * In Ex mode we only use the OS supplied line editing features and no | |
2620 * mappings or abbreviations. | |
168 | 2621 * Returns a string in allocated memory or NULL. |
7 | 2622 */ |
2623 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2624 getexmodeline( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2625 int promptc, /* normally ':', NUL for ":append" and '?' for |
168 | 2626 :s prompt */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2627 void *cookie UNUSED, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2628 int indent, /* indent for inside conditionals */ |
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
2629 int do_concat UNUSED) |
7 | 2630 { |
168 | 2631 garray_T line_ga; |
2632 char_u *pend; | |
2633 int startcol = 0; | |
1329 | 2634 int c1 = 0; |
168 | 2635 int escaped = FALSE; /* CTRL-V typed */ |
2636 int vcol = 0; | |
2637 char_u *p; | |
1329 | 2638 int prev_char; |
5966 | 2639 int len; |
7 | 2640 |
2641 /* Switch cursor on now. This avoids that it happens after the "\n", which | |
2642 * confuses the system function that computes tabstops. */ | |
2643 cursor_on(); | |
2644 | |
2645 /* always start in column 0; write a newline if necessary */ | |
2646 compute_cmdrow(); | |
168 | 2647 if ((msg_col || msg_didout) && promptc != '?') |
7 | 2648 msg_putchar('\n'); |
168 | 2649 if (promptc == ':') |
7 | 2650 { |
164 | 2651 /* indent that is only displayed, not in the line itself */ |
168 | 2652 if (p_prompt) |
2653 msg_putchar(':'); | |
7 | 2654 while (indent-- > 0) |
2655 msg_putchar(' '); | |
2656 startcol = msg_col; | |
2657 } | |
2658 | |
2659 ga_init2(&line_ga, 1, 30); | |
2660 | |
164 | 2661 /* autoindent for :insert and :append is in the line itself */ |
168 | 2662 if (promptc <= 0) |
164 | 2663 { |
2664 vcol = indent; | |
2665 while (indent >= 8) | |
2666 { | |
2667 ga_append(&line_ga, TAB); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2668 msg_puts(" "); |
164 | 2669 indent -= 8; |
2670 } | |
2671 while (indent-- > 0) | |
2672 { | |
2673 ga_append(&line_ga, ' '); | |
2674 msg_putchar(' '); | |
2675 } | |
2676 } | |
168 | 2677 ++no_mapping; |
2678 ++allow_keys; | |
164 | 2679 |
7 | 2680 /* |
2681 * Get the line, one character at a time. | |
2682 */ | |
2683 got_int = FALSE; | |
168 | 2684 while (!got_int) |
7 | 2685 { |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2686 long sw; |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2687 char_u *s; |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2688 |
7 | 2689 if (ga_grow(&line_ga, 40) == FAIL) |
2690 break; | |
2691 | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2692 /* |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2693 * Get one character at a time. |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2694 */ |
1329 | 2695 prev_char = c1; |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2696 |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2697 /* Check for a ":normal" command and no more characters left. */ |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2698 if (ex_normal_busy > 0 && typebuf.tb_len == 0) |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2699 c1 = '\n'; |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2700 else |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10942
diff
changeset
|
2701 c1 = vgetc(); |
7 | 2702 |
2703 /* | |
168 | 2704 * Handle line editing. |
2705 * Previously this was left to the system, putting the terminal in | |
2706 * cooked mode, but then CTRL-D and CTRL-T can't be used properly. | |
7 | 2707 */ |
168 | 2708 if (got_int) |
2709 { | |
2710 msg_putchar('\n'); | |
2711 break; | |
2712 } | |
2713 | |
10676
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2714 if (c1 == K_PS) |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2715 { |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2716 bracketed_paste(PASTE_EX, FALSE, &line_ga); |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2717 goto redraw; |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2718 } |
b8c04c007d39
patch 8.0.0228: pasting in xterm on the command line has PasteStart
Christian Brabandt <cb@256bit.org>
parents:
10565
diff
changeset
|
2719 |
168 | 2720 if (!escaped) |
7 | 2721 { |
168 | 2722 /* CR typed means "enter", which is NL */ |
2723 if (c1 == '\r') | |
2724 c1 = '\n'; | |
2725 | |
2726 if (c1 == BS || c1 == K_BS | |
2727 || c1 == DEL || c1 == K_DEL || c1 == K_KDEL) | |
7 | 2728 { |
168 | 2729 if (line_ga.ga_len > 0) |
2730 { | |
5966 | 2731 if (has_mbyte) |
2732 { | |
2733 p = (char_u *)line_ga.ga_data; | |
2734 p[line_ga.ga_len] = NUL; | |
2735 len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1; | |
2736 line_ga.ga_len -= len; | |
2737 } | |
2738 else | |
2739 --line_ga.ga_len; | |
168 | 2740 goto redraw; |
2741 } | |
2742 continue; | |
7 | 2743 } |
2744 | |
168 | 2745 if (c1 == Ctrl_U) |
7 | 2746 { |
168 | 2747 msg_col = startcol; |
2748 msg_clr_eos(); | |
2749 line_ga.ga_len = 0; | |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2750 goto redraw; |
168 | 2751 } |
2752 | |
2753 if (c1 == Ctrl_T) | |
2754 { | |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2755 sw = get_sw_value(curbuf); |
168 | 2756 p = (char_u *)line_ga.ga_data; |
2757 p[line_ga.ga_len] = NUL; | |
5995 | 2758 indent = get_indent_str(p, 8, FALSE); |
3740 | 2759 indent += sw - indent % sw; |
168 | 2760 add_indent: |
5995 | 2761 while (get_indent_str(p, 8, FALSE) < indent) |
7 | 2762 { |
7009 | 2763 (void)ga_grow(&line_ga, 2); /* one more for the NUL */ |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2764 p = (char_u *)line_ga.ga_data; |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2765 s = skipwhite(p); |
168 | 2766 mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); |
2767 *s = ' '; | |
2768 ++line_ga.ga_len; | |
7 | 2769 } |
168 | 2770 redraw: |
2771 /* redraw the line */ | |
2772 msg_col = startcol; | |
2773 vcol = 0; | |
5966 | 2774 p = (char_u *)line_ga.ga_data; |
2775 p[line_ga.ga_len] = NUL; | |
2776 while (p < (char_u *)line_ga.ga_data + line_ga.ga_len) | |
7 | 2777 { |
168 | 2778 if (*p == TAB) |
7 | 2779 { |
168 | 2780 do |
2781 msg_putchar(' '); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2782 while (++vcol % 8); |
5966 | 2783 ++p; |
7 | 2784 } |
168 | 2785 else |
164 | 2786 { |
5966 | 2787 len = MB_PTR2LEN(p); |
2788 msg_outtrans_len(p, len); | |
2789 vcol += ptr2cells(p); | |
2790 p += len; | |
7 | 2791 } |
2792 } | |
168 | 2793 msg_clr_eos(); |
1329 | 2794 windgoto(msg_row, msg_col); |
168 | 2795 continue; |
2796 } | |
2797 | |
2798 if (c1 == Ctrl_D) | |
2799 { | |
2800 /* Delete one shiftwidth. */ | |
2801 p = (char_u *)line_ga.ga_data; | |
2802 if (prev_char == '0' || prev_char == '^') | |
7 | 2803 { |
168 | 2804 if (prev_char == '^') |
2805 ex_keep_indent = TRUE; | |
2806 indent = 0; | |
2807 p[--line_ga.ga_len] = NUL; | |
7 | 2808 } |
2809 else | |
2810 { | |
168 | 2811 p[line_ga.ga_len] = NUL; |
5995 | 2812 indent = get_indent_str(p, 8, FALSE); |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2813 if (indent > 0) |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2814 { |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2815 --indent; |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2816 indent -= indent % get_sw_value(curbuf); |
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2817 } |
168 | 2818 } |
5995 | 2819 while (get_indent_str(p, 8, FALSE) > indent) |
168 | 2820 { |
6733
5f6077b10738
patch 7.4.690 for Problem: Memory access errors when changing indent in Ex mode. Also missing
Bram Moolenaar <bram@vim.org>
parents:
6695
diff
changeset
|
2821 s = skipwhite(p); |
168 | 2822 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); |
2823 --line_ga.ga_len; | |
7 | 2824 } |
168 | 2825 goto add_indent; |
2826 } | |
2827 | |
2828 if (c1 == Ctrl_V || c1 == Ctrl_Q) | |
2829 { | |
2830 escaped = TRUE; | |
2831 continue; | |
7 | 2832 } |
168 | 2833 |
2834 /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ | |
2835 if (IS_SPECIAL(c1)) | |
2836 continue; | |
7 | 2837 } |
168 | 2838 |
2839 if (IS_SPECIAL(c1)) | |
2840 c1 = '?'; | |
5966 | 2841 if (has_mbyte) |
2842 len = (*mb_char2bytes)(c1, | |
2843 (char_u *)line_ga.ga_data + line_ga.ga_len); | |
2844 else | |
2845 { | |
2846 len = 1; | |
2847 ((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1; | |
2848 } | |
168 | 2849 if (c1 == '\n') |
2850 msg_putchar('\n'); | |
2851 else if (c1 == TAB) | |
2852 { | |
2853 /* Don't use chartabsize(), 'ts' can be different */ | |
2854 do | |
2855 msg_putchar(' '); | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
2856 while (++vcol % 8); |
168 | 2857 } |
7 | 2858 else |
2859 { | |
168 | 2860 msg_outtrans_len( |
5966 | 2861 ((char_u *)line_ga.ga_data) + line_ga.ga_len, len); |
168 | 2862 vcol += char2cells(c1); |
7 | 2863 } |
5966 | 2864 line_ga.ga_len += len; |
168 | 2865 escaped = FALSE; |
2866 | |
2867 windgoto(msg_row, msg_col); | |
164 | 2868 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
168 | 2869 |
2590 | 2870 /* We are done when a NL is entered, but not when it comes after an |
2871 * odd number of backslashes, that results in a NUL. */ | |
2872 if (line_ga.ga_len > 0 && pend[-1] == '\n') | |
7 | 2873 { |
2590 | 2874 int bcount = 0; |
2875 | |
2876 while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\') | |
2877 ++bcount; | |
2878 | |
2879 if (bcount > 0) | |
2880 { | |
2881 /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> | |
2882 * "\NL", etc. */ | |
2883 line_ga.ga_len -= (bcount + 1) / 2; | |
2884 pend -= (bcount + 1) / 2; | |
2885 pend[-1] = '\n'; | |
2886 } | |
2887 | |
2888 if ((bcount & 1) == 0) | |
2889 { | |
2890 --line_ga.ga_len; | |
2891 --pend; | |
2892 *pend = NUL; | |
2893 break; | |
2894 } | |
7 | 2895 } |
2896 } | |
2897 | |
168 | 2898 --no_mapping; |
2899 --allow_keys; | |
2900 | |
7 | 2901 /* make following messages go to the next line */ |
2902 msg_didout = FALSE; | |
2903 msg_col = 0; | |
2904 if (msg_row < Rows - 1) | |
2905 ++msg_row; | |
2906 emsg_on_display = FALSE; /* don't want ui_delay() */ | |
2907 | |
2908 if (got_int) | |
2909 ga_clear(&line_ga); | |
2910 | |
2911 return (char_u *)line_ga.ga_data; | |
2912 } | |
2913 | |
502 | 2914 # if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \ |
2915 || defined(FEAT_MOUSESHAPE) || defined(PROTO) | |
7 | 2916 /* |
2917 * Return TRUE if ccline.overstrike is on. | |
2918 */ | |
2919 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2920 cmdline_overstrike(void) |
7 | 2921 { |
2922 return ccline.overstrike; | |
2923 } | |
2924 | |
2925 /* | |
2926 * Return TRUE if the cursor is at the end of the cmdline. | |
2927 */ | |
2928 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2929 cmdline_at_end(void) |
7 | 2930 { |
2931 return (ccline.cmdpos >= ccline.cmdlen); | |
2932 } | |
2933 #endif | |
2934 | |
574 | 2935 #if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO) |
7 | 2936 /* |
2937 * Return the virtual column number at the current cursor position. | |
2938 * This is used by the IM code to obtain the start of the preedit string. | |
2939 */ | |
2940 colnr_T | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2941 cmdline_getvcol_cursor(void) |
7 | 2942 { |
2943 if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen) | |
2944 return MAXCOL; | |
2945 | |
2946 if (has_mbyte) | |
2947 { | |
2948 colnr_T col; | |
2949 int i = 0; | |
2950 | |
2951 for (col = 0; i < ccline.cmdpos; ++col) | |
474 | 2952 i += (*mb_ptr2len)(ccline.cmdbuff + i); |
7 | 2953 |
2954 return col; | |
2955 } | |
2956 else | |
2957 return ccline.cmdpos; | |
2958 } | |
2959 #endif | |
2960 | |
2961 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
2962 /* | |
2963 * If part of the command line is an IM preedit string, redraw it with | |
2964 * IM feedback attributes. The cursor position is restored after drawing. | |
2965 */ | |
2966 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
2967 redrawcmd_preedit(void) |
7 | 2968 { |
2969 if ((State & CMDLINE) | |
2970 && xic != NULL | |
976 | 2971 /* && im_get_status() doesn't work when using SCIM */ |
7 | 2972 && !p_imdisable |
2973 && im_is_preediting()) | |
2974 { | |
2975 int cmdpos = 0; | |
2976 int cmdspos; | |
2977 int old_row; | |
2978 int old_col; | |
2979 colnr_T col; | |
2980 | |
2981 old_row = msg_row; | |
2982 old_col = msg_col; | |
531 | 2983 cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent; |
7 | 2984 |
2985 if (has_mbyte) | |
2986 { | |
2987 for (col = 0; col < preedit_start_col | |
2988 && cmdpos < ccline.cmdlen; ++col) | |
2989 { | |
2990 cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos); | |
474 | 2991 cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 2992 } |
2993 } | |
2994 else | |
2995 { | |
2996 cmdspos += preedit_start_col; | |
2997 cmdpos += preedit_start_col; | |
2998 } | |
2999 | |
3000 msg_row = cmdline_row + (cmdspos / (int)Columns); | |
3001 msg_col = cmdspos % (int)Columns; | |
3002 if (msg_row >= Rows) | |
3003 msg_row = Rows - 1; | |
3004 | |
3005 for (col = 0; cmdpos < ccline.cmdlen; ++col) | |
3006 { | |
3007 int char_len; | |
3008 int char_attr; | |
3009 | |
3010 char_attr = im_get_feedback_attr(col); | |
3011 if (char_attr < 0) | |
3012 break; /* end of preedit string */ | |
3013 | |
3014 if (has_mbyte) | |
474 | 3015 char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); |
7 | 3016 else |
3017 char_len = 1; | |
3018 | |
3019 msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr); | |
3020 cmdpos += char_len; | |
3021 } | |
3022 | |
3023 msg_row = old_row; | |
3024 msg_col = old_col; | |
3025 } | |
3026 } | |
3027 #endif /* FEAT_XIM && FEAT_GUI_GTK */ | |
3028 | |
3029 /* | |
3030 * Allocate a new command line buffer. | |
3031 * Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen. | |
3032 */ | |
3033 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3034 alloc_cmdbuff(int len) |
7 | 3035 { |
3036 /* | |
3037 * give some extra space to avoid having to allocate all the time | |
3038 */ | |
3039 if (len < 80) | |
3040 len = 100; | |
3041 else | |
3042 len += 20; | |
3043 | |
3044 ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ | |
3045 ccline.cmdbufflen = len; | |
3046 } | |
3047 | |
3048 /* | |
3049 * Re-allocate the command line to length len + something extra. | |
3050 * return FAIL for failure, OK otherwise | |
3051 */ | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3052 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3053 realloc_cmdbuff(int len) |
7 | 3054 { |
3055 char_u *p; | |
3056 | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3057 if (len < ccline.cmdbufflen) |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3058 return OK; /* no need to resize */ |
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3059 |
7 | 3060 p = ccline.cmdbuff; |
3061 alloc_cmdbuff(len); /* will get some more */ | |
3062 if (ccline.cmdbuff == NULL) /* out of memory */ | |
3063 { | |
3064 ccline.cmdbuff = p; /* keep the old one */ | |
3065 return FAIL; | |
3066 } | |
2556
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3067 /* There isn't always a NUL after the command, but it may need to be |
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3068 * there, thus copy up to the NUL and add a NUL. */ |
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3069 mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); |
e065501c703a
Fix illegal memory access when using expressions in the command line.
Bram Moolenaar <bram@vim.org>
parents:
2534
diff
changeset
|
3070 ccline.cmdbuff[ccline.cmdlen] = NUL; |
7 | 3071 vim_free(p); |
1718 | 3072 |
3073 if (ccline.xpc != NULL | |
3074 && ccline.xpc->xp_pattern != NULL | |
3075 && ccline.xpc->xp_context != EXPAND_NOTHING | |
3076 && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
3077 { | |
1754 | 3078 int i = (int)(ccline.xpc->xp_pattern - p); |
1718 | 3079 |
3080 /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
3081 * to point into the newly allocated memory. */ | |
3082 if (i >= 0 && i <= ccline.cmdlen) | |
3083 ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
3084 } | |
3085 | |
7 | 3086 return OK; |
3087 } | |
3088 | |
359 | 3089 #if defined(FEAT_ARABIC) || defined(PROTO) |
3090 static char_u *arshape_buf = NULL; | |
3091 | |
3092 # if defined(EXITFREE) || defined(PROTO) | |
3093 void | |
17266
a9556c0ba457
patch 8.1.1632: build with EXITFREE but without +arabic fails
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
3094 free_arshape_buf(void) |
359 | 3095 { |
3096 vim_free(arshape_buf); | |
3097 } | |
3098 # endif | |
3099 #endif | |
3100 | |
7 | 3101 /* |
3102 * Draw part of the cmdline at the current cursor position. But draw stars | |
3103 * when cmdline_star is TRUE. | |
3104 */ | |
3105 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3106 draw_cmdline(int start, int len) |
7 | 3107 { |
3108 #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
3109 int i; | |
3110 | |
3111 if (cmdline_star > 0) | |
3112 for (i = 0; i < len; ++i) | |
3113 { | |
3114 msg_putchar('*'); | |
3115 if (has_mbyte) | |
474 | 3116 i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1; |
7 | 3117 } |
3118 else | |
3119 #endif | |
3120 #ifdef FEAT_ARABIC | |
17155
da2bb80cd838
patch 8.1.1577: command line redrawn for +arabic without Arabic characters
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3121 if (p_arshape && !p_tbidi && cmdline_has_arabic(start, len)) |
7 | 3122 { |
3123 static int buflen = 0; | |
3124 char_u *p; | |
3125 int j; | |
3126 int newlen = 0; | |
3127 int mb_l; | |
719 | 3128 int pc, pc1 = 0; |
7 | 3129 int prev_c = 0; |
3130 int prev_c1 = 0; | |
714 | 3131 int u8c; |
3132 int u8cc[MAX_MCO]; | |
7 | 3133 int nc = 0; |
3134 | |
3135 /* | |
3136 * Do arabic shaping into a temporary buffer. This is very | |
3137 * inefficient! | |
3138 */ | |
507 | 3139 if (len * 2 + 2 > buflen) |
7 | 3140 { |
3141 /* Re-allocate the buffer. We keep it around to avoid a lot of | |
3142 * alloc()/free() calls. */ | |
359 | 3143 vim_free(arshape_buf); |
507 | 3144 buflen = len * 2 + 2; |
359 | 3145 arshape_buf = alloc(buflen); |
3146 if (arshape_buf == NULL) | |
7 | 3147 return; /* out of memory */ |
3148 } | |
3149 | |
507 | 3150 if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) |
3151 { | |
3152 /* Prepend a space to draw the leading composing char on. */ | |
3153 arshape_buf[0] = ' '; | |
3154 newlen = 1; | |
3155 } | |
3156 | |
7 | 3157 for (j = start; j < start + len; j += mb_l) |
3158 { | |
3159 p = ccline.cmdbuff + j; | |
714 | 3160 u8c = utfc_ptr2char_len(p, u8cc, start + len - j); |
474 | 3161 mb_l = utfc_ptr2len_len(p, start + len - j); |
7 | 3162 if (ARABIC_CHAR(u8c)) |
3163 { | |
3164 /* Do Arabic shaping. */ | |
3165 if (cmdmsg_rl) | |
3166 { | |
3167 /* displaying from right to left */ | |
3168 pc = prev_c; | |
3169 pc1 = prev_c1; | |
714 | 3170 prev_c1 = u8cc[0]; |
7 | 3171 if (j + mb_l >= start + len) |
3172 nc = NUL; | |
3173 else | |
3174 nc = utf_ptr2char(p + mb_l); | |
3175 } | |
3176 else | |
3177 { | |
3178 /* displaying from left to right */ | |
3179 if (j + mb_l >= start + len) | |
3180 pc = NUL; | |
3181 else | |
714 | 3182 { |
3183 int pcc[MAX_MCO]; | |
3184 | |
3185 pc = utfc_ptr2char_len(p + mb_l, pcc, | |
7 | 3186 start + len - j - mb_l); |
714 | 3187 pc1 = pcc[0]; |
3188 } | |
7 | 3189 nc = prev_c; |
3190 } | |
3191 prev_c = u8c; | |
3192 | |
714 | 3193 u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); |
7 | 3194 |
359 | 3195 newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen); |
714 | 3196 if (u8cc[0] != 0) |
7 | 3197 { |
714 | 3198 newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen); |
3199 if (u8cc[1] != 0) | |
3200 newlen += (*mb_char2bytes)(u8cc[1], | |
359 | 3201 arshape_buf + newlen); |
7 | 3202 } |
3203 } | |
3204 else | |
3205 { | |
3206 prev_c = u8c; | |
359 | 3207 mch_memmove(arshape_buf + newlen, p, mb_l); |
7 | 3208 newlen += mb_l; |
3209 } | |
3210 } | |
3211 | |
359 | 3212 msg_outtrans_len(arshape_buf, newlen); |
7 | 3213 } |
3214 else | |
3215 #endif | |
3216 msg_outtrans_len(ccline.cmdbuff + start, len); | |
3217 } | |
3218 | |
3219 /* | |
3220 * Put a character on the command line. Shifts the following text to the | |
3221 * right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc. | |
3222 * "c" must be printable (fit in one display cell)! | |
3223 */ | |
3224 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3225 putcmdline(int c, int shift) |
7 | 3226 { |
3227 if (cmd_silent) | |
3228 return; | |
3229 msg_no_more = TRUE; | |
3230 msg_putchar(c); | |
3231 if (shift) | |
3232 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); | |
3233 msg_no_more = FALSE; | |
3234 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3235 extra_char = c; |
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3236 extra_char_shift = shift; |
7 | 3237 } |
3238 | |
3239 /* | |
3240 * Undo a putcmdline(c, FALSE). | |
3241 */ | |
3242 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3243 unputcmdline(void) |
7 | 3244 { |
3245 if (cmd_silent) | |
3246 return; | |
3247 msg_no_more = TRUE; | |
3248 if (ccline.cmdlen == ccline.cmdpos) | |
3249 msg_putchar(' '); | |
3558 | 3250 else if (has_mbyte) |
3251 draw_cmdline(ccline.cmdpos, | |
3252 (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos)); | |
7 | 3253 else |
3254 draw_cmdline(ccline.cmdpos, 1); | |
3255 msg_no_more = FALSE; | |
3256 cursorcmd(); | |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3257 extra_char = NUL; |
7 | 3258 } |
3259 | |
3260 /* | |
3261 * Put the given string, of the given length, onto the command line. | |
3262 * If len is -1, then STRLEN() is used to calculate the length. | |
3263 * If 'redraw' is TRUE then the new part of the command line, and the remaining | |
3264 * part will be redrawn, otherwise it will not. If this function is called | |
3265 * twice in a row, then 'redraw' should be FALSE and redrawcmd() should be | |
3266 * called afterwards. | |
3267 */ | |
3268 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3269 put_on_cmdline(char_u *str, int len, int redraw) |
7 | 3270 { |
3271 int retval; | |
3272 int i; | |
3273 int m; | |
3274 int c; | |
3275 | |
3276 if (len < 0) | |
3277 len = (int)STRLEN(str); | |
3278 | |
3279 /* Check if ccline.cmdbuff needs to be longer */ | |
3280 if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) | |
2557
029ace8dff7d
Now really fix using expressions in the command line (hopefully).
Bram Moolenaar <bram@vim.org>
parents:
2556
diff
changeset
|
3281 retval = realloc_cmdbuff(ccline.cmdlen + len + 1); |
7 | 3282 else |
3283 retval = OK; | |
3284 if (retval == OK) | |
3285 { | |
3286 if (!ccline.overstrike) | |
3287 { | |
3288 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3289 ccline.cmdbuff + ccline.cmdpos, | |
3290 (size_t)(ccline.cmdlen - ccline.cmdpos)); | |
3291 ccline.cmdlen += len; | |
3292 } | |
3293 else | |
3294 { | |
3295 if (has_mbyte) | |
3296 { | |
3297 /* Count nr of characters in the new string. */ | |
3298 m = 0; | |
474 | 3299 for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) |
7 | 3300 ++m; |
3301 /* Count nr of bytes in cmdline that are overwritten by these | |
3302 * characters. */ | |
3303 for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; | |
474 | 3304 i += (*mb_ptr2len)(ccline.cmdbuff + i)) |
7 | 3305 --m; |
3306 if (i < ccline.cmdlen) | |
3307 { | |
3308 mch_memmove(ccline.cmdbuff + ccline.cmdpos + len, | |
3309 ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i)); | |
3310 ccline.cmdlen += ccline.cmdpos + len - i; | |
3311 } | |
3312 else | |
3313 ccline.cmdlen = ccline.cmdpos + len; | |
3314 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3315 else if (ccline.cmdpos + len > ccline.cmdlen) |
7 | 3316 ccline.cmdlen = ccline.cmdpos + len; |
3317 } | |
3318 mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len); | |
3319 ccline.cmdbuff[ccline.cmdlen] = NUL; | |
3320 | |
3321 if (enc_utf8) | |
3322 { | |
3323 /* When the inserted text starts with a composing character, | |
3324 * backup to the character before it. There could be two of them. | |
3325 */ | |
3326 i = 0; | |
3327 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3328 while (ccline.cmdpos > 0 && utf_iscomposing(c)) | |
3329 { | |
3330 i = (*mb_head_off)(ccline.cmdbuff, | |
3331 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3332 ccline.cmdpos -= i; | |
3333 len += i; | |
3334 c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); | |
3335 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3336 #ifdef FEAT_ARABIC |
7 | 3337 if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) |
3338 { | |
3339 /* Check the previous character for Arabic combining pair. */ | |
3340 i = (*mb_head_off)(ccline.cmdbuff, | |
3341 ccline.cmdbuff + ccline.cmdpos - 1) + 1; | |
3342 if (arabic_combine(utf_ptr2char(ccline.cmdbuff | |
3343 + ccline.cmdpos - i), c)) | |
3344 { | |
3345 ccline.cmdpos -= i; | |
3346 len += i; | |
3347 } | |
3348 else | |
3349 i = 0; | |
3350 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15575
diff
changeset
|
3351 #endif |
7 | 3352 if (i != 0) |
3353 { | |
3354 /* Also backup the cursor position. */ | |
3355 i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); | |
3356 ccline.cmdspos -= i; | |
3357 msg_col -= i; | |
3358 if (msg_col < 0) | |
3359 { | |
3360 msg_col += Columns; | |
3361 --msg_row; | |
3362 } | |
3363 } | |
3364 } | |
3365 | |
3366 if (redraw && !cmd_silent) | |
3367 { | |
3368 msg_no_more = TRUE; | |
3369 i = cmdline_row; | |
3114 | 3370 cursorcmd(); |
7 | 3371 draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); |
3372 /* Avoid clearing the rest of the line too often. */ | |
3373 if (cmdline_row != i || ccline.overstrike) | |
3374 msg_clr_eos(); | |
3375 msg_no_more = FALSE; | |
3376 } | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3377 if (KeyTyped) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3378 { |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3379 m = Columns * Rows; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3380 if (m < 0) /* overflow, Columns or Rows at weird value */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3381 m = MAXCOL; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3382 } |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3383 else |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3384 m = MAXCOL; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3385 for (i = 0; i < len; ++i) |
7 | 3386 { |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3387 c = cmdline_charsize(ccline.cmdpos); |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3388 /* count ">" for a double-wide char that doesn't fit. */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3389 if (has_mbyte) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3390 correct_cmdspos(ccline.cmdpos, c); |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3391 /* Stop cursor at the end of the screen, but do increment the |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3392 * insert position, so that entering a very long command |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3393 * works, even though you can't see it. */ |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3394 if (ccline.cmdspos + c < m) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3395 ccline.cmdspos += c; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3396 |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3397 if (has_mbyte) |
7 | 3398 { |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3399 c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3400 if (c > len - i - 1) |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3401 c = len - i - 1; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3402 ccline.cmdpos += c; |
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3403 i += c; |
7 | 3404 } |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3405 ++ccline.cmdpos; |
7 | 3406 } |
3407 } | |
3408 if (redraw) | |
3409 msg_check(); | |
3410 return retval; | |
3411 } | |
3412 | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3413 static cmdline_info_T prev_ccline; |
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3414 static int prev_ccline_used = FALSE; |
95 | 3415 |
3416 /* | |
3417 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
3418 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
3419 * available globally in prev_ccline. | |
3420 */ | |
3421 static void | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3422 save_cmdline(cmdline_info_T *ccp) |
95 | 3423 { |
3424 if (!prev_ccline_used) | |
3425 { | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3426 vim_memset(&prev_ccline, 0, sizeof(cmdline_info_T)); |
95 | 3427 prev_ccline_used = TRUE; |
3428 } | |
3429 *ccp = prev_ccline; | |
3430 prev_ccline = ccline; | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3431 ccline.cmdbuff = NULL; // signal that ccline is not in use |
95 | 3432 } |
3433 | |
3434 /* | |
1214 | 3435 * Restore ccline after it has been saved with save_cmdline(). |
95 | 3436 */ |
3437 static void | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3438 restore_cmdline(cmdline_info_T *ccp) |
95 | 3439 { |
3440 ccline = prev_ccline; | |
3441 prev_ccline = *ccp; | |
3442 } | |
3443 | |
15 | 3444 /* |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3445 * Paste a yank register into the command line. |
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3446 * Used by CTRL-R command in command-line mode. |
15 | 3447 * insert_reg() can't be used here, because special characters from the |
3448 * register contents will be interpreted as commands. | |
3449 * | |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7250
diff
changeset
|
3450 * Return FAIL for failure, OK otherwise. |
15 | 3451 */ |
3452 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3453 cmdline_paste( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3454 int regname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3455 int literally, /* Insert text literally instead of "as typed" */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3456 int remcr) /* remove trailing CR */ |
15 | 3457 { |
3458 long i; | |
3459 char_u *arg; | |
772 | 3460 char_u *p; |
15 | 3461 int allocated; |
3462 | |
3463 /* check for valid regname; also accept special characters for CTRL-R in | |
3464 * the command line */ | |
3465 if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3466 && regname != Ctrl_A && regname != Ctrl_L |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13794
diff
changeset
|
3467 && !valid_yank_reg(regname, FALSE)) |
15 | 3468 return FAIL; |
3469 | |
3470 /* A register containing CTRL-R can cause an endless loop. Allow using | |
3471 * CTRL-C to break the loop. */ | |
3472 line_breakcheck(); | |
3473 if (got_int) | |
3474 return FAIL; | |
3475 | |
3476 #ifdef FEAT_CLIPBOARD | |
3477 regname = may_get_selection(regname); | |
3478 #endif | |
3479 | |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3480 // Need to set "textlock" to avoid nasty things like going to another |
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3481 // buffer when evaluating an expression. |
634 | 3482 ++textlock; |
15 | 3483 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
634 | 3484 --textlock; |
15 | 3485 |
3486 if (i) | |
3487 { | |
3488 /* Got the value of a special register in "arg". */ | |
3489 if (arg == NULL) | |
3490 return FAIL; | |
772 | 3491 |
3492 /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate | |
3493 * part of the word. */ | |
3494 p = arg; | |
3495 if (p_is && regname == Ctrl_W) | |
3496 { | |
3497 char_u *w; | |
3498 int len; | |
3499 | |
3500 /* Locate start of last word in the cmd buffer. */ | |
2937 | 3501 for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) |
772 | 3502 { |
3503 if (has_mbyte) | |
3504 { | |
3505 len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1; | |
3506 if (!vim_iswordc(mb_ptr2char(w - len))) | |
3507 break; | |
3508 w -= len; | |
3509 } | |
3510 else | |
3511 { | |
3512 if (!vim_iswordc(w[-1])) | |
3513 break; | |
3514 --w; | |
3515 } | |
3516 } | |
2937 | 3517 len = (int)((ccline.cmdbuff + ccline.cmdpos) - w); |
772 | 3518 if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0) |
3519 p += len; | |
3520 } | |
3521 | |
3522 cmdline_paste_str(p, literally); | |
15 | 3523 if (allocated) |
3524 vim_free(arg); | |
3525 return OK; | |
3526 } | |
3527 | |
1015 | 3528 return cmdline_paste_reg(regname, literally, remcr); |
15 | 3529 } |
3530 | |
3531 /* | |
3532 * Put a string on the command line. | |
3533 * When "literally" is TRUE, insert literally. | |
3534 * When "literally" is FALSE, insert as typed, but don't leave the command | |
3535 * line. | |
3536 */ | |
3537 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3538 cmdline_paste_str(char_u *s, int literally) |
15 | 3539 { |
3540 int c, cv; | |
3541 | |
3542 if (literally) | |
3543 put_on_cmdline(s, -1, TRUE); | |
3544 else | |
3545 while (*s != NUL) | |
3546 { | |
3547 cv = *s; | |
3548 if (cv == Ctrl_V && s[1]) | |
3549 ++s; | |
3550 if (has_mbyte) | |
1606 | 3551 c = mb_cptr2char_adv(&s); |
15 | 3552 else |
3553 c = *s++; | |
3628 | 3554 if (cv == Ctrl_V || c == ESC || c == Ctrl_C |
3555 || c == CAR || c == NL || c == Ctrl_L | |
15 | 3556 #ifdef UNIX |
3557 || c == intr_char | |
3558 #endif | |
3559 || (c == Ctrl_BSL && *s == Ctrl_N)) | |
3560 stuffcharReadbuff(Ctrl_V); | |
3561 stuffcharReadbuff(c); | |
3562 } | |
3563 } | |
3564 | |
7 | 3565 #ifdef FEAT_WILDMENU |
3566 /* | |
3567 * Delete characters on the command line, from "from" to the current | |
3568 * position. | |
3569 */ | |
3570 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3571 cmdline_del(int from) |
7 | 3572 { |
3573 mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos, | |
3574 (size_t)(ccline.cmdlen - ccline.cmdpos + 1)); | |
3575 ccline.cmdlen -= ccline.cmdpos - from; | |
3576 ccline.cmdpos = from; | |
3577 } | |
3578 #endif | |
3579 | |
3580 /* | |
9066
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3581 * This function is called when the screen size changes and with incremental |
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3582 * search and in other situations where the command line may have been |
c7bdd383275d
commit https://github.com/vim/vim/commit/89c79b99328b66f77f1d12dc8c6701dfe2c57f15
Christian Brabandt <cb@256bit.org>
parents:
8765
diff
changeset
|
3583 * overwritten. |
7 | 3584 */ |
3585 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3586 redrawcmdline(void) |
7 | 3587 { |
11416
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3588 redrawcmdline_ex(TRUE); |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3589 } |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3590 |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3591 void |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3592 redrawcmdline_ex(int do_compute_cmdrow) |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3593 { |
7 | 3594 if (cmd_silent) |
3595 return; | |
3596 need_wait_return = FALSE; | |
11416
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3597 if (do_compute_cmdrow) |
32aed0993813
patch 8.0.0592: if a job writes to a buffer screen is not updated
Christian Brabandt <cb@256bit.org>
parents:
11321
diff
changeset
|
3598 compute_cmdrow(); |
7 | 3599 redrawcmd(); |
3600 cursorcmd(); | |
3601 } | |
3602 | |
3603 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3604 redrawcmdprompt(void) |
7 | 3605 { |
3606 int i; | |
3607 | |
3608 if (cmd_silent) | |
3609 return; | |
531 | 3610 if (ccline.cmdfirstc != NUL) |
7 | 3611 msg_putchar(ccline.cmdfirstc); |
3612 if (ccline.cmdprompt != NULL) | |
3613 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3614 msg_puts_attr((char *)ccline.cmdprompt, ccline.cmdattr); |
7 | 3615 ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; |
3616 /* do the reverse of set_cmdspos() */ | |
531 | 3617 if (ccline.cmdfirstc != NUL) |
7 | 3618 --ccline.cmdindent; |
3619 } | |
3620 else | |
3621 for (i = ccline.cmdindent; i > 0; --i) | |
3622 msg_putchar(' '); | |
3623 } | |
3624 | |
3625 /* | |
3626 * Redraw what is currently on the command line. | |
3627 */ | |
3628 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3629 redrawcmd(void) |
7 | 3630 { |
3631 if (cmd_silent) | |
3632 return; | |
3633 | |
683 | 3634 /* when 'incsearch' is set there may be no command line while redrawing */ |
3635 if (ccline.cmdbuff == NULL) | |
3636 { | |
3637 windgoto(cmdline_row, 0); | |
3638 msg_clr_eos(); | |
3639 return; | |
3640 } | |
3641 | |
7 | 3642 msg_start(); |
3643 redrawcmdprompt(); | |
3644 | |
3645 /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ | |
3646 msg_no_more = TRUE; | |
3647 draw_cmdline(0, ccline.cmdlen); | |
3648 msg_clr_eos(); | |
3649 msg_no_more = FALSE; | |
3650 | |
3651 set_cmdspos_cursor(); | |
11664
e3bfe624ba0a
patch 8.0.0714: when a timer causes a command line redraw " goes missing
Christian Brabandt <cb@256bit.org>
parents:
11647
diff
changeset
|
3652 if (extra_char != NUL) |
11674
d093e4167733
patch 8.0.0720: unfinished mapping not displayed when running timer
Christian Brabandt <cb@256bit.org>
parents:
11664
diff
changeset
|
3653 putcmdline(extra_char, extra_char_shift); |
7 | 3654 |
3655 /* | |
3656 * An emsg() before may have set msg_scroll. This is used in normal mode, | |
3657 * in cmdline mode we can reset them now. | |
3658 */ | |
3659 msg_scroll = FALSE; /* next message overwrites cmdline */ | |
3660 | |
3661 /* Typing ':' at the more prompt may set skip_redraw. We don't want this | |
3662 * in cmdline mode */ | |
3663 skip_redraw = FALSE; | |
3664 } | |
3665 | |
3666 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3667 compute_cmdrow(void) |
7 | 3668 { |
540 | 3669 if (exmode_active || msg_scrolled != 0) |
7 | 3670 cmdline_row = Rows - 1; |
3671 else | |
3672 cmdline_row = W_WINROW(lastwin) + lastwin->w_height | |
12529
158917d728b4
patch 8.0.1143: macros always expand to the same thing
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3673 + lastwin->w_status_height; |
7 | 3674 } |
3675 | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3676 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3677 cursorcmd(void) |
7 | 3678 { |
3679 if (cmd_silent) | |
3680 return; | |
3681 | |
3682 #ifdef FEAT_RIGHTLEFT | |
3683 if (cmdmsg_rl) | |
3684 { | |
3685 msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1)); | |
3686 msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1; | |
3687 if (msg_row <= 0) | |
3688 msg_row = Rows - 1; | |
3689 } | |
3690 else | |
3691 #endif | |
3692 { | |
3693 msg_row = cmdline_row + (ccline.cmdspos / (int)Columns); | |
3694 msg_col = ccline.cmdspos % (int)Columns; | |
3695 if (msg_row >= Rows) | |
3696 msg_row = Rows - 1; | |
3697 } | |
3698 | |
3699 windgoto(msg_row, msg_col); | |
3700 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
12293
1ff5e5dfa9b0
patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents:
11995
diff
changeset
|
3701 if (p_imst == IM_ON_THE_SPOT) |
1ff5e5dfa9b0
patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents:
11995
diff
changeset
|
3702 redrawcmd_preedit(); |
7 | 3703 #endif |
3704 #ifdef MCH_CURSOR_SHAPE | |
3705 mch_update_cursor(); | |
3706 #endif | |
3707 } | |
3708 | |
3709 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3710 gotocmdline(int clr) |
7 | 3711 { |
3712 msg_start(); | |
3713 #ifdef FEAT_RIGHTLEFT | |
3714 if (cmdmsg_rl) | |
3715 msg_col = Columns - 1; | |
3716 else | |
3717 #endif | |
3718 msg_col = 0; /* always start in column 0 */ | |
3719 if (clr) /* clear the bottom line(s) */ | |
3720 msg_clr_eos(); /* will reset clear_cmdline */ | |
3721 windgoto(cmdline_row, 0); | |
3722 } | |
3723 | |
3724 /* | |
3725 * Check the word in front of the cursor for an abbreviation. | |
3726 * Called when the non-id character "c" has been entered. | |
3727 * When an abbreviation is recognized it is removed from the text with | |
3728 * backspaces and the replacement string is inserted, followed by "c". | |
3729 */ | |
3730 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3731 ccheck_abbr(int c) |
7 | 3732 { |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3733 int spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3734 |
7 | 3735 if (p_paste || no_abbr) /* no abbreviations or in paste mode */ |
3736 return FALSE; | |
3737 | |
13933
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3738 /* Do not consider '<,'> be part of the mapping, skip leading whitespace. |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3739 * Actually accepts any mark. */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3740 while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3741 spos++; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3742 if (ccline.cmdlen - spos > 5 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3743 && ccline.cmdbuff[spos] == '\'' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3744 && ccline.cmdbuff[spos + 2] == ',' |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3745 && ccline.cmdbuff[spos + 3] == '\'') |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3746 spos += 5; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3747 else |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3748 /* check abbreviation from the beginning of the commandline */ |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3749 spos = 0; |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3750 |
bea665293ea0
patch 8.0.1837: one character cmdline abbreviation not triggered after '<,'>
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
3751 return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); |
7 | 3752 } |
3753 | |
3754 /* | |
1586 | 3755 * Escape special characters in "fname" for when used as a file name argument |
3756 * after a Vim command, or, when "shell" is non-zero, a shell command. | |
3757 * Returns the result in allocated memory. | |
3758 */ | |
3759 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3760 vim_strsave_fnameescape(char_u *fname, int shell) |
1586 | 3761 { |
1685 | 3762 char_u *p; |
1586 | 3763 #ifdef BACKSLASH_IN_FILENAME |
3764 char_u buf[20]; | |
3765 int j = 0; | |
3766 | |
5481 | 3767 /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ |
1586 | 3768 for (p = PATH_ESC_CHARS; *p != NUL; ++p) |
5481 | 3769 if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) |
1586 | 3770 buf[j++] = *p; |
3771 buf[j] = NUL; | |
1700 | 3772 p = vim_strsave_escaped(fname, buf); |
1586 | 3773 #else |
1685 | 3774 p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS); |
3775 if (shell && csh_like_shell() && p != NULL) | |
3776 { | |
3777 char_u *s; | |
3778 | |
3779 /* For csh and similar shells need to put two backslashes before '!'. | |
3780 * One is taken by Vim, one by the shell. */ | |
3781 s = vim_strsave_escaped(p, (char_u *)"!"); | |
3782 vim_free(p); | |
3783 p = s; | |
3784 } | |
1700 | 3785 #endif |
3786 | |
3787 /* '>' and '+' are special at the start of some commands, e.g. ":edit" and | |
3788 * ":write". "cd -" has a special meaning. */ | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2433
diff
changeset
|
3789 if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) |
1700 | 3790 escape_fname(&p); |
3791 | |
1685 | 3792 return p; |
1586 | 3793 } |
3794 | |
3795 /* | |
435 | 3796 * Put a backslash before the file name in "pp", which is in allocated memory. |
3797 */ | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3798 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3799 escape_fname(char_u **pp) |
435 | 3800 { |
3801 char_u *p; | |
3802 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
3803 p = alloc(STRLEN(*pp) + 2); |
435 | 3804 if (p != NULL) |
3805 { | |
3806 p[0] = '\\'; | |
3807 STRCPY(p + 1, *pp); | |
3808 vim_free(*pp); | |
3809 *pp = p; | |
3810 } | |
3811 } | |
3812 | |
3813 /* | |
7 | 3814 * For each file name in files[num_files]: |
3815 * If 'orig_pat' starts with "~/", replace the home directory with "~". | |
3816 */ | |
3817 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3818 tilde_replace( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3819 char_u *orig_pat, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3820 int num_files, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3821 char_u **files) |
7 | 3822 { |
3823 int i; | |
3824 char_u *p; | |
3825 | |
3826 if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) | |
3827 { | |
3828 for (i = 0; i < num_files; ++i) | |
3829 { | |
3830 p = home_replace_save(NULL, files[i]); | |
3831 if (p != NULL) | |
3832 { | |
3833 vim_free(files[i]); | |
3834 files[i] = p; | |
3835 } | |
3836 } | |
3837 } | |
3838 } | |
3839 | |
3840 /* | |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3841 * Get a pointer to the current command line info. |
7 | 3842 */ |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3843 cmdline_info_T * |
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3844 get_cmdline_info(void) |
7 | 3845 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3846 return &ccline; |
7 | 3847 } |
3848 | |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3849 #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO) |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3850 /* |
14854
3b72808fbb0d
patch 8.1.0439: recursive use of getcmdline() still not protected
Christian Brabandt <cb@256bit.org>
parents:
14848
diff
changeset
|
3851 * Get pointer to the command line info to use. save_ccline() may clear |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3852 * ccline and put the previous value in prev_ccline. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3853 */ |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3854 static cmdline_info_T * |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3855 get_ccline_ptr(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3856 { |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3857 if ((State & CMDLINE) == 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3858 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3859 if (ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3860 return &ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3861 if (prev_ccline_used && prev_ccline.cmdbuff != NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3862 return &prev_ccline; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3863 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3864 } |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3865 #endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3866 |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3867 #if defined(FEAT_EVAL) || defined(PROTO) |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3868 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3869 * Get the current command line in allocated memory. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3870 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3871 * Returns NULL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3872 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3873 char_u * |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3874 get_cmdline_str(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3875 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3876 cmdline_info_T *p; |
14848
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
3877 |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
3878 if (cmdline_star > 0) |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
3879 return NULL; |
45d8aa272dbe
patch 8.1.0436: can get the text of inputsecret() with getcmdline()
Christian Brabandt <cb@256bit.org>
parents:
14842
diff
changeset
|
3880 p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3881 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3882 return NULL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3883 return vim_strnsave(p->cmdbuff, p->cmdlen); |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3884 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3885 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3886 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3887 * Get the current command line position, counted in bytes. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3888 * Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3889 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3890 * Returns -1 when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3891 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3892 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3893 get_cmdline_pos(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3894 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3895 cmdline_info_T *p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3896 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3897 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3898 return -1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3899 return p->cmdpos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3900 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3901 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3902 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3903 * Set the command line byte position to "pos". Zero is the first position. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3904 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3905 * Returns 1 when failed, 0 when OK. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3906 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3907 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3908 set_cmdline_pos( |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3909 int pos) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3910 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3911 cmdline_info_T *p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3912 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3913 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3914 return 1; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3915 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3916 /* The position is not set directly but after CTRL-\ e or CTRL-R = has |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3917 * changed the command line. */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3918 if (pos < 0) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3919 new_cmdpos = 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3920 else |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3921 new_cmdpos = pos; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3922 return 0; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3923 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3924 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3925 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3926 #if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3927 /* |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3928 * Get the current command-line type. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3929 * Returns ':' or '/' or '?' or '@' or '>' or '-' |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3930 * Only works when the command line is being edited. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3931 * Returns NUL when something is wrong. |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3932 */ |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3933 int |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3934 get_cmdline_type(void) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3935 { |
17779
87a8760babec
patch 8.1.1886: command line expansion code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
3936 cmdline_info_T *p = get_ccline_ptr(); |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3937 |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3938 if (p == NULL) |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3939 return NUL; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3940 if (p->cmdfirstc == NUL) |
8647
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3941 return |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3942 # ifdef FEAT_EVAL |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3943 (p->input_fn) ? '@' : |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3944 # endif |
59866aabe737
commit https://github.com/vim/vim/commit/064154c3fedd6a46ca2f61463d7e5567bd22d9f1
Christian Brabandt <cb@256bit.org>
parents:
8645
diff
changeset
|
3945 '-'; |
8645
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3946 return p->cmdfirstc; |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3947 } |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3948 #endif |
f4819f0fc5ad
commit https://github.com/vim/vim/commit/d293b2b9d43ee4b7b48ca6974202cbf319438975
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
3949 |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3950 /* |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3951 * Return the first character of the current command line. |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3952 */ |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3953 int |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3954 get_cmdline_firstc(void) |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3955 { |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3956 return ccline.cmdfirstc; |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3957 } |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
3958 |
7 | 3959 /* |
3960 * Get indices "num1,num2" that specify a range within a list (not a range of | |
3961 * text lines in a buffer!) from a string. Used for ":history" and ":clist". | |
3962 * Returns OK if parsed successfully, otherwise FAIL. | |
3963 */ | |
3964 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
3965 get_list_range(char_u **str, int *num1, int *num2) |
7 | 3966 { |
3967 int len; | |
3968 int first = FALSE; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9301
diff
changeset
|
3969 varnumber_T num; |
7 | 3970 |
3971 *str = skipwhite(*str); | |
3972 if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ | |
3973 { | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3974 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); |
7 | 3975 *str += len; |
3976 *num1 = (int)num; | |
3977 first = TRUE; | |
3978 } | |
3979 *str = skipwhite(*str); | |
3980 if (**str == ',') /* parse "to" part of range */ | |
3981 { | |
3982 *str = skipwhite(*str + 1); | |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3983 vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); |
7 | 3984 if (len > 0) |
3985 { | |
3986 *num2 = (int)num; | |
3987 *str = skipwhite(*str + len); | |
3988 } | |
3989 else if (!first) /* no number given at all */ | |
3990 return FAIL; | |
3991 } | |
3992 else if (first) /* only one number given */ | |
3993 *num2 = *num1; | |
3994 return OK; | |
3995 } | |
3996 | |
3997 #if defined(FEAT_CMDWIN) || defined(PROTO) | |
3998 /* | |
3999 * Open a window on the current command line and history. Allow editing in | |
4000 * the window. Returns when the window is closed. | |
4001 * Returns: | |
4002 * CR if the command is to be executed | |
4003 * Ctrl_C if it is to be abandoned | |
4004 * K_IGNORE if editing continues | |
4005 */ | |
4006 static int | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
4007 open_cmdwin(void) |
7 | 4008 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4009 bufref_T old_curbuf; |
7 | 4010 win_T *old_curwin = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4011 bufref_T bufref; |
7 | 4012 win_T *wp; |
4013 int i; | |
4014 linenr_T lnum; | |
4015 int histtype; | |
4016 garray_T winsizes; | |
4017 int save_restart_edit = restart_edit; | |
4018 int save_State = State; | |
4019 int save_exmode = exmode_active; | |
510 | 4020 #ifdef FEAT_RIGHTLEFT |
4021 int save_cmdmsg_rl = cmdmsg_rl; | |
4022 #endif | |
6145 | 4023 #ifdef FEAT_FOLDING |
4024 int save_KeyTyped; | |
4025 #endif | |
7 | 4026 |
4027 /* Can't do this recursively. Can't do it when typing a password. */ | |
4028 if (cmdwin_type != 0 | |
4029 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) | |
4030 || cmdline_star > 0 | |
4031 # endif | |
4032 ) | |
4033 { | |
4034 beep_flush(); | |
4035 return K_IGNORE; | |
4036 } | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4037 set_bufref(&old_curbuf, curbuf); |
7 | 4038 |
4039 /* Save current window sizes. */ | |
4040 win_size_save(&winsizes); | |
4041 | |
4042 /* Don't execute autocommands while creating the window. */ | |
1410 | 4043 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
4044 |
15575
6effd97a0429
patch 8.1.0795: cannot build without popup menu
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
4045 #if defined(FEAT_INS_EXPAND) |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4046 // When using completion in Insert mode with <C-R>=<C-F> one can open the |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4047 // command line window, but we don't want the popup menu then. |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4048 pum_undisplay(); |
15575
6effd97a0429
patch 8.1.0795: cannot build without popup menu
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
4049 #endif |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4050 |
683 | 4051 /* don't use a new tab page */ |
4052 cmdmod.tab = 0; | |
11321
f57dce6b934b
patch 8.0.0546: swap file exists briefly when opening the command window
Christian Brabandt <cb@256bit.org>
parents:
11285
diff
changeset
|
4053 cmdmod.noswapfile = 1; |
683 | 4054 |
7 | 4055 /* Create a window for the command-line buffer. */ |
4056 if (win_split((int)p_cwh, WSP_BOT) == FAIL) | |
4057 { | |
4058 beep_flush(); | |
1410 | 4059 unblock_autocmds(); |
7 | 4060 return K_IGNORE; |
4061 } | |
1831 | 4062 cmdwin_type = get_cmdline_type(); |
7 | 4063 |
4064 /* Create the command-line buffer empty. */ | |
1743 | 4065 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); |
1621 | 4066 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); |
7 | 4067 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); |
4068 curbuf->b_p_ma = TRUE; | |
1865 | 4069 #ifdef FEAT_FOLDING |
4070 curwin->w_p_fen = FALSE; | |
4071 #endif | |
7 | 4072 # ifdef FEAT_RIGHTLEFT |
510 | 4073 curwin->w_p_rl = cmdmsg_rl; |
4074 cmdmsg_rl = FALSE; | |
7 | 4075 # endif |
2583 | 4076 RESET_BINDING(curwin); |
7 | 4077 |
4078 /* Do execute autocommands for setting the filetype (load syntax). */ | |
1410 | 4079 unblock_autocmds(); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4080 /* But don't allow switching to another buffer. */ |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4081 ++curbuf_lock; |
7 | 4082 |
510 | 4083 /* Showing the prompt may have set need_wait_return, reset it. */ |
4084 need_wait_return = FALSE; | |
4085 | |
1831 | 4086 histtype = hist_char2type(cmdwin_type); |
7 | 4087 if (histtype == HIST_CMD || histtype == HIST_DEBUG) |
4088 { | |
4089 if (p_wc == TAB) | |
4090 { | |
4091 add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT); | |
4092 add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL); | |
4093 } | |
4094 set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); | |
4095 } | |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
4096 --curbuf_lock; |
7 | 4097 |
10 | 4098 /* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin |
4099 * sets 'textwidth' to 78). */ | |
4100 curbuf->b_p_tw = 0; | |
4101 | |
7 | 4102 /* Fill the buffer with the history. */ |
4103 init_history(); | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4104 if (get_hislen() > 0) |
7 | 4105 { |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4106 i = *get_hisidx(histtype); |
7 | 4107 if (i >= 0) |
4108 { | |
4109 lnum = 0; | |
4110 do | |
4111 { | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4112 if (++i == get_hislen()) |
7 | 4113 i = 0; |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4114 if (get_histentry(histtype)[i].hisstr != NULL) |
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4115 ml_append(lnum++, get_histentry(histtype)[i].hisstr, |
7 | 4116 (colnr_T)0, FALSE); |
4117 } | |
17652
9efb4dda9720
patch 8.1.1823: command line history code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17588
diff
changeset
|
4118 while (i != *get_hisidx(histtype)); |
7 | 4119 } |
4120 } | |
4121 | |
4122 /* Replace the empty last line with the current command-line and put the | |
4123 * cursor there. */ | |
4124 ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); | |
4125 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4126 curwin->w_cursor.col = ccline.cmdpos; | |
510 | 4127 changed_line_abv_curs(); |
4128 invalidate_botline(); | |
743 | 4129 redraw_later(SOME_VALID); |
7 | 4130 |
4131 /* No Ex mode here! */ | |
4132 exmode_active = 0; | |
4133 | |
4134 State = NORMAL; | |
4135 # ifdef FEAT_MOUSE | |
4136 setmouse(); | |
4137 # endif | |
4138 | |
4139 /* Trigger CmdwinEnter autocommands. */ | |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
4140 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); |
929 | 4141 if (restart_edit != 0) /* autocmd with ":startinsert" */ |
4142 stuffcharReadbuff(K_NOP); | |
7 | 4143 |
4144 i = RedrawingDisabled; | |
4145 RedrawingDisabled = 0; | |
4146 | |
4147 /* | |
4148 * Call the main loop until <CR> or CTRL-C is typed. | |
4149 */ | |
4150 cmdwin_result = 0; | |
168 | 4151 main_loop(TRUE, FALSE); |
7 | 4152 |
4153 RedrawingDisabled = i; | |
4154 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
4155 # ifdef FEAT_FOLDING |
6145 | 4156 save_KeyTyped = KeyTyped; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
4157 # endif |
6145 | 4158 |
7 | 4159 /* Trigger CmdwinLeave autocommands. */ |
12656
0a9dacb8826a
patch 8.0.1206: no autocmd for entering or leaving the command line
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
4160 trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); |
6145 | 4161 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
4162 # ifdef FEAT_FOLDING |
6145 | 4163 /* Restore KeyTyped in case it is modified by autocommands */ |
4164 KeyTyped = save_KeyTyped; | |
7 | 4165 # endif |
4166 | |
4167 cmdwin_type = 0; | |
4168 exmode_active = save_exmode; | |
4169 | |
1612 | 4170 /* Safety check: The old window or buffer was deleted: It's a bug when |
7 | 4171 * this happens! */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4172 if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) |
7 | 4173 { |
4174 cmdwin_result = Ctrl_C; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15239
diff
changeset
|
4175 emsg(_("E199: Active window or buffer deleted")); |
7 | 4176 } |
4177 else | |
4178 { | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13256
diff
changeset
|
4179 # if defined(FEAT_EVAL) |
7 | 4180 /* autocmds may abort script processing */ |
4181 if (aborting() && cmdwin_result != K_IGNORE) | |
4182 cmdwin_result = Ctrl_C; | |
4183 # endif | |
4184 /* Set the new command line from the cmdline buffer. */ | |
4185 vim_free(ccline.cmdbuff); | |
510 | 4186 if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ |
7 | 4187 { |
510 | 4188 char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; |
4189 | |
4190 if (histtype == HIST_CMD) | |
4191 { | |
4192 /* Execute the command directly. */ | |
4193 ccline.cmdbuff = vim_strsave((char_u *)p); | |
4194 cmdwin_result = CAR; | |
4195 } | |
4196 else | |
4197 { | |
4198 /* First need to cancel what we were doing. */ | |
4199 ccline.cmdbuff = NULL; | |
4200 stuffcharReadbuff(':'); | |
4201 stuffReadbuff((char_u *)p); | |
4202 stuffcharReadbuff(CAR); | |
4203 } | |
7 | 4204 } |
4205 else if (cmdwin_result == K_XF2) /* :qa typed */ | |
4206 { | |
4207 ccline.cmdbuff = vim_strsave((char_u *)"qa"); | |
4208 cmdwin_result = CAR; | |
4209 } | |
2839 | 4210 else if (cmdwin_result == Ctrl_C) |
4211 { | |
4212 /* :q or :close, don't execute any command | |
4213 * and don't modify the cmd window. */ | |
4214 ccline.cmdbuff = NULL; | |
4215 } | |
7 | 4216 else |
4217 ccline.cmdbuff = vim_strsave(ml_get_curline()); | |
4218 if (ccline.cmdbuff == NULL) | |
11647
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4219 { |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4220 ccline.cmdbuff = vim_strsave((char_u *)""); |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4221 ccline.cmdlen = 0; |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4222 ccline.cmdbufflen = 1; |
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4223 ccline.cmdpos = 0; |
7 | 4224 cmdwin_result = Ctrl_C; |
11647
aa426eb9589d
patch 8.0.0706: crash when cancelling the cmdline window in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11619
diff
changeset
|
4225 } |
7 | 4226 else |
4227 { | |
4228 ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
4229 ccline.cmdbufflen = ccline.cmdlen + 1; | |
4230 ccline.cmdpos = curwin->w_cursor.col; | |
4231 if (ccline.cmdpos > ccline.cmdlen) | |
4232 ccline.cmdpos = ccline.cmdlen; | |
4233 if (cmdwin_result == K_IGNORE) | |
4234 { | |
4235 set_cmdspos_cursor(); | |
4236 redrawcmd(); | |
4237 } | |
4238 } | |
4239 | |
4240 /* Don't execute autocommands while deleting the window. */ | |
1410 | 4241 block_autocmds(); |
6876 | 4242 # ifdef FEAT_CONCEAL |
4243 /* Avoid command-line window first character being concealed. */ | |
4244 curwin->w_p_cole = 0; | |
4245 # endif | |
7 | 4246 wp = curwin; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4247 set_bufref(&bufref, curbuf); |
7 | 4248 win_goto(old_curwin); |
4249 win_close(wp, TRUE); | |
2099
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
4250 |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
4251 /* win_close() may have already wiped the buffer when 'bh' is |
c1f67ce5740a
updated for version 7.2.382
Bram Moolenaar <bram@zimbu.org>
parents:
2097
diff
changeset
|
4252 * set to 'wipe' */ |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4253 if (bufref_valid(&bufref)) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
4254 close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); |
7 | 4255 |
4256 /* Restore window sizes. */ | |
4257 win_size_restore(&winsizes); | |
4258 | |
1410 | 4259 unblock_autocmds(); |
7 | 4260 } |
4261 | |
4262 ga_clear(&winsizes); | |
4263 restart_edit = save_restart_edit; | |
510 | 4264 # ifdef FEAT_RIGHTLEFT |
4265 cmdmsg_rl = save_cmdmsg_rl; | |
4266 # endif | |
7 | 4267 |
4268 State = save_State; | |
4269 # ifdef FEAT_MOUSE | |
4270 setmouse(); | |
4271 # endif | |
4272 | |
4273 return cmdwin_result; | |
4274 } | |
4275 #endif /* FEAT_CMDWIN */ | |
4276 | |
4277 /* | |
4278 * Used for commands that either take a simple command string argument, or: | |
4279 * cmd << endmarker | |
4280 * {script} | |
4281 * endmarker | |
4282 * Returns a pointer to allocated memory with {script} or NULL. | |
4283 */ | |
4284 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
4285 script_get(exarg_T *eap, char_u *cmd) |
7 | 4286 { |
4287 char_u *theline; | |
4288 char *end_pattern = NULL; | |
4289 char dot[] = "."; | |
4290 garray_T ga; | |
4291 | |
4292 if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) | |
4293 return NULL; | |
4294 | |
4295 ga_init2(&ga, 1, 0x400); | |
4296 | |
4297 if (cmd[2] != NUL) | |
4298 end_pattern = (char *)skipwhite(cmd + 2); | |
4299 else | |
4300 end_pattern = dot; | |
4301 | |
4302 for (;;) | |
4303 { | |
4304 theline = eap->getline( | |
4305 #ifdef FEAT_EVAL | |
75 | 4306 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 4307 #endif |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17155
diff
changeset
|
4308 NUL, eap->cookie, 0, TRUE); |
7 | 4309 |
4310 if (theline == NULL || STRCMP(end_pattern, theline) == 0) | |
1694 | 4311 { |
4312 vim_free(theline); | |
7 | 4313 break; |
1694 | 4314 } |
7 | 4315 |
4316 ga_concat(&ga, theline); | |
4317 ga_append(&ga, '\n'); | |
4318 vim_free(theline); | |
4319 } | |
21 | 4320 ga_append(&ga, NUL); |
7 | 4321 |
4322 return (char_u *)ga.ga_data; | |
4323 } |