annotate src/popupmnu.c @ 928:03c4ceec6bec v7.0.054

updated for version 7.0-054
author vimboss
date Wed, 16 Aug 2006 13:55:16 +0000
parents 8e5830943bff
children 306fc545fe2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
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
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
33 static int pum_set_selected __ARGS((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
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
45 pum_display(array, size, selected)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
46 pumitem_T *array;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
47 int size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
48 int selected; /* index of initially selected item, none if
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 top_clear;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
58 int row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
59 int height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
60 int col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
61 int above_row = cmdline_row;
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
62 int redo_count = 0;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
63
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
64 redo:
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
65 def_width = PUM_DEF_WIDTH;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
66 max_width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
67 kind_width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
68 extra_width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
69
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
70 /* Pretend the pum is already there to avoid that must_redraw is set when
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
71 * 'cuc' is on. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
72 pum_array = (pumitem_T *)1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
73 validate_cursor_col();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
74 pum_array = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
75
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
76 row = curwin->w_cline_row + W_WINROW(curwin);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
77 height = curwin->w_cline_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
78 col = curwin->w_wcol + W_WINCOL(curwin) - curwin->w_leftcol;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
79
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
80 if (firstwin->w_p_pvw)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
81 top_clear = firstwin->w_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
82 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
83 top_clear = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
84
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
85 /* When the preview window is at the bottom stop just above it. Also
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
86 * avoid drawing over the status line so that it's clear there is a window
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
87 * boundary. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
88 if (lastwin->w_p_pvw)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
89 above_row -= lastwin->w_height + lastwin->w_status_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
90
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
91 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
92 * Figure out the size and position of the pum.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
93 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
94 if (size < PUM_DEF_HEIGHT)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
95 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
96 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
97 pum_height = PUM_DEF_HEIGHT;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
98 if (p_ph > 0 && pum_height > p_ph)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
99 pum_height = p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
100
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
101 /* Put the pum below "row" if possible. If there are few lines decide on
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
102 * where there is more room. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
103 if (row >= above_row - pum_height
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
104 && row > (above_row - top_clear - height) / 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
105 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
106 /* pum above "row" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
107 if (row >= size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
108 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
109 pum_row = row - size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
110 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
111 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
112 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
113 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
114 pum_row = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
115 pum_height = row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
116 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
117 if (p_ph > 0 && pum_height > p_ph)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
118 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
119 pum_row += pum_height - p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
120 pum_height = p_ph;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
121 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
122 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
123 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
124 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
125 /* pum below "row" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
126 pum_row = row + height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
127 if (size > above_row - pum_row)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
128 pum_height = above_row - pum_row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
129 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
130 pum_height = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
131 if (p_ph > 0 && 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 /* don't display when we only have room for one line */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
136 if (pum_height < 1 || (pum_height == 1 && size > 1))
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
137 return;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
138
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
139 /* If there is a preview window at the top avoid drawing over it. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
140 if (firstwin->w_p_pvw
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
141 && pum_row < firstwin->w_height
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
142 && pum_height > firstwin->w_height + 4)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
143 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
144 pum_row += firstwin->w_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
145 pum_height -= firstwin->w_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
146 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
147
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
148 /* Compute the width of the widest match and the widest extra. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
149 for (i = 0; i < size; ++i)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
150 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
151 w = vim_strsize(array[i].pum_text);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
152 if (max_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
153 max_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
154 if (array[i].pum_kind != NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
155 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
156 w = vim_strsize(array[i].pum_kind) + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
157 if (kind_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
158 kind_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
159 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
160 if (array[i].pum_extra != NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
161 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
162 w = vim_strsize(array[i].pum_extra) + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
163 if (extra_width < w)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
164 extra_width = w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
165 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
166 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
167 pum_base_width = max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
168 pum_kind_width = kind_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
169
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
170 /* if there are more items than room we need a scrollbar */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
171 if (pum_height < size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
172 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
173 pum_scrollbar = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
174 ++max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
175 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
176 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
177 pum_scrollbar = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
178
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
179 if (def_width < max_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
180 def_width = max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
181
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
182 if (col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
183 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
184 /* align pum column with "col" */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
185 pum_col = col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
186 pum_width = Columns - pum_col - pum_scrollbar;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
187 if (pum_width > max_width + kind_width + extra_width + 1
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
188 && pum_width > PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
189 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
190 pum_width = max_width + kind_width + extra_width + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
191 if (pum_width < PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
192 pum_width = PUM_DEF_WIDTH;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
193 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
194 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
195 else if (Columns < def_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
196 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
197 /* not enough room, will use what we have */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
198 pum_col = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
199 pum_width = Columns - 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
200 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
201 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
202 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
203 if (max_width > PUM_DEF_WIDTH)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
204 max_width = PUM_DEF_WIDTH; /* truncate */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
205 pum_col = Columns - max_width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
206 pum_width = max_width - pum_scrollbar;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
207 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
208
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
209 pum_array = array;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
210 pum_size = size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
211
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
212 /* 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
213 * the positioning. Limit this to two times, when there is not much
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
214 * room the window size will keep changing. */
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
215 if (pum_set_selected(selected, redo_count) && ++redo_count <= 2)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
216 goto redo;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
217 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
218
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
219 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
220 * Redraw the popup menu, using "pum_first" and "pum_selected".
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
221 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
222 void
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
223 pum_redraw()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
224 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
225 int row = pum_row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
226 int col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
227 int attr_norm = highlight_attr[HLF_PNI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
228 int attr_select = highlight_attr[HLF_PSI];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
229 int attr_scroll = highlight_attr[HLF_PSB];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
230 int attr_thumb = highlight_attr[HLF_PST];
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
231 int attr;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
232 int i;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
233 int idx;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
234 char_u *s;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
235 char_u *p = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
236 int totwidth, width, w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
237 int thumb_pos = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
238 int thumb_heigth = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
239 int round;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
240 int n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
241
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
242 if (pum_scrollbar)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
243 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
244 thumb_heigth = pum_height * pum_height / pum_size;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
245 if (thumb_heigth == 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
246 thumb_heigth = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
247 thumb_pos = (pum_first * (pum_height - thumb_heigth)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
248 + (pum_size - pum_height) / 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
249 / (pum_size - pum_height);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
250 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
251
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
252 for (i = 0; i < pum_height; ++i)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
253 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
254 idx = i + pum_first;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
255 attr = (idx == pum_selected) ? attr_select : attr_norm;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
256
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
257 /* prepend a space if there is room */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
258 if (pum_col > 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
259 screen_putchar(' ', row, pum_col - 1, attr);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
260
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
261 /* Display each entry, use two spaces for a Tab.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
262 * Do this 3 times: For the main text, kind and extra info */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
263 col = pum_col;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
264 totwidth = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
265 for (round = 1; round <= 3; ++round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
266 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
267 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
268 s = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
269 switch (round)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
270 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
271 case 1: p = pum_array[idx].pum_text; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
272 case 2: p = pum_array[idx].pum_kind; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
273 case 3: p = pum_array[idx].pum_extra; break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
274 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
275 if (p != NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
276 for ( ; ; mb_ptr_adv(p))
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
277 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
278 if (s == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
279 s = p;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
280 w = ptr2cells(p);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
281 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
282 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
283 /* Display the text that fits or comes before a Tab. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
284 screen_puts_len(s, (int)(p - s), row, col, attr);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
285 col += width;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
286
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
287 if (*p != TAB)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
288 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
289
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
290 /* Display two spaces for a Tab. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
291 screen_puts_len((char_u *)" ", 2, row, col, attr);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
292 col += 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
293 totwidth += 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
294 s = NULL; /* start text at next char */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
295 width = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
296 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
297 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
298 width += w;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
299 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
300
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
301 if (round > 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
302 n = pum_kind_width + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
303 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
304 n = 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
305
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
306 /* Stop when there is nothing more to display. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
307 if (round == 3
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
308 || (round == 2 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
309 || (round == 1 && pum_array[idx].pum_kind == NULL
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
310 && pum_array[idx].pum_extra == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
311 || pum_base_width + n >= pum_width)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
312 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
313 screen_fill(row, row + 1, col, pum_col + pum_base_width + n,
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
314 ' ', ' ', attr);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
315 col = pum_col + pum_base_width + n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
316 totwidth = pum_base_width + n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
317 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
318
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
319 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
320 if (pum_scrollbar > 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
321 screen_putchar(' ', row, pum_col + pum_width,
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
322 i >= thumb_pos && i < thumb_pos + thumb_heigth
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
323 ? attr_thumb : attr_scroll);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
324
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
325 ++row;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
326 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
327 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
328
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
329 #if 0 /* not used yet */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
330 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
331 * Return the index of the currently selected item.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
332 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
333 int
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
334 pum_get_selected()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
335 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
336 return pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
337 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
338 #endif
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
339
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
340 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
341 * Set the index of the currently selected item. The menu will scroll when
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
342 * necessary. When "n" is out of range don't scroll.
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
343 * This may be repeated when the preview window is used:
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
344 * "repeat" == 0: open preview window normally
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
345 * "repeat" == 1: open preview window but don't set the size
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
346 * "repeat" == 2: don't open preview window
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
347 * Returns TRUE when the window was resized and the location of the popup menu
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
348 * must be recomputed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
349 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
350 static int
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
351 pum_set_selected(n, repeat)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
352 int n;
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
353 int repeat;
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
354 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
355 int resized = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
356 int context = pum_height / 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
357
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
358 pum_selected = n;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
359
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
360 if (pum_selected >= 0 && pum_selected < pum_size)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
361 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
362 if (pum_first > pum_selected - 4)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
363 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
364 /* scroll down; when we did a jump it's probably a PageUp then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
365 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
366 if (pum_first > pum_selected - 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
367 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
368 pum_first -= pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
369 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
370 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
371 else if (pum_first > pum_selected)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
372 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
373 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
374 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
375 pum_first = pum_selected;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
376 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
377 else if (pum_first < pum_selected - pum_height + 5)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
378 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
379 /* scroll up; when we did a jump it's probably a PageDown then
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
380 * scroll a whole page */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
381 if (pum_first < pum_selected - pum_height + 1 + 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
382 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
383 pum_first += pum_height - 2;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
384 if (pum_first < pum_selected - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
385 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
386 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
387 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
388 pum_first = pum_selected - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
389 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
390
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
391 /* Give a few lines of context when possible. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
392 if (context > 3)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
393 context = 3;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
394 if (pum_height > 2)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
395 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
396 if (pum_first > pum_selected - context)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
397 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
398 /* scroll down */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
399 pum_first = pum_selected - context;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
400 if (pum_first < 0)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
401 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
402 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
403 else if (pum_first < pum_selected + context - pum_height + 1)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
404 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
405 /* scroll up */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
406 pum_first = pum_selected + context - pum_height + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
407 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
408 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
409
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
410 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
411 /*
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
412 * Show extra info in the preview window if there is something and
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
413 * 'completeopt' contains "preview".
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
414 * Skip this when tried twice already.
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
415 * Skip this also when there is not much room.
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
416 * NOTE: Be very careful not to sync undo!
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
417 */
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
418 if (pum_array[pum_selected].pum_info != NULL
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
419 && Rows > 10
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
420 && repeat <= 1
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
421 && vim_strchr(p_cot, 'p') != NULL)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
422 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
423 win_T *curwin_save = curwin;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
424 int res = OK;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
425
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
426 /* Open a preview window. 3 lines by default. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
427 g_do_tagpreview = 3;
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
428 resized = prepare_tagpreview(FALSE);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
429 g_do_tagpreview = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
430
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
431 if (curwin->w_p_pvw)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
432 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
433 if (curbuf->b_fname == NULL
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
434 && curbuf->b_p_bt[0] == 'n' && curbuf->b_p_bt[2] == 'f'
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
435 && curbuf->b_p_bh[0] == 'w')
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
436 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
437 /* Already a "wipeout" buffer, make it empty. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
438 while (!bufempty())
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
439 ml_delete((linenr_T)1, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
440 }
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
441 else
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
442 {
825
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
443 /* Don't want to sync undo in the current buffer. */
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
444 ++no_u_sync;
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
445 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
446 --no_u_sync;
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
447 if (res == OK)
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
448 {
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
449 /* Edit a new, empty buffer. Set options for a "wipeout"
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
450 * buffer. */
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
451 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
452 set_option_value((char_u *)"bt", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
453 (char_u *)"nofile", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
454 set_option_value((char_u *)"bh", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
455 (char_u *)"wipe", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
456 set_option_value((char_u *)"diff", 0L,
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
457 (char_u *)"", OPT_LOCAL);
6675076019ae updated for version 7.0d
vimboss
parents: 816
diff changeset
458 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
459 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
460 if (res == OK)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
461 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
462 char_u *p, *e;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
463 linenr_T lnum = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
464
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
465 for (p = pum_array[pum_selected].pum_info; *p != NUL; )
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
466 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
467 e = vim_strchr(p, '\n');
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
468 if (e == NULL)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
469 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
470 ml_append(lnum++, p, 0, FALSE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
471 break;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
472 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
473 else
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
474 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
475 *e = NUL;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 825
diff changeset
476 ml_append(lnum++, p, (int)(e - p + 1), FALSE);
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
477 *e = '\n';
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
478 p = e + 1;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
479 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
480 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
481
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
482 /* Increase the height of the preview window to show the
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
483 * text, but no more than 'previewheight' lines. */
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
484 if (repeat == 0)
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
485 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
486 if (lnum > p_pvh)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
487 lnum = p_pvh;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
488 if (curwin->w_height < lnum)
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
489 {
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
490 win_setheight((int)lnum);
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
491 resized = TRUE;
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
492 }
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
493 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
494
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
495 curbuf->b_changed = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
496 curbuf->b_p_ma = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
497 curwin->w_cursor.lnum = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
498 curwin->w_cursor.col = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
499
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
500 if (curwin != curwin_save && win_valid(curwin_save))
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
501 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
502 /* Return cursor to where we were */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
503 validate_cursor();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
504 redraw_later(SOME_VALID);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
505
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
506 /* When the preview window was resized we need to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
507 * update the view on the buffer. Only go back to
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
508 * the window when needed, otherwise it will always be
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
509 * redraw. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
510 if (resized)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
511 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
512 win_enter(curwin_save, TRUE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
513 update_topline();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
514 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
515
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
516 /* Update the screen before drawing the popup menu.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
517 * Enable updating the status lines. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
518 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
519 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
520 pum_do_redraw = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
521
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 800
diff changeset
522 if (!resized && win_valid(curwin_save))
800
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
523 win_enter(curwin_save, TRUE);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
524
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
525 /* May need to update the screen again when there are
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
526 * autocommands involved. */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
527 pum_do_redraw = TRUE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
528 update_screen(0);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
529 pum_do_redraw = FALSE;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
530 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
531 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
532 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
533 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
534 #endif
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
535 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
536
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
537 /* Never display more than we have */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
538 if (pum_first > pum_size - pum_height)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
539 pum_first = pum_size - pum_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
540
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
541 if (!resized)
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
542 pum_redraw();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
543
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
544 return resized;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
545 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
546
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
547 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
548 * Undisplay the popup menu (later).
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
549 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
550 void
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
551 pum_undisplay()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
552 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
553 pum_array = NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
554 redraw_all_later(SOME_VALID);
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
555 status_redraw_all();
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
556 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
557
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
558 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
559 * Clear the popup menu. Currently only resets the offset to the first
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
560 * displayed item.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
561 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
562 void
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
563 pum_clear()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
564 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
565 pum_first = 0;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
566 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
567
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
568 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
569 * Return TRUE if the popup menu is displayed.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
570 * Overruled when "pum_do_redraw" is set, used to redraw the status lines.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
571 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
572 int
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
573 pum_visible()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
574 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
575 return !pum_do_redraw && pum_array != NULL;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
576 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
577
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
578 /*
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
579 * Return the height of the popup menu, the number of entries visible.
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
580 * Only valid when pum_visible() returns TRUE!
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
581 */
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
582 int
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
583 pum_get_height()
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
584 {
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
585 return pum_height;
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
586 }
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
587
d8f905020502 updated for version 7.0b
vimboss
parents:
diff changeset
588 #endif