Blame


1 2b2d2872 2021-06-20 op /*
2 2b2d2872 2021-06-20 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 2b2d2872 2021-06-20 op *
4 2b2d2872 2021-06-20 op * Permission to use, copy, modify, and distribute this software for any
5 2b2d2872 2021-06-20 op * purpose with or without fee is hereby granted, provided that the above
6 2b2d2872 2021-06-20 op * copyright notice and this permission notice appear in all copies.
7 2b2d2872 2021-06-20 op *
8 2b2d2872 2021-06-20 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 2b2d2872 2021-06-20 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 2b2d2872 2021-06-20 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 2b2d2872 2021-06-20 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 2b2d2872 2021-06-20 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 2b2d2872 2021-06-20 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 2b2d2872 2021-06-20 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 2b2d2872 2021-06-20 op */
16 2b2d2872 2021-06-20 op
17 61251035 2021-06-26 op #include <limits.h>
18 2b2d2872 2021-06-20 op #include <stdlib.h>
19 61251035 2021-06-26 op #include <string.h>
20 2b2d2872 2021-06-20 op
21 b1e1e41a 2021-07-14 op #include "compl.h"
22 e5a2797f 2021-07-13 op #include "defaults.h"
23 450a89f7 2021-07-12 op #include "minibuffer.h"
24 2b2d2872 2021-06-20 op #include "telescope.h"
25 d1a0f2a3 2021-07-12 op #include "ui.h"
26 5caf7d67 2021-07-12 op #include "utf8.h"
27 2b2d2872 2021-06-20 op
28 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
29 ca231710 2021-07-15 op do { \
30 ca231710 2021-07-15 op if (in_minibuffer) { \
31 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
32 ca231710 2021-07-15 op "is not yet available."); \
33 ca231710 2021-07-15 op return; \
34 ca231710 2021-07-15 op } \
35 ca231710 2021-07-15 op } while(0)
36 ca231710 2021-07-15 op
37 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
38 c4c82003 2021-07-01 op static inline int
39 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
40 2b2d2872 2021-06-20 op {
41 c4c82003 2021-07-01 op struct vline *vl;
42 c4c82003 2021-07-01 op int did;
43 2b2d2872 2021-06-20 op
44 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
45 c4c82003 2021-07-01 op return 0;
46 963c680c 2021-07-05 op vl = buffer->current_line;
47 2b2d2872 2021-06-20 op
48 c4c82003 2021-07-01 op did = 0;
49 c4c82003 2021-07-01 op while (n != 0) {
50 c4c82003 2021-07-01 op if (n > 0) {
51 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
52 c4c82003 2021-07-01 op if (vl == NULL)
53 c4c82003 2021-07-01 op return did;
54 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
55 963c680c 2021-07-05 op continue;
56 c4c82003 2021-07-01 op buffer->current_line = vl;
57 c4c82003 2021-07-01 op n--;
58 c4c82003 2021-07-01 op } else {
59 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
60 c4c82003 2021-07-01 op if (vl == NULL)
61 c4c82003 2021-07-01 op return did;
62 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
63 963c680c 2021-07-05 op continue;
64 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
65 6e6c6afb 2021-07-14 op buffer->line_off--;
66 c4c82003 2021-07-01 op buffer->top_line = vl;
67 6e6c6afb 2021-07-14 op }
68 c4c82003 2021-07-01 op buffer->current_line = vl;
69 c4c82003 2021-07-01 op n++;
70 c4c82003 2021-07-01 op }
71 c4c82003 2021-07-01 op
72 c4c82003 2021-07-01 op did = 1;
73 2b2d2872 2021-06-20 op }
74 2b2d2872 2021-06-20 op
75 c4c82003 2021-07-01 op return did;
76 2b2d2872 2021-06-20 op }
77 2b2d2872 2021-06-20 op
78 2b2d2872 2021-06-20 op void
79 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
80 2b2d2872 2021-06-20 op {
81 c4c82003 2021-07-01 op forward_line(buffer, -1);
82 c4c82003 2021-07-01 op }
83 2b2d2872 2021-06-20 op
84 c4c82003 2021-07-01 op void
85 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
86 c4c82003 2021-07-01 op {
87 c4c82003 2021-07-01 op forward_line(buffer, +1);
88 2b2d2872 2021-06-20 op }
89 2b2d2872 2021-06-20 op
90 2b2d2872 2021-06-20 op void
91 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
92 2b2d2872 2021-06-20 op {
93 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
94 2b2d2872 2021-06-20 op buffer->cpoff--;
95 2b2d2872 2021-06-20 op }
96 2b2d2872 2021-06-20 op
97 2b2d2872 2021-06-20 op void
98 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
99 2b2d2872 2021-06-20 op {
100 2b2d2872 2021-06-20 op size_t len = 0;
101 2b2d2872 2021-06-20 op
102 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
103 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
104 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
105 2b2d2872 2021-06-20 op buffer->cpoff = len;
106 2b2d2872 2021-06-20 op }
107 2b2d2872 2021-06-20 op
108 2b2d2872 2021-06-20 op void
109 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
110 2b2d2872 2021-06-20 op {
111 2b2d2872 2021-06-20 op do {
112 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
113 2b2d2872 2021-06-20 op message("No previous paragraph");
114 2b2d2872 2021-06-20 op return;
115 2b2d2872 2021-06-20 op }
116 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
117 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
118 2b2d2872 2021-06-20 op }
119 2b2d2872 2021-06-20 op
120 2b2d2872 2021-06-20 op void
121 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
122 2b2d2872 2021-06-20 op {
123 2b2d2872 2021-06-20 op do {
124 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
125 2b2d2872 2021-06-20 op message("No next paragraph");
126 2b2d2872 2021-06-20 op return;
127 2b2d2872 2021-06-20 op }
128 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
129 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
130 2b2d2872 2021-06-20 op }
131 2b2d2872 2021-06-20 op
132 2b2d2872 2021-06-20 op void
133 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
134 2b2d2872 2021-06-20 op {
135 2b2d2872 2021-06-20 op buffer->cpoff = 0;
136 2b2d2872 2021-06-20 op }
137 2b2d2872 2021-06-20 op
138 2b2d2872 2021-06-20 op void
139 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
140 2b2d2872 2021-06-20 op {
141 2b2d2872 2021-06-20 op struct vline *vl;
142 2b2d2872 2021-06-20 op
143 2b2d2872 2021-06-20 op vl = buffer->current_line;
144 2b2d2872 2021-06-20 op if (vl->line == NULL)
145 2b2d2872 2021-06-20 op return;
146 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
147 2b2d2872 2021-06-20 op }
148 2b2d2872 2021-06-20 op
149 2b2d2872 2021-06-20 op void
150 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
151 2b2d2872 2021-06-20 op {
152 2b2d2872 2021-06-20 op ui_schedule_redraw();
153 2b2d2872 2021-06-20 op }
154 2b2d2872 2021-06-20 op
155 2b2d2872 2021-06-20 op void
156 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
157 2b2d2872 2021-06-20 op {
158 e39920a9 2021-07-07 op struct vline *vl;
159 e39920a9 2021-07-07 op
160 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
161 e39920a9 2021-07-07 op == NULL)
162 2b2d2872 2021-06-20 op return;
163 2b2d2872 2021-06-20 op
164 e39920a9 2021-07-07 op forward_line(buffer, -1);
165 e39920a9 2021-07-07 op
166 e39920a9 2021-07-07 op buffer->top_line = vl;
167 2b2d2872 2021-06-20 op }
168 2b2d2872 2021-06-20 op
169 2b2d2872 2021-06-20 op void
170 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
171 2b2d2872 2021-06-20 op {
172 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
173 2b2d2872 2021-06-20 op return;
174 2b2d2872 2021-06-20 op
175 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
176 2b2d2872 2021-06-20 op buffer->line_off++;
177 2b2d2872 2021-06-20 op }
178 2b2d2872 2021-06-20 op
179 2b2d2872 2021-06-20 op void
180 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
181 2b2d2872 2021-06-20 op {
182 64923c4b 2021-07-15 op struct vline *vl;
183 64923c4b 2021-07-15 op int i;
184 64923c4b 2021-07-15 op
185 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
186 64923c4b 2021-07-15 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
187 64923c4b 2021-07-15 op if (vl == NULL)
188 64923c4b 2021-07-15 op break;
189 64923c4b 2021-07-15 op buffer->top_line = vl;
190 64923c4b 2021-07-15 op forward_line(buffer, -1);
191 64923c4b 2021-07-15 op }
192 2b2d2872 2021-06-20 op }
193 2b2d2872 2021-06-20 op
194 2b2d2872 2021-06-20 op void
195 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
196 2b2d2872 2021-06-20 op {
197 64923c4b 2021-07-15 op int i;
198 64923c4b 2021-07-15 op
199 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
200 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
201 64923c4b 2021-07-15 op break;
202 64923c4b 2021-07-15 op
203 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
204 64923c4b 2021-07-15 op vlines);
205 64923c4b 2021-07-15 op }
206 2b2d2872 2021-06-20 op }
207 2b2d2872 2021-06-20 op
208 2b2d2872 2021-06-20 op void
209 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
210 2b2d2872 2021-06-20 op {
211 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
212 c4c82003 2021-07-01 op buffer->cpoff = 0;
213 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
214 2b2d2872 2021-06-20 op buffer->line_off = 0;
215 2b2d2872 2021-06-20 op }
216 2b2d2872 2021-06-20 op
217 2b2d2872 2021-06-20 op void
218 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
219 2b2d2872 2021-06-20 op {
220 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
221 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
222 2b2d2872 2021-06-20 op }
223 2b2d2872 2021-06-20 op
224 2b2d2872 2021-06-20 op void
225 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
226 2b2d2872 2021-06-20 op {
227 2b2d2872 2021-06-20 op save_session();
228 2b2d2872 2021-06-20 op event_loopbreak();
229 2b2d2872 2021-06-20 op }
230 2b2d2872 2021-06-20 op
231 2b2d2872 2021-06-20 op void
232 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
233 2b2d2872 2021-06-20 op {
234 2b2d2872 2021-06-20 op struct vline *vl;
235 963c680c 2021-07-05 op struct line *l;
236 2b2d2872 2021-06-20 op
237 2b2d2872 2021-06-20 op vl = buffer->current_line;
238 963c680c 2021-07-05 op switch (vl->parent->type) {
239 963c680c 2021-07-05 op case LINE_LINK:
240 83dce83d 2021-07-17 op load_url_in_tab(current_tab, vl->parent->alt);
241 963c680c 2021-07-05 op break;
242 963c680c 2021-07-05 op case LINE_PRE_START:
243 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
244 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
245 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
246 963c680c 2021-07-05 op break;
247 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
248 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
249 6e6c6afb 2021-07-14 op buffer->line_max--;
250 6e6c6afb 2021-07-14 op else
251 6e6c6afb 2021-07-14 op buffer->line_max++;
252 963c680c 2021-07-05 op }
253 963c680c 2021-07-05 op break;
254 963c680c 2021-07-05 op default:
255 963c680c 2021-07-05 op break;
256 963c680c 2021-07-05 op }
257 2b2d2872 2021-06-20 op }
258 2b2d2872 2021-06-20 op
259 2b2d2872 2021-06-20 op void
260 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
261 2b2d2872 2021-06-20 op {
262 2b2d2872 2021-06-20 op struct vline *vl;
263 2b2d2872 2021-06-20 op
264 2b2d2872 2021-06-20 op vl = buffer->current_line;
265 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
266 2b2d2872 2021-06-20 op return;
267 2b2d2872 2021-06-20 op
268 fbadd395 2021-07-16 op new_tab(vl->parent->alt);
269 2b2d2872 2021-06-20 op }
270 2b2d2872 2021-06-20 op
271 2b2d2872 2021-06-20 op void
272 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
273 2b2d2872 2021-06-20 op {
274 5d0feb4b 2021-06-23 op struct excursion place;
275 5d0feb4b 2021-06-23 op
276 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
277 5d0feb4b 2021-06-23 op
278 2b2d2872 2021-06-20 op do {
279 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
280 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
281 2b2d2872 2021-06-20 op message("No previous link");
282 2b2d2872 2021-06-20 op return;
283 2b2d2872 2021-06-20 op }
284 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
285 2b2d2872 2021-06-20 op }
286 2b2d2872 2021-06-20 op
287 2b2d2872 2021-06-20 op void
288 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
289 2b2d2872 2021-06-20 op {
290 5d0feb4b 2021-06-23 op struct excursion place;
291 5d0feb4b 2021-06-23 op
292 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
293 5d0feb4b 2021-06-23 op
294 2b2d2872 2021-06-20 op do {
295 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
296 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
297 2b2d2872 2021-06-20 op message("No next link");
298 2b2d2872 2021-06-20 op return;
299 2b2d2872 2021-06-20 op }
300 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
301 1c412d48 2021-06-25 op }
302 1c412d48 2021-06-25 op
303 1c412d48 2021-06-25 op static inline int
304 1c412d48 2021-06-25 op is_heading(const struct line *l)
305 1c412d48 2021-06-25 op {
306 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
307 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
308 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
309 1c412d48 2021-06-25 op }
310 1c412d48 2021-06-25 op
311 1c412d48 2021-06-25 op void
312 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
313 1c412d48 2021-06-25 op {
314 1c412d48 2021-06-25 op struct excursion place;
315 1c412d48 2021-06-25 op
316 1c412d48 2021-06-25 op save_excursion(&place, buffer);
317 1c412d48 2021-06-25 op
318 1c412d48 2021-06-25 op do {
319 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
320 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
321 1c412d48 2021-06-25 op message("No previous heading");
322 1c412d48 2021-06-25 op return;
323 1c412d48 2021-06-25 op }
324 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
325 2b2d2872 2021-06-20 op }
326 2b2d2872 2021-06-20 op
327 2b2d2872 2021-06-20 op void
328 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
329 1c412d48 2021-06-25 op {
330 1c412d48 2021-06-25 op struct excursion place;
331 1c412d48 2021-06-25 op
332 1c412d48 2021-06-25 op save_excursion(&place, buffer);
333 1c412d48 2021-06-25 op
334 1c412d48 2021-06-25 op do {
335 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
336 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
337 1c412d48 2021-06-25 op message("No next heading");
338 1c412d48 2021-06-25 op return;
339 1c412d48 2021-06-25 op }
340 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
341 1c412d48 2021-06-25 op }
342 1c412d48 2021-06-25 op
343 1c412d48 2021-06-25 op void
344 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
345 2b2d2872 2021-06-20 op {
346 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
347 2b2d2872 2021-06-20 op message("No previous page");
348 2b2d2872 2021-06-20 op else
349 83dce83d 2021-07-17 op start_loading_anim(current_tab);
350 2b2d2872 2021-06-20 op }
351 2b2d2872 2021-06-20 op
352 2b2d2872 2021-06-20 op void
353 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
354 2b2d2872 2021-06-20 op {
355 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
356 2b2d2872 2021-06-20 op message("No next page");
357 2b2d2872 2021-06-20 op else
358 83dce83d 2021-07-17 op start_loading_anim(current_tab);
359 2b2d2872 2021-06-20 op }
360 2b2d2872 2021-06-20 op
361 2b2d2872 2021-06-20 op void
362 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
363 2b2d2872 2021-06-20 op {
364 2b2d2872 2021-06-20 op message(NULL);
365 2b2d2872 2021-06-20 op }
366 2b2d2872 2021-06-20 op
367 2b2d2872 2021-06-20 op void
368 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
369 2b2d2872 2021-06-20 op {
370 2b2d2872 2021-06-20 op size_t len;
371 2b2d2872 2021-06-20 op
372 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
373 2b2d2872 2021-06-20 op
374 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
375 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
376 2b2d2872 2021-06-20 op
377 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
378 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
379 2b2d2872 2021-06-20 op
380 2b2d2872 2021-06-20 op if (thiskey.meta)
381 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
382 2b2d2872 2021-06-20 op
383 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
384 2b2d2872 2021-06-20 op
385 2b2d2872 2021-06-20 op if (thiskey.meta)
386 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
387 2b2d2872 2021-06-20 op }
388 2b2d2872 2021-06-20 op
389 2b2d2872 2021-06-20 op void
390 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
391 2b2d2872 2021-06-20 op {
392 2b2d2872 2021-06-20 op struct tab *tab, *t;
393 2b2d2872 2021-06-20 op
394 83dce83d 2021-07-17 op tab = current_tab;
395 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
396 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
397 2b2d2872 2021-06-20 op message("Can't close the only tab.");
398 2b2d2872 2021-06-20 op return;
399 2b2d2872 2021-06-20 op }
400 2b2d2872 2021-06-20 op
401 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
402 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
403 2b2d2872 2021-06-20 op
404 2b2d2872 2021-06-20 op stop_tab(tab);
405 2b2d2872 2021-06-20 op
406 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
407 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
408 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
409 2b2d2872 2021-06-20 op free(tab);
410 2b2d2872 2021-06-20 op
411 2b2d2872 2021-06-20 op switch_to_tab(t);
412 2b2d2872 2021-06-20 op }
413 2b2d2872 2021-06-20 op
414 2b2d2872 2021-06-20 op void
415 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
416 2b2d2872 2021-06-20 op {
417 2b2d2872 2021-06-20 op struct tab *t, *i;
418 2b2d2872 2021-06-20 op
419 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
420 83dce83d 2021-07-17 op if (t == current_tab)
421 2b2d2872 2021-06-20 op continue;
422 2b2d2872 2021-06-20 op
423 2b2d2872 2021-06-20 op stop_tab(t);
424 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
425 2b2d2872 2021-06-20 op free(t);
426 2b2d2872 2021-06-20 op }
427 2b2d2872 2021-06-20 op }
428 2b2d2872 2021-06-20 op
429 2b2d2872 2021-06-20 op void
430 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
431 2b2d2872 2021-06-20 op {
432 2b2d2872 2021-06-20 op const char *url;
433 2b2d2872 2021-06-20 op
434 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
435 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
436 2b2d2872 2021-06-20 op
437 2b2d2872 2021-06-20 op new_tab(url);
438 2b2d2872 2021-06-20 op }
439 2b2d2872 2021-06-20 op
440 2b2d2872 2021-06-20 op void
441 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
442 2b2d2872 2021-06-20 op {
443 83dce83d 2021-07-17 op struct tab *t;
444 2b2d2872 2021-06-20 op
445 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
446 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
447 2ddbda6b 2021-07-17 op switch_to_tab(t);
448 2b2d2872 2021-06-20 op }
449 2b2d2872 2021-06-20 op
450 2b2d2872 2021-06-20 op void
451 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
452 2b2d2872 2021-06-20 op {
453 83dce83d 2021-07-17 op struct tab *t;
454 2b2d2872 2021-06-20 op
455 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
456 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
457 2ddbda6b 2021-07-17 op switch_to_tab(t);
458 2b2d2872 2021-06-20 op }
459 2b2d2872 2021-06-20 op
460 2b2d2872 2021-06-20 op void
461 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
462 2b2d2872 2021-06-20 op {
463 83dce83d 2021-07-17 op struct tab *t;
464 2b2d2872 2021-06-20 op
465 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
466 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
467 2b2d2872 2021-06-20 op
468 2b2d2872 2021-06-20 op if (t == NULL)
469 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
470 2b2d2872 2021-06-20 op else
471 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
472 2b2d2872 2021-06-20 op }
473 2b2d2872 2021-06-20 op
474 2b2d2872 2021-06-20 op void
475 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
476 2b2d2872 2021-06-20 op {
477 83dce83d 2021-07-17 op struct tab *t;
478 2b2d2872 2021-06-20 op
479 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
480 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
481 2b2d2872 2021-06-20 op
482 2b2d2872 2021-06-20 op if (t == NULL) {
483 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
484 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
485 2b2d2872 2021-06-20 op else
486 83dce83d 2021-07-17 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
487 2b2d2872 2021-06-20 op } else
488 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
489 2b2d2872 2021-06-20 op }
490 2b2d2872 2021-06-20 op
491 2b2d2872 2021-06-20 op void
492 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
493 65601367 2021-07-14 op {
494 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
495 65601367 2021-07-14 op
496 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
497 65601367 2021-07-14 op NULL, compl_ts, NULL);
498 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
499 65601367 2021-07-14 op }
500 65601367 2021-07-14 op
501 65601367 2021-07-14 op void
502 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
503 2b2d2872 2021-06-20 op {
504 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
505 2b2d2872 2021-06-20 op
506 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
507 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
508 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
509 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
510 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
511 2b2d2872 2021-06-20 op }
512 2b2d2872 2021-06-20 op
513 2b2d2872 2021-06-20 op void
514 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
515 2b2d2872 2021-06-20 op {
516 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
517 2b2d2872 2021-06-20 op
518 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
519 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
520 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
521 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
522 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
523 2b2d2872 2021-06-20 op }
524 2b2d2872 2021-06-20 op
525 2b2d2872 2021-06-20 op void
526 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
527 661233ed 2021-07-14 op {
528 83dce83d 2021-07-17 op load_url_in_tab(current_tab, current_tab->hist_cur->h);
529 661233ed 2021-07-14 op }
530 661233ed 2021-07-14 op
531 661233ed 2021-07-14 op void
532 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
533 2b2d2872 2021-06-20 op {
534 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
535 ca231710 2021-07-15 op
536 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
537 e5a2797f 2021-07-13 op NULL, NULL);
538 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
539 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
540 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
541 2b2d2872 2021-06-20 op }
542 2b2d2872 2021-06-20 op
543 2b2d2872 2021-06-20 op void
544 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
545 2b2d2872 2021-06-20 op {
546 83dce83d 2021-07-17 op load_url_in_tab(current_tab, "about:bookmarks");
547 2b2d2872 2021-06-20 op }
548 2b2d2872 2021-06-20 op
549 2b2d2872 2021-06-20 op void
550 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
551 2b2d2872 2021-06-20 op {
552 2b2d2872 2021-06-20 op ui_toggle_side_window();
553 753c6ac7 2021-07-14 op }
554 753c6ac7 2021-07-14 op
555 753c6ac7 2021-07-14 op void
556 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
557 753c6ac7 2021-07-14 op {
558 c1a72389 2021-07-15 op struct line *l;
559 c1a72389 2021-07-15 op
560 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
561 753c6ac7 2021-07-14 op
562 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
563 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
564 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
565 c1a72389 2021-07-15 op
566 c1a72389 2021-07-15 op if (l == NULL) {
567 c1a72389 2021-07-15 op message("No links found");
568 c1a72389 2021-07-15 op return;
569 c1a72389 2021-07-15 op }
570 c1a72389 2021-07-15 op
571 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
572 c1a72389 2021-07-15 op NULL, compl_ls, l);
573 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
574 753c6ac7 2021-07-14 op }
575 753c6ac7 2021-07-14 op
576 753c6ac7 2021-07-14 op void
577 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
578 753c6ac7 2021-07-14 op {
579 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
580 753c6ac7 2021-07-14 op
581 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
582 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
583 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
584 edd9a650 2021-07-15 op }
585 edd9a650 2021-07-15 op
586 edd9a650 2021-07-15 op void
587 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
588 edd9a650 2021-07-15 op {
589 c1a72389 2021-07-15 op struct line *l;
590 c1a72389 2021-07-15 op
591 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
592 edd9a650 2021-07-15 op
593 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
594 c1a72389 2021-07-15 op while (l != NULL &&
595 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
596 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
597 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
598 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
599 c1a72389 2021-07-15 op
600 c1a72389 2021-07-15 op if (l == NULL) {
601 c1a72389 2021-07-15 op message("No headings found");
602 c1a72389 2021-07-15 op return;
603 c1a72389 2021-07-15 op }
604 c1a72389 2021-07-15 op
605 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
606 c1a72389 2021-07-15 op NULL, compl_toc, l);
607 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
608 edd9a650 2021-07-15 op sizeof(ministate.prompt));
609 2b2d2872 2021-06-20 op }
610 2b2d2872 2021-06-20 op
611 2b2d2872 2021-06-20 op void
612 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
613 61251035 2021-06-26 op {
614 61251035 2021-06-26 op if (fill_column == INT_MAX)
615 61251035 2021-06-26 op return;
616 61251035 2021-06-26 op
617 61251035 2021-06-26 op fill_column += 2;
618 61251035 2021-06-26 op message("fill-column: %d", fill_column);
619 61251035 2021-06-26 op
620 61251035 2021-06-26 op ui_schedule_redraw();
621 61251035 2021-06-26 op }
622 61251035 2021-06-26 op
623 61251035 2021-06-26 op void
624 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
625 61251035 2021-06-26 op {
626 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
627 61251035 2021-06-26 op return;
628 61251035 2021-06-26 op
629 61251035 2021-06-26 op fill_column -= 2;
630 61251035 2021-06-26 op message("fill-column: %d", fill_column);
631 61251035 2021-06-26 op
632 61251035 2021-06-26 op ui_schedule_redraw();
633 61251035 2021-06-26 op }
634 61251035 2021-06-26 op
635 61251035 2021-06-26 op void
636 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
637 2b2d2872 2021-06-20 op {
638 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
639 2b2d2872 2021-06-20 op if (olivetti_mode)
640 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
641 2b2d2872 2021-06-20 op else
642 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
643 2b2d2872 2021-06-20 op
644 2b2d2872 2021-06-20 op ui_schedule_redraw();
645 2b2d2872 2021-06-20 op }
646 2b2d2872 2021-06-20 op
647 2b2d2872 2021-06-20 op void
648 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
649 2b2d2872 2021-06-20 op {
650 2b2d2872 2021-06-20 op char *c, *n;
651 2b2d2872 2021-06-20 op
652 2b2d2872 2021-06-20 op if (!in_minibuffer) {
653 2b2d2872 2021-06-20 op message("text is read-only");
654 2b2d2872 2021-06-20 op return;
655 2b2d2872 2021-06-20 op }
656 2b2d2872 2021-06-20 op
657 2b2d2872 2021-06-20 op minibuffer_taint_hist();
658 2b2d2872 2021-06-20 op
659 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
660 2b2d2872 2021-06-20 op if (*c == '\0')
661 2b2d2872 2021-06-20 op return;
662 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
663 2b2d2872 2021-06-20 op
664 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
665 b1e1e41a 2021-07-14 op
666 b1e1e41a 2021-07-14 op recompute_completions(0);
667 2b2d2872 2021-06-20 op }
668 2b2d2872 2021-06-20 op
669 2b2d2872 2021-06-20 op void
670 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
671 2b2d2872 2021-06-20 op {
672 2b2d2872 2021-06-20 op char *c, *p, *start;
673 2b2d2872 2021-06-20 op
674 2b2d2872 2021-06-20 op if (!in_minibuffer) {
675 2b2d2872 2021-06-20 op message("text is read-only");
676 2b2d2872 2021-06-20 op return;
677 2b2d2872 2021-06-20 op }
678 2b2d2872 2021-06-20 op
679 2b2d2872 2021-06-20 op minibuffer_taint_hist();
680 2b2d2872 2021-06-20 op
681 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
682 2b2d2872 2021-06-20 op start = buffer->current_line->line;
683 2b2d2872 2021-06-20 op if (c == start)
684 2b2d2872 2021-06-20 op return;
685 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
686 2b2d2872 2021-06-20 op
687 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
688 2b2d2872 2021-06-20 op buffer->cpoff--;
689 b1e1e41a 2021-07-14 op
690 b1e1e41a 2021-07-14 op recompute_completions(0);
691 2b2d2872 2021-06-20 op }
692 2b2d2872 2021-06-20 op
693 2b2d2872 2021-06-20 op void
694 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
695 2b2d2872 2021-06-20 op {
696 2b2d2872 2021-06-20 op char *c;
697 2b2d2872 2021-06-20 op
698 2b2d2872 2021-06-20 op if (!in_minibuffer) {
699 2b2d2872 2021-06-20 op message("text is read-only");
700 2b2d2872 2021-06-20 op return;
701 2b2d2872 2021-06-20 op }
702 2b2d2872 2021-06-20 op
703 2b2d2872 2021-06-20 op minibuffer_taint_hist();
704 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
705 2b2d2872 2021-06-20 op *c = '\0';
706 b1e1e41a 2021-07-14 op
707 b1e1e41a 2021-07-14 op recompute_completions(0);
708 2b2d2872 2021-06-20 op }
709 2b2d2872 2021-06-20 op
710 2b2d2872 2021-06-20 op void
711 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
712 2b2d2872 2021-06-20 op {
713 2b2d2872 2021-06-20 op if (!in_minibuffer)
714 2b2d2872 2021-06-20 op return;
715 2b2d2872 2021-06-20 op
716 2b2d2872 2021-06-20 op ministate.abortfn();
717 2b2d2872 2021-06-20 op }
718 2b2d2872 2021-06-20 op
719 2b2d2872 2021-06-20 op void
720 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
721 2b2d2872 2021-06-20 op {
722 2b2d2872 2021-06-20 op if (!in_minibuffer)
723 2b2d2872 2021-06-20 op return;
724 2b2d2872 2021-06-20 op
725 2b2d2872 2021-06-20 op minibuffer_taint_hist();
726 2b2d2872 2021-06-20 op ministate.donefn();
727 2b2d2872 2021-06-20 op }
728 2b2d2872 2021-06-20 op
729 2b2d2872 2021-06-20 op void
730 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
731 2b2d2872 2021-06-20 op {
732 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
733 2b2d2872 2021-06-20 op message("No history");
734 2b2d2872 2021-06-20 op return;
735 2b2d2872 2021-06-20 op }
736 2b2d2872 2021-06-20 op
737 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
738 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
739 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
740 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
741 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
742 fc14510d 2021-07-14 op message("No prev history item");
743 2b2d2872 2021-06-20 op } else {
744 2b2d2872 2021-06-20 op ministate.hist_off--;
745 2b2d2872 2021-06-20 op }
746 2b2d2872 2021-06-20 op
747 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
748 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
749 2b2d2872 2021-06-20 op }
750 2b2d2872 2021-06-20 op
751 2b2d2872 2021-06-20 op void
752 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
753 2b2d2872 2021-06-20 op {
754 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
755 2b2d2872 2021-06-20 op message("No history");
756 2b2d2872 2021-06-20 op return;
757 2b2d2872 2021-06-20 op }
758 2b2d2872 2021-06-20 op
759 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
760 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
761 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
762 2b2d2872 2021-06-20 op ministate.hist_off = 0;
763 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
764 fc14510d 2021-07-14 op message("No next history item");
765 2b2d2872 2021-06-20 op } else {
766 2b2d2872 2021-06-20 op ministate.hist_off++;
767 2b2d2872 2021-06-20 op }
768 2b2d2872 2021-06-20 op
769 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
770 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
771 2b2d2872 2021-06-20 op }
772 e7b982f4 2021-07-14 op
773 e7b982f4 2021-07-14 op void
774 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
775 e7b982f4 2021-07-14 op {
776 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
777 e7b982f4 2021-07-14 op return;
778 e7b982f4 2021-07-14 op
779 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
780 e7b982f4 2021-07-14 op
781 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
782 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
783 e7b982f4 2021-07-14 op
784 e7b982f4 2021-07-14 op forward_line(buffer, -1);
785 e7b982f4 2021-07-14 op
786 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
787 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
788 e7b982f4 2021-07-14 op }
789 e7b982f4 2021-07-14 op
790 e7b982f4 2021-07-14 op void
791 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
792 e7b982f4 2021-07-14 op {
793 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
794 e7b982f4 2021-07-14 op return;
795 e7b982f4 2021-07-14 op
796 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
797 e7b982f4 2021-07-14 op
798 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
799 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
800 e7b982f4 2021-07-14 op
801 e7b982f4 2021-07-14 op forward_line(buffer, +1);
802 e7b982f4 2021-07-14 op
803 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
804 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
805 e7b982f4 2021-07-14 op }
806 e7b982f4 2021-07-14 op
807 e7b982f4 2021-07-14 op void
808 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
809 e7b982f4 2021-07-14 op {
810 e7b982f4 2021-07-14 op struct vline *vl;
811 e7b982f4 2021-07-14 op
812 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
813 e7b982f4 2021-07-14 op return;
814 e7b982f4 2021-07-14 op
815 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
816 e7b982f4 2021-07-14 op if ((vl = buffer->current_line) == NULL)
817 e7b982f4 2021-07-14 op return;
818 e7b982f4 2021-07-14 op
819 e7b982f4 2021-07-14 op minibuffer_taint_hist();
820 e7b982f4 2021-07-14 op strlcpy(ministate.buf, vl->parent->line, sizeof(ministate.buf));
821 e7b982f4 2021-07-14 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
822 e7b982f4 2021-07-14 op }
823 8a3b5609 2021-07-15 op
824 8a3b5609 2021-07-15 op void
825 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
826 8a3b5609 2021-07-15 op {
827 8a3b5609 2021-07-15 op message("Zzz...");
828 8a3b5609 2021-07-15 op ui_suspend();
829 8a3b5609 2021-07-15 op }
830 987d9c88 2021-07-15 op
831 987d9c88 2021-07-15 op void
832 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
833 987d9c88 2021-07-15 op {
834 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
835 987d9c88 2021-07-15 op
836 987d9c88 2021-07-15 op if (dont_wrap_pre)
837 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
838 987d9c88 2021-07-15 op else
839 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
840 987d9c88 2021-07-15 op
841 987d9c88 2021-07-15 op ui_schedule_redraw();
842 987d9c88 2021-07-15 op }
843 de190a2b 2021-07-17 op
844 de190a2b 2021-07-17 op void
845 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
846 de190a2b 2021-07-17 op {
847 de190a2b 2021-07-17 op struct vline *vl;
848 de190a2b 2021-07-17 op
849 de190a2b 2021-07-17 op if (!in_minibuffer)
850 de190a2b 2021-07-17 op return;
851 de190a2b 2021-07-17 op
852 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
853 de190a2b 2021-07-17 op
854 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
855 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
856 de190a2b 2021-07-17 op
857 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
858 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
859 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
860 de190a2b 2021-07-17 op
861 de190a2b 2021-07-17 op if (vl == NULL)
862 de190a2b 2021-07-17 op return;
863 de190a2b 2021-07-17 op
864 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
865 de190a2b 2021-07-17 op buffer->top_line = vl;
866 de190a2b 2021-07-17 op buffer->current_line = vl;
867 de190a2b 2021-07-17 op }
868 de190a2b 2021-07-17 op
869 de190a2b 2021-07-17 op void
870 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
871 de190a2b 2021-07-17 op {
872 de190a2b 2021-07-17 op struct vline *vl;
873 de190a2b 2021-07-17 op
874 de190a2b 2021-07-17 op if (!in_minibuffer)
875 de190a2b 2021-07-17 op return;
876 de190a2b 2021-07-17 op
877 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
878 de190a2b 2021-07-17 op
879 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
880 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
881 de190a2b 2021-07-17 op
882 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
883 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
884 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
885 de190a2b 2021-07-17 op
886 de190a2b 2021-07-17 op if (vl == NULL)
887 de190a2b 2021-07-17 op return;
888 de190a2b 2021-07-17 op
889 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
890 de190a2b 2021-07-17 op buffer->current_line = vl;
891 de190a2b 2021-07-17 op }