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