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