annotate src/popupmnu.c @ 11666:5cd9ba96561d v8.0.0716

patch 8.0.0716: not easy to start Vim cleanly commit https://github.com/vim/vim/commit/c4da113ef98dcfd6f2a088b1693c0317dcb5bf42 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 15 19:39:43 2017 +0200 patch 8.0.0716: not easy to start Vim cleanly Problem: Not easy to start Vim cleanly without changing the viminfo file. Not possible to know whether the -i command line flag was used. Solution: Add the --clean command line argument. Add the 'viminfofile' option. Add "-u DEFAULTS".
author Christian Brabandt <cb@256bit.org>
date Sat, 15 Jul 2017 19:45:03 +0200
parents 506f5d8b7d8b
children 68d7bc045dbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 8220
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
2 *
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
4 *
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
8 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
9
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
10 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
11 * popupmnu.c: Popup menu (PUM)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
12 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
13 #include "vim.h"
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
14
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
15 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
16
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
18 static int pum_size; /* nr of items in "pum_array" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
19 static int pum_selected; /* index of selected item or -1 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
20 static int pum_first = 0; /* index of top item */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
21
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
22 static int pum_height; /* nr of displayed pum items */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
23 static int pum_width; /* width of displayed pum items */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
24 static int pum_base_width; /* width of pum items base */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
25 static int pum_kind_width; /* width of pum items kind column */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
26 static int pum_scrollbar; /* TRUE when scrollbar present */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
27
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
28 static int pum_row; /* top row of pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
29 static int pum_col; /* left column of pum */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
30
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
31 static int pum_do_redraw = FALSE; /* do redraw anyway */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
32
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7181
diff changeset
33 static int pum_set_selected(int n, int repeat);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
34
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
35 #define PUM_DEF_HEIGHT 10
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
36 #define PUM_DEF_WIDTH 15
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
37
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
38 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
39 * Show the popup menu with items "array[size]".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
40 * "array" must remain valid until pum_undisplay() is called!
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
41 * When possible the leftmost character is aligned with screen column "col".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
42 * The menu appears above the screen line "row" or at "row" + "height" - 1.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
43 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
44 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
45 pum_display(
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
46 pumitem_T *array,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
47 int size,
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
48 int selected) /* index of initially selected item, none if
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
49 out of range */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
50 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
51 int w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
52 int def_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
53 int max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
54 int kind_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
55 int extra_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
56 int i;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
57 int row;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
58 int context_lines;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
59 int col;
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
60 int above_row;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
61 int below_row;
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
62 int redo_count = 0;
10332
4d98f501d1c5 commit https://github.com/vim/vim/commit/aab3383e70456f054fe9d0963fe3eb45994aa5e7
Christian Brabandt <cb@256bit.org>
parents: 10326
diff changeset
63 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
64 win_T *pvwin;
10332
4d98f501d1c5 commit https://github.com/vim/vim/commit/aab3383e70456f054fe9d0963fe3eb45994aa5e7
Christian Brabandt <cb@256bit.org>
parents: 10326
diff changeset
65 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
66
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
67 redo:
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
68 def_width = PUM_DEF_WIDTH;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
69 max_width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
70 kind_width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
71 extra_width = 0;
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
72 above_row = 0;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
73 below_row = cmdline_row;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
74
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
75 /* Pretend the pum is already there to avoid that must_redraw is set when
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
76 * 'cuc' is on. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
77 pum_array = (pumitem_T *)1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
78 validate_cursor_col();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
79 pum_array = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
80
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
81 row = curwin->w_wrow + W_WINROW(curwin);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
82
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
83 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
84 FOR_ALL_WINDOWS(pvwin)
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
85 if (pvwin->w_p_pvw)
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
86 break;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
87 if (pvwin != NULL)
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
88 {
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
89 if (W_WINROW(pvwin) < W_WINROW(curwin))
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
90 above_row = W_WINROW(pvwin) + pvwin->w_height;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
91 else if (W_WINROW(pvwin) > W_WINROW(curwin) + curwin->w_height)
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
92 below_row = W_WINROW(pvwin);
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
93 }
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
94 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
95
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
96 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
97 * Figure out the size and position of the pum.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
98 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
99 if (size < PUM_DEF_HEIGHT)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
100 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
101 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
102 pum_height = PUM_DEF_HEIGHT;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
103 if (p_ph > 0 && pum_height > p_ph)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
104 pum_height = p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
105
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
106 /* Put the pum below "row" if possible. If there are few lines decide on
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
107 * where there is more room. */
10410
783a75eca83a commit https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806
Christian Brabandt <cb@256bit.org>
parents: 10332
diff changeset
108 if (row + 2 >= below_row - pum_height
783a75eca83a commit https://github.com/vim/vim/commit/73095288da839f7c738a49baa109773e76106806
Christian Brabandt <cb@256bit.org>
parents: 10332
diff changeset
109 && row - above_row > (below_row - above_row) / 2)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
110 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
111 /* pum above "row" */
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
112
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
113 /* Leave two lines of context if possible */
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
114 if (curwin->w_wrow - curwin->w_cline_row >= 2)
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
115 context_lines = 2;
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
116 else
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
117 context_lines = curwin->w_wrow - curwin->w_cline_row;
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
118
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
119 if (row >= size + context_lines)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
120 {
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
121 pum_row = row - size - context_lines;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
122 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
123 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
124 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
125 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
126 pum_row = 0;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
127 pum_height = row - context_lines;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
128 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
129 if (p_ph > 0 && pum_height > p_ph)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
130 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
131 pum_row += pum_height - p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
132 pum_height = p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
133 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
134 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
135 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
136 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
137 /* pum below "row" */
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
138
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
139 /* Leave two lines of context if possible */
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
140 if (curwin->w_cline_row + curwin->w_cline_height - curwin->w_wrow >= 3)
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
141 context_lines = 3;
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
142 else
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
143 context_lines = curwin->w_cline_row
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
144 + curwin->w_cline_height - curwin->w_wrow;
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
145
149d8b46404c updated for version 7.2a
vimboss
parents: 1570
diff changeset
146 pum_row = row + context_lines;
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
147 if (size > below_row - pum_row)
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
148 pum_height = below_row - pum_row;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
149 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
150 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
151 if (p_ph > 0 && pum_height > p_ph)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
152 pum_height = p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
153 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
154
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
155 /* don't display when we only have room for one line */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
156 if (pum_height < 1 || (pum_height == 1 && size > 1))
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
157 return;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
158
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
159 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
160 /* If there is a preview window at the above avoid drawing over it. */
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
161 if (pvwin != NULL && pum_row < above_row && pum_height > above_row)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
162 {
10326
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
163 pum_row += above_row;
7d10572eaba4 commit https://github.com/vim/vim/commit/91e44a3305ef6bf2d43496c351dcff0a45c6bfb8
Christian Brabandt <cb@256bit.org>
parents: 10302
diff changeset
164 pum_height -= above_row;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
165 }
8220
ad9edad64d22 commit https://github.com/vim/vim/commit/0106e3d0bf8a38351af45331cbf3b9172a6bb90b
Christian Brabandt <cb@256bit.org>
parents: 7833
diff changeset
166 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
167
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
168 /* Compute the width of the widest match and the widest extra. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
169 for (i = 0; i < size; ++i)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
170 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
171 w = vim_strsize(array[i].pum_text);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
172 if (max_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
173 max_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
174 if (array[i].pum_kind != NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
175 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
176 w = vim_strsize(array[i].pum_kind) + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
177 if (kind_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
178 kind_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
179 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
180 if (array[i].pum_extra != NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
181 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
182 w = vim_strsize(array[i].pum_extra) + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
183 if (extra_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
184 extra_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
185 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
186 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
187 pum_base_width = max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
188 pum_kind_width = kind_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
189
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
190 /* Calculate column */
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
191 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
192 if (curwin->w_p_rl)
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1622
diff changeset
193 col = W_WINCOL(curwin) + W_WIDTH(curwin) - curwin->w_wcol - 1;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
194 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
195 #endif
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents: 1622
diff changeset
196 col = W_WINCOL(curwin) + curwin->w_wcol;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
197
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
198 /* if there are more items than room we need a scrollbar */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
199 if (pum_height < size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
200 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
201 pum_scrollbar = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
202 ++max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
203 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
204 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
205 pum_scrollbar = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
206
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
207 if (def_width < max_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
208 def_width = max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
209
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
210 if (((col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
211 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
212 && !curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
213 || (curwin->w_p_rl && (col > PUM_DEF_WIDTH || col > max_width)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
214 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
215 ))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
216 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
217 /* align pum column with "col" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
218 pum_col = col;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
219
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
220 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
221 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
222 pum_width = pum_col - pum_scrollbar + 1;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
223 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
224 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
225 pum_width = Columns - pum_col - pum_scrollbar;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
226
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
227 if (pum_width > max_width + kind_width + extra_width + 1
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
228 && pum_width > PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
229 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
230 pum_width = max_width + kind_width + extra_width + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
231 if (pum_width < PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
232 pum_width = PUM_DEF_WIDTH;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
233 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
234 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
235 else if (Columns < def_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
236 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
237 /* not enough room, will use what we have */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
238 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
239 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
240 pum_col = Columns - 1;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
241 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
242 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
243 pum_col = 0;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
244 pum_width = Columns - 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
245 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
246 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
247 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
248 if (max_width > PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
249 max_width = PUM_DEF_WIDTH; /* truncate */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
250 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
251 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
252 pum_col = max_width - 1;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
253 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
254 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
255 pum_col = Columns - max_width;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
256 pum_width = max_width - pum_scrollbar;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
257 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
258
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
259 pum_array = array;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
260 pum_size = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
261
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
262 /* Set selected item and redraw. If the window size changed need to redo
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
263 * the positioning. Limit this to two times, when there is not much
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
264 * room the window size will keep changing. */
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
265 if (pum_set_selected(selected, redo_count) && ++redo_count <= 2)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
266 goto redo;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
267 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
268
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
269 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
270 * Redraw the popup menu, using "pum_first" and "pum_selected".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
271 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
272 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
273 pum_redraw(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
274 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
275 int row = pum_row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
276 int col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
277 int attr_norm = highlight_attr[HLF_PNI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
278 int attr_select = highlight_attr[HLF_PSI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
279 int attr_scroll = highlight_attr[HLF_PSB];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
280 int attr_thumb = highlight_attr[HLF_PST];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
281 int attr;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
282 int i;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
283 int idx;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
284 char_u *s;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
285 char_u *p = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
286 int totwidth, width, w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
287 int thumb_pos = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
288 int thumb_heigth = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
289 int round;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
290 int n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
291
5444
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
292 /* Never display more than we have */
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
293 if (pum_first > pum_size - pum_height)
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
294 pum_first = pum_size - pum_height;
d563839a9be0 updated for version 7.4.072
Bram Moolenaar <bram@vim.org>
parents: 2622
diff changeset
295
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
296 if (pum_scrollbar)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
297 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
298 thumb_heigth = pum_height * pum_height / pum_size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
299 if (thumb_heigth == 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
300 thumb_heigth = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
301 thumb_pos = (pum_first * (pum_height - thumb_heigth)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
302 + (pum_size - pum_height) / 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
303 / (pum_size - pum_height);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
304 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
305
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
306 for (i = 0; i < pum_height; ++i)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
307 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
308 idx = i + pum_first;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
309 attr = (idx == pum_selected) ? attr_select : attr_norm;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
310
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
311 /* prepend a space if there is room */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
312 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
313 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
314 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
315 if (pum_col < W_WINCOL(curwin) + W_WIDTH(curwin) - 1)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
316 screen_putchar(' ', row, pum_col + 1, attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
317 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
318 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
319 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
320 if (pum_col > 0)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
321 screen_putchar(' ', row, pum_col - 1, attr);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
322
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
323 /* Display each entry, use two spaces for a Tab.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
324 * Do this 3 times: For the main text, kind and extra info */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
325 col = pum_col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
326 totwidth = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
327 for (round = 1; round <= 3; ++round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
328 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
329 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
330 s = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
331 switch (round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
332 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
333 case 1: p = pum_array[idx].pum_text; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
334 case 2: p = pum_array[idx].pum_kind; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
335 case 3: p = pum_array[idx].pum_extra; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
336 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
337 if (p != NULL)
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
338 for ( ; ; MB_PTR_ADV(p))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
339 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
340 if (s == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
341 s = p;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
342 w = ptr2cells(p);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
343 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
344 {
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
345 /* Display the text that fits or comes before a Tab.
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
346 * First convert it to printable characters. */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
347 char_u *st;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
348 int saved = *p;
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
349
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
350 *p = NUL;
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
351 st = transstr(s);
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
352 *p = saved;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
353 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
354 if (curwin->w_p_rl)
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
355 {
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
356 if (st != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
357 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
358 char_u *rt = reverse_text(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
359
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
360 if (rt != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
361 {
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
362 char_u *rt_start = rt;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
363 int size;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
364
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
365 size = vim_strsize(rt);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
366 if (size > pum_width)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
367 {
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
368 do
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
369 {
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
370 size -= has_mbyte
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
371 ? (*mb_ptr2cells)(rt) : 1;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
372 MB_PTR_ADV(rt);
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
373 } while (size > pum_width);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
374
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
375 if (size < pum_width)
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
376 {
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
377 /* Most left character requires
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
378 * 2-cells but only 1 cell is
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
379 * available on screen. Put a
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
380 * '<' on the left of the pum
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
381 * item */
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
382 *(--rt) = '<';
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
383 size++;
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
384 }
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
385 }
2056
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
386 screen_puts_len(rt, (int)STRLEN(rt),
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
387 row, col - size + 1, attr);
e9e3355861ba updated for version 7.2.342
Bram Moolenaar <bram@zimbu.org>
parents: 1743
diff changeset
388 vim_free(rt_start);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
389 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
390 vim_free(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
391 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
392 col -= width;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
393 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
394 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
395 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
396 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
397 if (st != NULL)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
398 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
399 screen_puts_len(st, (int)STRLEN(st), row, col,
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
400 attr);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
401 vim_free(st);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
402 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
403 col += width;
1097
537cb92935b6 updated for version 7.0-223
vimboss
parents: 940
diff changeset
404 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
405
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
406 if (*p != TAB)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
407 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
408
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
409 /* Display two spaces for a Tab. */
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
410 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
411 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
412 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
413 screen_puts_len((char_u *)" ", 2, row, col - 1,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
414 attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
415 col -= 2;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
416 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
417 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
418 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
419 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
420 screen_puts_len((char_u *)" ", 2, row, col, attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
421 col += 2;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
422 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
423 totwidth += 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
424 s = NULL; /* start text at next char */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
425 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
426 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
427 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
428 width += w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
429 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
430
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
431 if (round > 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
432 n = pum_kind_width + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
433 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
434 n = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
435
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
436 /* Stop when there is nothing more to display. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
437 if (round == 3
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
438 || (round == 2 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
439 || (round == 1 && pum_array[idx].pum_kind == NULL
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
440 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
441 || pum_base_width + n >= pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
442 break;
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
443 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
444 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
445 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
446 screen_fill(row, row + 1, pum_col - pum_base_width - n + 1,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
447 col + 1, ' ', ' ', attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
448 col = pum_col - pum_base_width - n + 1;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
449 }
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
450 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
451 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
452 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
453 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
454 ' ', ' ', attr);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
455 col = pum_col + pum_base_width + n;
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
456 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
457 totwidth = pum_base_width + n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
458 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
459
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
460 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
461 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
462 screen_fill(row, row + 1, pum_col - pum_width + 1, col + 1, ' ',
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
463 ' ', attr);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
464 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
465 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
466 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ',
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
467 attr);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
468 if (pum_scrollbar > 0)
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
469 {
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
470 #ifdef FEAT_RIGHTLEFT
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
471 if (curwin->w_p_rl)
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
472 screen_putchar(' ', row, pum_col - pum_width,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
473 i >= thumb_pos && i < thumb_pos + thumb_heigth
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
474 ? attr_thumb : attr_scroll);
1344
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
475 else
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
476 #endif
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
477 screen_putchar(' ', row, pum_col + pum_width,
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
478 i >= thumb_pos && i < thumb_pos + thumb_heigth
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
479 ? attr_thumb : attr_scroll);
843bfffb04c7 updated for version 7.1-058
vimboss
parents: 1302
diff changeset
480 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
481
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
482 ++row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
483 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
484 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
485
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
486 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
487 * Set the index of the currently selected item. The menu will scroll when
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
488 * necessary. When "n" is out of range don't scroll.
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
489 * This may be repeated when the preview window is used:
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
490 * "repeat" == 0: open preview window normally
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
491 * "repeat" == 1: open preview window but don't set the size
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
492 * "repeat" == 2: don't open preview window
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
493 * Returns TRUE when the window was resized and the location of the popup menu
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
494 * must be recomputed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
495 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
496 static int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
497 pum_set_selected(int n, int repeat)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
498 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
499 int resized = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
500 int context = pum_height / 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
501
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
502 pum_selected = n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
503
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
504 if (pum_selected >= 0 && pum_selected < pum_size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
505 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
506 if (pum_first > pum_selected - 4)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
507 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
508 /* scroll down; when we did a jump it's probably a PageUp then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
509 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
510 if (pum_first > pum_selected - 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
511 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
512 pum_first -= pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
513 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
514 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
515 else if (pum_first > pum_selected)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
516 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
517 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
518 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
519 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
520 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
521 else if (pum_first < pum_selected - pum_height + 5)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
522 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
523 /* scroll up; when we did a jump it's probably a PageDown then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
524 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
525 if (pum_first < pum_selected - pum_height + 1 + 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
526 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
527 pum_first += pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
528 if (pum_first < pum_selected - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
529 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
530 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
531 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
532 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
533 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
534
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
535 /* Give a few lines of context when possible. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
536 if (context > 3)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
537 context = 3;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
538 if (pum_height > 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
539 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
540 if (pum_first > pum_selected - context)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
541 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
542 /* scroll down */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
543 pum_first = pum_selected - context;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
544 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
545 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
546 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
547 else if (pum_first < pum_selected + context - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
548 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
549 /* scroll up */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
550 pum_first = pum_selected + context - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
551 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
552 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
553
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
554 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
555 /*
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
556 * Show extra info in the preview window if there is something and
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
557 * 'completeopt' contains "preview".
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
558 * Skip this when tried twice already.
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
559 * Skip this also when there is not much room.
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
560 * NOTE: Be very careful not to sync undo!
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
561 */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
562 if (pum_array[pum_selected].pum_info != NULL
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
563 && Rows > 10
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
564 && repeat <= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
565 && vim_strchr(p_cot, 'p') != NULL)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
566 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
567 win_T *curwin_save = curwin;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
568 int res = OK;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
569
2622
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
570 /* Open a preview window. 3 lines by default. Prefer
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
571 * 'previewheight' if set and smaller. */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
572 g_do_tagpreview = 3;
2622
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
573 if (p_pvh > 0 && p_pvh < g_do_tagpreview)
b2cfe84c96cc updated for version 7.3.044
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
574 g_do_tagpreview = p_pvh;
6043
a97e5b9dbc26 updated for version 7.4.361
Bram Moolenaar <bram@vim.org>
parents: 5444
diff changeset
575 ++RedrawingDisabled;
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
576 /* Prevent undo sync here, if an autocommand syncs undo weird
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
577 * things can happen to the undo tree. */
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
578 ++no_u_sync;
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
579 resized = prepare_tagpreview(FALSE);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
580 --no_u_sync;
6043
a97e5b9dbc26 updated for version 7.4.361
Bram Moolenaar <bram@vim.org>
parents: 5444
diff changeset
581 --RedrawingDisabled;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
582 g_do_tagpreview = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
583
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
584 if (curwin->w_p_pvw)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
585 {
10302
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
586 if (!resized
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
587 && curbuf->b_nwindows == 1
210af8588e8a commit https://github.com/vim/vim/commit/50e5376926dc2ec4a26a7a16f8f0f3213c4afdf0
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
588 && curbuf->b_fname == NULL
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
589 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f'
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
590 && curbuf->b_p_bh[0] == 'w')
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
591 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
592 /* Already a "wipeout" buffer, make it empty. */
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10410
diff changeset
593 while (!BUFEMPTY())
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
594 ml_delete((linenr_T)1, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
595 }
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
596 else
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
597 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
598 /* Don't want to sync undo in the current buffer. */
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
599 ++no_u_sync;
1743
734d5bdae499 updated for version 7.2-041
vimboss
parents: 1668
diff changeset
600 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
601 --no_u_sync;
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
602 if (res == OK)
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
603 {
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
604 /* Edit a new, empty buffer. Set options for a "wipeout"
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
605 * buffer. */
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
606 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
607 set_option_value((char_u *)"bt", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
608 (char_u *)"nofile", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
609 set_option_value((char_u *)"bh", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
610 (char_u *)"wipe", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
611 set_option_value((char_u *)"diff", 0L,
1302
7281a86ae640 updated for version 7.1-016
vimboss
parents: 1097
diff changeset
612 NULL, OPT_LOCAL);
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
613 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
614 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
615 if (res == OK)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
616 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
617 char_u *p, *e;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
618 linenr_T lnum = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
619
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
620 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
621 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
622 e = vim_strchr(p, '\n');
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
623 if (e == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
624 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
625 ml_append(lnum++, p, 0, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
626 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
627 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
628 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
629 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
630 *e = NUL;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
631 ml_append(lnum++, p, (int)(e - p + 1), FALSE);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
632 *e = '\n';
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
633 p = e + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
634 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
635 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
636
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
637 /* Increase the height of the preview window to show the
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
638 * text, but no more than 'previewheight' lines. */
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
639 if (repeat == 0)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
640 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
641 if (lnum > p_pvh)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
642 lnum = p_pvh;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
643 if (curwin->w_height < lnum)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
644 {
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
645 win_setheight((int)lnum);
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
646 resized = TRUE;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
647 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
648 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
649
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
650 curbuf->b_changed = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
651 curbuf->b_p_ma = FALSE;
2113
85ad19790706 updated for version 7.2.396
Bram Moolenaar <bram@zimbu.org>
parents: 2056
diff changeset
652 curwin->w_cursor.lnum = 1;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
653 curwin->w_cursor.col = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
654
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
655 if (curwin != curwin_save && win_valid(curwin_save))
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
656 {
6089
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
657 /* When the first completion is done and the preview
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
658 * window is not resized, skip the preview window's
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
659 * status line redrawing. */
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
660 if (ins_compl_active() && !resized)
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
661 curwin->w_redr_status = FALSE;
2f02675bc4b0 updated for version 7.4.383
Bram Moolenaar <bram@vim.org>
parents: 6043
diff changeset
662
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
663 /* Return cursor to where we were */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
664 validate_cursor();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
665 redraw_later(SOME_VALID);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
666
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
667 /* When the preview window was resized we need to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
668 * update the view on the buffer. Only go back to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
669 * the window when needed, otherwise it will always be
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
670 * redraw. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
671 if (resized)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
672 {
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
673 ++no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
674 win_enter(curwin_save, TRUE);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
675 --no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
676 update_topline();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
677 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
678
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
679 /* Update the screen before drawing the popup menu.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
680 * Enable updating the status lines. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
681 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
682 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
683 pum_do_redraw = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
684
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
685 if (!resized && win_valid(curwin_save))
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
686 {
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
687 ++no_u_sync;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
688 win_enter(curwin_save, TRUE);
7181
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
689 --no_u_sync;
ce8b286e89ef commit https://github.com/vim/vim/commit/e7d1376b636e6c758196c3542bd2c1053f9edb75
Christian Brabandt <cb@256bit.org>
parents: 6089
diff changeset
690 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
691
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
692 /* May need to update the screen again when there are
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
693 * autocommands involved. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
694 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
695 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
696 pum_do_redraw = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
697 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
698 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
699 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
700 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
701 #endif
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
702 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
703
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
704 if (!resized)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
705 pum_redraw();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
706
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
707 return resized;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
708 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
709
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
710 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
711 * Undisplay the popup menu (later).
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
712 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
713 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
714 pum_undisplay(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
715 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
716 pum_array = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
717 redraw_all_later(SOME_VALID);
940
306fc545fe2c updated for version 7.0-066
vimboss
parents: 838
diff changeset
718 #ifdef FEAT_WINDOWS
306fc545fe2c updated for version 7.0-066
vimboss
parents: 838
diff changeset
719 redraw_tabline = TRUE;
306fc545fe2c updated for version 7.0-066
vimboss
parents: 838
diff changeset
720 #endif
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
721 status_redraw_all();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
722 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
723
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
724 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
725 * Clear the popup menu. Currently only resets the offset to the first
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
726 * displayed item.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
727 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
728 void
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
729 pum_clear(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
730 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
731 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
732 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
733
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
734 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
735 * Return TRUE if the popup menu is displayed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
736 * Overruled when "pum_do_redraw" is set, used to redraw the status lines.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
737 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
738 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
739 pum_visible(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
740 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
741 return !pum_do_redraw && pum_array != NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
742 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
743
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
744 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
745 * Return the height of the popup menu, the number of entries visible.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
746 * Only valid when pum_visible() returns TRUE!
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
747 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
748 int
7833
c079097365f3 commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
749 pum_get_height(void)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
750 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
751 return pum_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
752 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
753
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
754 #endif