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