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 64923c4b 2021-07-15 op buffer->top_line = vl;
201 64923c4b 2021-07-15 op forward_line(buffer, -1);
202 64923c4b 2021-07-15 op }
203 2b2d2872 2021-06-20 op }
204 2b2d2872 2021-06-20 op
205 2b2d2872 2021-06-20 op void
206 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
207 2b2d2872 2021-06-20 op {
208 64923c4b 2021-07-15 op int i;
209 64923c4b 2021-07-15 op
210 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
211 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
212 64923c4b 2021-07-15 op break;
213 64923c4b 2021-07-15 op
214 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
215 64923c4b 2021-07-15 op vlines);
216 64923c4b 2021-07-15 op }
217 2b2d2872 2021-06-20 op }
218 2b2d2872 2021-06-20 op
219 2b2d2872 2021-06-20 op void
220 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
221 2b2d2872 2021-06-20 op {
222 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
223 c4c82003 2021-07-01 op buffer->cpoff = 0;
224 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
225 2b2d2872 2021-06-20 op buffer->line_off = 0;
226 2b2d2872 2021-06-20 op }
227 2b2d2872 2021-06-20 op
228 2b2d2872 2021-06-20 op void
229 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
230 2b2d2872 2021-06-20 op {
231 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
232 f04d2fc5 2021-07-18 op
233 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
234 52b1043c 2021-07-19 op return;
235 52b1043c 2021-07-19 op
236 f04d2fc5 2021-07-18 op /* deal with invisible lines */
237 f04d2fc5 2021-07-18 op if (buffer->current_line->parent->flags & L_HIDDEN)
238 f04d2fc5 2021-07-18 op forward_line(buffer, -1);
239 f04d2fc5 2021-07-18 op
240 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
241 2b2d2872 2021-06-20 op }
242 2b2d2872 2021-06-20 op
243 2b2d2872 2021-06-20 op void
244 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
245 2b2d2872 2021-06-20 op {
246 2b2d2872 2021-06-20 op save_session();
247 2b2d2872 2021-06-20 op event_loopbreak();
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_push_button(struct buffer *buffer)
252 2b2d2872 2021-06-20 op {
253 2b2d2872 2021-06-20 op struct vline *vl;
254 963c680c 2021-07-05 op struct line *l;
255 2b2d2872 2021-06-20 op
256 2b2d2872 2021-06-20 op vl = buffer->current_line;
257 a87cfde9 2021-07-19 op
258 a87cfde9 2021-07-19 op if (vl == NULL)
259 a87cfde9 2021-07-19 op return;
260 a87cfde9 2021-07-19 op
261 963c680c 2021-07-05 op switch (vl->parent->type) {
262 963c680c 2021-07-05 op case LINE_LINK:
263 83dce83d 2021-07-17 op load_url_in_tab(current_tab, vl->parent->alt);
264 963c680c 2021-07-05 op break;
265 963c680c 2021-07-05 op case LINE_PRE_START:
266 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
267 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
268 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
269 963c680c 2021-07-05 op break;
270 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
271 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
272 6e6c6afb 2021-07-14 op buffer->line_max--;
273 6e6c6afb 2021-07-14 op else
274 6e6c6afb 2021-07-14 op buffer->line_max++;
275 963c680c 2021-07-05 op }
276 963c680c 2021-07-05 op break;
277 963c680c 2021-07-05 op default:
278 963c680c 2021-07-05 op break;
279 963c680c 2021-07-05 op }
280 2b2d2872 2021-06-20 op }
281 2b2d2872 2021-06-20 op
282 2b2d2872 2021-06-20 op void
283 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
284 2b2d2872 2021-06-20 op {
285 2b2d2872 2021-06-20 op struct vline *vl;
286 2b2d2872 2021-06-20 op
287 2b2d2872 2021-06-20 op vl = buffer->current_line;
288 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
289 2b2d2872 2021-06-20 op return;
290 2b2d2872 2021-06-20 op
291 fbadd395 2021-07-16 op new_tab(vl->parent->alt);
292 2b2d2872 2021-06-20 op }
293 2b2d2872 2021-06-20 op
294 2b2d2872 2021-06-20 op void
295 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
296 2b2d2872 2021-06-20 op {
297 5d0feb4b 2021-06-23 op struct excursion place;
298 5d0feb4b 2021-06-23 op
299 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
300 5d0feb4b 2021-06-23 op
301 2b2d2872 2021-06-20 op do {
302 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
303 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
304 2b2d2872 2021-06-20 op message("No previous link");
305 2b2d2872 2021-06-20 op return;
306 2b2d2872 2021-06-20 op }
307 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
308 2b2d2872 2021-06-20 op }
309 2b2d2872 2021-06-20 op
310 2b2d2872 2021-06-20 op void
311 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
312 2b2d2872 2021-06-20 op {
313 5d0feb4b 2021-06-23 op struct excursion place;
314 5d0feb4b 2021-06-23 op
315 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
316 5d0feb4b 2021-06-23 op
317 2b2d2872 2021-06-20 op do {
318 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
319 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
320 2b2d2872 2021-06-20 op message("No next link");
321 2b2d2872 2021-06-20 op return;
322 2b2d2872 2021-06-20 op }
323 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
324 1c412d48 2021-06-25 op }
325 1c412d48 2021-06-25 op
326 1c412d48 2021-06-25 op static inline int
327 1c412d48 2021-06-25 op is_heading(const struct line *l)
328 1c412d48 2021-06-25 op {
329 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
330 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
331 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
332 1c412d48 2021-06-25 op }
333 1c412d48 2021-06-25 op
334 1c412d48 2021-06-25 op void
335 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
336 1c412d48 2021-06-25 op {
337 1c412d48 2021-06-25 op struct excursion place;
338 1c412d48 2021-06-25 op
339 1c412d48 2021-06-25 op save_excursion(&place, buffer);
340 1c412d48 2021-06-25 op
341 1c412d48 2021-06-25 op do {
342 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
343 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
344 1c412d48 2021-06-25 op message("No previous heading");
345 1c412d48 2021-06-25 op return;
346 1c412d48 2021-06-25 op }
347 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
348 2b2d2872 2021-06-20 op }
349 2b2d2872 2021-06-20 op
350 2b2d2872 2021-06-20 op void
351 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
352 1c412d48 2021-06-25 op {
353 1c412d48 2021-06-25 op struct excursion place;
354 1c412d48 2021-06-25 op
355 1c412d48 2021-06-25 op save_excursion(&place, buffer);
356 1c412d48 2021-06-25 op
357 1c412d48 2021-06-25 op do {
358 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
359 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
360 1c412d48 2021-06-25 op message("No next heading");
361 1c412d48 2021-06-25 op return;
362 1c412d48 2021-06-25 op }
363 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
364 1c412d48 2021-06-25 op }
365 1c412d48 2021-06-25 op
366 1c412d48 2021-06-25 op void
367 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
368 2b2d2872 2021-06-20 op {
369 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
370 2b2d2872 2021-06-20 op message("No previous page");
371 2b2d2872 2021-06-20 op else
372 83dce83d 2021-07-17 op start_loading_anim(current_tab);
373 2b2d2872 2021-06-20 op }
374 2b2d2872 2021-06-20 op
375 2b2d2872 2021-06-20 op void
376 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
377 2b2d2872 2021-06-20 op {
378 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
379 2b2d2872 2021-06-20 op message("No next page");
380 2b2d2872 2021-06-20 op else
381 83dce83d 2021-07-17 op start_loading_anim(current_tab);
382 2b2d2872 2021-06-20 op }
383 2b2d2872 2021-06-20 op
384 2b2d2872 2021-06-20 op void
385 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
386 2b2d2872 2021-06-20 op {
387 2b2d2872 2021-06-20 op message(NULL);
388 2b2d2872 2021-06-20 op }
389 2b2d2872 2021-06-20 op
390 2b2d2872 2021-06-20 op void
391 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
392 2b2d2872 2021-06-20 op {
393 2b2d2872 2021-06-20 op size_t len;
394 2b2d2872 2021-06-20 op
395 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
396 2b2d2872 2021-06-20 op
397 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
398 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
399 2b2d2872 2021-06-20 op
400 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
401 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
402 2b2d2872 2021-06-20 op
403 2b2d2872 2021-06-20 op if (thiskey.meta)
404 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
405 2b2d2872 2021-06-20 op
406 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
407 2b2d2872 2021-06-20 op
408 2b2d2872 2021-06-20 op if (thiskey.meta)
409 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
410 2b2d2872 2021-06-20 op }
411 2b2d2872 2021-06-20 op
412 2b2d2872 2021-06-20 op void
413 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
414 2b2d2872 2021-06-20 op {
415 2b2d2872 2021-06-20 op struct tab *tab, *t;
416 2b2d2872 2021-06-20 op
417 83dce83d 2021-07-17 op tab = current_tab;
418 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
419 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
420 2b2d2872 2021-06-20 op message("Can't close the only tab.");
421 2b2d2872 2021-06-20 op return;
422 2b2d2872 2021-06-20 op }
423 2b2d2872 2021-06-20 op
424 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
425 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
426 2b2d2872 2021-06-20 op
427 2b2d2872 2021-06-20 op stop_tab(tab);
428 2b2d2872 2021-06-20 op
429 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
430 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
431 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
432 2b2d2872 2021-06-20 op free(tab);
433 2b2d2872 2021-06-20 op
434 2b2d2872 2021-06-20 op switch_to_tab(t);
435 2b2d2872 2021-06-20 op }
436 2b2d2872 2021-06-20 op
437 2b2d2872 2021-06-20 op void
438 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
439 2b2d2872 2021-06-20 op {
440 2b2d2872 2021-06-20 op struct tab *t, *i;
441 2b2d2872 2021-06-20 op
442 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
443 83dce83d 2021-07-17 op if (t == current_tab)
444 2b2d2872 2021-06-20 op continue;
445 2b2d2872 2021-06-20 op
446 2b2d2872 2021-06-20 op stop_tab(t);
447 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
448 2b2d2872 2021-06-20 op free(t);
449 2b2d2872 2021-06-20 op }
450 2b2d2872 2021-06-20 op }
451 2b2d2872 2021-06-20 op
452 2b2d2872 2021-06-20 op void
453 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
454 2b2d2872 2021-06-20 op {
455 2b2d2872 2021-06-20 op const char *url;
456 2b2d2872 2021-06-20 op
457 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
458 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
459 2b2d2872 2021-06-20 op
460 2b2d2872 2021-06-20 op new_tab(url);
461 2b2d2872 2021-06-20 op }
462 2b2d2872 2021-06-20 op
463 2b2d2872 2021-06-20 op void
464 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
465 2b2d2872 2021-06-20 op {
466 83dce83d 2021-07-17 op struct tab *t;
467 2b2d2872 2021-06-20 op
468 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
469 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
470 2ddbda6b 2021-07-17 op switch_to_tab(t);
471 2b2d2872 2021-06-20 op }
472 2b2d2872 2021-06-20 op
473 2b2d2872 2021-06-20 op void
474 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
475 2b2d2872 2021-06-20 op {
476 83dce83d 2021-07-17 op struct tab *t;
477 2b2d2872 2021-06-20 op
478 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
479 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
480 2ddbda6b 2021-07-17 op switch_to_tab(t);
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_move(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 t = TAILQ_NEXT(current_tab, tabs);
489 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
490 2b2d2872 2021-06-20 op
491 2b2d2872 2021-06-20 op if (t == NULL)
492 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
493 2b2d2872 2021-06-20 op else
494 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
495 2b2d2872 2021-06-20 op }
496 2b2d2872 2021-06-20 op
497 2b2d2872 2021-06-20 op void
498 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
499 2b2d2872 2021-06-20 op {
500 83dce83d 2021-07-17 op struct tab *t;
501 2b2d2872 2021-06-20 op
502 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
503 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
504 2b2d2872 2021-06-20 op
505 2b2d2872 2021-06-20 op if (t == NULL) {
506 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
507 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
508 2b2d2872 2021-06-20 op else
509 83dce83d 2021-07-17 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
510 2b2d2872 2021-06-20 op } else
511 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
512 2b2d2872 2021-06-20 op }
513 2b2d2872 2021-06-20 op
514 2b2d2872 2021-06-20 op void
515 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
516 65601367 2021-07-14 op {
517 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
518 65601367 2021-07-14 op
519 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
520 65601367 2021-07-14 op NULL, compl_ts, NULL);
521 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
522 65601367 2021-07-14 op }
523 65601367 2021-07-14 op
524 65601367 2021-07-14 op void
525 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
526 2b2d2872 2021-06-20 op {
527 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
528 2b2d2872 2021-06-20 op
529 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
530 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
531 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
532 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
533 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
534 2b2d2872 2021-06-20 op }
535 2b2d2872 2021-06-20 op
536 2b2d2872 2021-06-20 op void
537 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
538 2b2d2872 2021-06-20 op {
539 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
540 2b2d2872 2021-06-20 op
541 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
542 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
543 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
544 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
545 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
546 2b2d2872 2021-06-20 op }
547 2b2d2872 2021-06-20 op
548 2b2d2872 2021-06-20 op void
549 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
550 661233ed 2021-07-14 op {
551 83dce83d 2021-07-17 op load_url_in_tab(current_tab, current_tab->hist_cur->h);
552 661233ed 2021-07-14 op }
553 661233ed 2021-07-14 op
554 661233ed 2021-07-14 op void
555 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
556 2b2d2872 2021-06-20 op {
557 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
558 ca231710 2021-07-15 op
559 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
560 e5a2797f 2021-07-13 op NULL, NULL);
561 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
562 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
563 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
564 2b2d2872 2021-06-20 op }
565 2b2d2872 2021-06-20 op
566 2b2d2872 2021-06-20 op void
567 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
568 2b2d2872 2021-06-20 op {
569 83dce83d 2021-07-17 op load_url_in_tab(current_tab, "about:bookmarks");
570 2b2d2872 2021-06-20 op }
571 2b2d2872 2021-06-20 op
572 2b2d2872 2021-06-20 op void
573 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
574 2b2d2872 2021-06-20 op {
575 2b2d2872 2021-06-20 op ui_toggle_side_window();
576 753c6ac7 2021-07-14 op }
577 753c6ac7 2021-07-14 op
578 753c6ac7 2021-07-14 op void
579 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
580 753c6ac7 2021-07-14 op {
581 c1a72389 2021-07-15 op struct line *l;
582 c1a72389 2021-07-15 op
583 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
584 753c6ac7 2021-07-14 op
585 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
586 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
587 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
588 c1a72389 2021-07-15 op
589 c1a72389 2021-07-15 op if (l == NULL) {
590 c1a72389 2021-07-15 op message("No links found");
591 c1a72389 2021-07-15 op return;
592 c1a72389 2021-07-15 op }
593 c1a72389 2021-07-15 op
594 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
595 c1a72389 2021-07-15 op NULL, compl_ls, l);
596 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
597 753c6ac7 2021-07-14 op }
598 753c6ac7 2021-07-14 op
599 753c6ac7 2021-07-14 op void
600 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
601 753c6ac7 2021-07-14 op {
602 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
603 753c6ac7 2021-07-14 op
604 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
605 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
606 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
607 edd9a650 2021-07-15 op }
608 edd9a650 2021-07-15 op
609 edd9a650 2021-07-15 op void
610 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
611 edd9a650 2021-07-15 op {
612 c1a72389 2021-07-15 op struct line *l;
613 c1a72389 2021-07-15 op
614 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
615 edd9a650 2021-07-15 op
616 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
617 c1a72389 2021-07-15 op while (l != NULL &&
618 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
619 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
620 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
621 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
622 c1a72389 2021-07-15 op
623 c1a72389 2021-07-15 op if (l == NULL) {
624 c1a72389 2021-07-15 op message("No headings found");
625 c1a72389 2021-07-15 op return;
626 c1a72389 2021-07-15 op }
627 c1a72389 2021-07-15 op
628 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
629 c1a72389 2021-07-15 op NULL, compl_toc, l);
630 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
631 edd9a650 2021-07-15 op sizeof(ministate.prompt));
632 2b2d2872 2021-06-20 op }
633 2b2d2872 2021-06-20 op
634 2b2d2872 2021-06-20 op void
635 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
636 61251035 2021-06-26 op {
637 61251035 2021-06-26 op if (fill_column == INT_MAX)
638 61251035 2021-06-26 op return;
639 61251035 2021-06-26 op
640 61251035 2021-06-26 op fill_column += 2;
641 61251035 2021-06-26 op message("fill-column: %d", fill_column);
642 61251035 2021-06-26 op
643 61251035 2021-06-26 op ui_schedule_redraw();
644 61251035 2021-06-26 op }
645 61251035 2021-06-26 op
646 61251035 2021-06-26 op void
647 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
648 61251035 2021-06-26 op {
649 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
650 61251035 2021-06-26 op return;
651 61251035 2021-06-26 op
652 61251035 2021-06-26 op fill_column -= 2;
653 61251035 2021-06-26 op message("fill-column: %d", fill_column);
654 61251035 2021-06-26 op
655 61251035 2021-06-26 op ui_schedule_redraw();
656 61251035 2021-06-26 op }
657 61251035 2021-06-26 op
658 61251035 2021-06-26 op void
659 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
660 2b2d2872 2021-06-20 op {
661 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
662 2b2d2872 2021-06-20 op if (olivetti_mode)
663 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
664 2b2d2872 2021-06-20 op else
665 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
666 2b2d2872 2021-06-20 op
667 2b2d2872 2021-06-20 op ui_schedule_redraw();
668 2b2d2872 2021-06-20 op }
669 2b2d2872 2021-06-20 op
670 2b2d2872 2021-06-20 op void
671 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
672 2b2d2872 2021-06-20 op {
673 2b2d2872 2021-06-20 op char *c, *n;
674 2b2d2872 2021-06-20 op
675 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
676 2b2d2872 2021-06-20 op
677 2b2d2872 2021-06-20 op minibuffer_taint_hist();
678 2b2d2872 2021-06-20 op
679 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
680 2b2d2872 2021-06-20 op if (*c == '\0')
681 2b2d2872 2021-06-20 op return;
682 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
683 2b2d2872 2021-06-20 op
684 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
685 b1e1e41a 2021-07-14 op
686 b1e1e41a 2021-07-14 op recompute_completions(0);
687 2b2d2872 2021-06-20 op }
688 2b2d2872 2021-06-20 op
689 2b2d2872 2021-06-20 op void
690 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
691 2b2d2872 2021-06-20 op {
692 2b2d2872 2021-06-20 op char *c, *p, *start;
693 2b2d2872 2021-06-20 op
694 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
695 2b2d2872 2021-06-20 op
696 2b2d2872 2021-06-20 op minibuffer_taint_hist();
697 2b2d2872 2021-06-20 op
698 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
699 2b2d2872 2021-06-20 op start = buffer->current_line->line;
700 2b2d2872 2021-06-20 op if (c == start)
701 2b2d2872 2021-06-20 op return;
702 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
703 2b2d2872 2021-06-20 op
704 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
705 2b2d2872 2021-06-20 op buffer->cpoff--;
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_kill_line(struct buffer *buffer)
712 2b2d2872 2021-06-20 op {
713 2b2d2872 2021-06-20 op char *c;
714 2b2d2872 2021-06-20 op
715 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
716 2b2d2872 2021-06-20 op
717 2b2d2872 2021-06-20 op minibuffer_taint_hist();
718 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
719 2b2d2872 2021-06-20 op *c = '\0';
720 b1e1e41a 2021-07-14 op
721 b1e1e41a 2021-07-14 op recompute_completions(0);
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_abort(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 ministate.abortfn();
731 2b2d2872 2021-06-20 op }
732 2b2d2872 2021-06-20 op
733 2b2d2872 2021-06-20 op void
734 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
735 2b2d2872 2021-06-20 op {
736 2b2d2872 2021-06-20 op if (!in_minibuffer)
737 2b2d2872 2021-06-20 op return;
738 2b2d2872 2021-06-20 op
739 2b2d2872 2021-06-20 op minibuffer_taint_hist();
740 2b2d2872 2021-06-20 op ministate.donefn();
741 2b2d2872 2021-06-20 op }
742 2b2d2872 2021-06-20 op
743 2b2d2872 2021-06-20 op void
744 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
745 2b2d2872 2021-06-20 op {
746 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
747 2b2d2872 2021-06-20 op message("No history");
748 2b2d2872 2021-06-20 op return;
749 2b2d2872 2021-06-20 op }
750 2b2d2872 2021-06-20 op
751 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
752 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
753 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
754 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
755 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
756 fc14510d 2021-07-14 op message("No prev history item");
757 2b2d2872 2021-06-20 op } else {
758 2b2d2872 2021-06-20 op ministate.hist_off--;
759 2b2d2872 2021-06-20 op }
760 2b2d2872 2021-06-20 op
761 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
762 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
763 2b2d2872 2021-06-20 op }
764 2b2d2872 2021-06-20 op
765 2b2d2872 2021-06-20 op void
766 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
767 2b2d2872 2021-06-20 op {
768 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
769 2b2d2872 2021-06-20 op message("No history");
770 2b2d2872 2021-06-20 op return;
771 2b2d2872 2021-06-20 op }
772 2b2d2872 2021-06-20 op
773 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
774 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
775 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
776 2b2d2872 2021-06-20 op ministate.hist_off = 0;
777 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
778 fc14510d 2021-07-14 op message("No next history item");
779 2b2d2872 2021-06-20 op } else {
780 2b2d2872 2021-06-20 op ministate.hist_off++;
781 2b2d2872 2021-06-20 op }
782 2b2d2872 2021-06-20 op
783 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
784 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
785 2b2d2872 2021-06-20 op }
786 e7b982f4 2021-07-14 op
787 e7b982f4 2021-07-14 op void
788 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
789 e7b982f4 2021-07-14 op {
790 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
791 e7b982f4 2021-07-14 op return;
792 e7b982f4 2021-07-14 op
793 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
794 e7b982f4 2021-07-14 op
795 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
796 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
797 e7b982f4 2021-07-14 op
798 e7b982f4 2021-07-14 op forward_line(buffer, -1);
799 e7b982f4 2021-07-14 op
800 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
801 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
802 e7b982f4 2021-07-14 op }
803 e7b982f4 2021-07-14 op
804 e7b982f4 2021-07-14 op void
805 e7b982f4 2021-07-14 op cmd_next_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_insert_current_candidate(struct buffer *buffer)
823 e7b982f4 2021-07-14 op {
824 e7b982f4 2021-07-14 op struct vline *vl;
825 e7b982f4 2021-07-14 op
826 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
827 e7b982f4 2021-07-14 op return;
828 e7b982f4 2021-07-14 op
829 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
830 e7b982f4 2021-07-14 op if ((vl = buffer->current_line) == NULL)
831 e7b982f4 2021-07-14 op return;
832 e7b982f4 2021-07-14 op
833 e7b982f4 2021-07-14 op minibuffer_taint_hist();
834 e7b982f4 2021-07-14 op strlcpy(ministate.buf, vl->parent->line, sizeof(ministate.buf));
835 e7b982f4 2021-07-14 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
836 e7b982f4 2021-07-14 op }
837 8a3b5609 2021-07-15 op
838 8a3b5609 2021-07-15 op void
839 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
840 8a3b5609 2021-07-15 op {
841 8a3b5609 2021-07-15 op message("Zzz...");
842 8a3b5609 2021-07-15 op ui_suspend();
843 8a3b5609 2021-07-15 op }
844 987d9c88 2021-07-15 op
845 987d9c88 2021-07-15 op void
846 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
847 987d9c88 2021-07-15 op {
848 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
849 987d9c88 2021-07-15 op
850 987d9c88 2021-07-15 op if (dont_wrap_pre)
851 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
852 987d9c88 2021-07-15 op else
853 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
854 987d9c88 2021-07-15 op
855 987d9c88 2021-07-15 op ui_schedule_redraw();
856 987d9c88 2021-07-15 op }
857 de190a2b 2021-07-17 op
858 de190a2b 2021-07-17 op void
859 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
860 de190a2b 2021-07-17 op {
861 de190a2b 2021-07-17 op struct vline *vl;
862 de190a2b 2021-07-17 op
863 de190a2b 2021-07-17 op if (!in_minibuffer)
864 de190a2b 2021-07-17 op return;
865 de190a2b 2021-07-17 op
866 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
867 de190a2b 2021-07-17 op
868 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
869 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
870 de190a2b 2021-07-17 op
871 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
872 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
873 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
874 de190a2b 2021-07-17 op
875 de190a2b 2021-07-17 op if (vl == NULL)
876 de190a2b 2021-07-17 op return;
877 de190a2b 2021-07-17 op
878 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
879 de190a2b 2021-07-17 op buffer->top_line = vl;
880 de190a2b 2021-07-17 op buffer->current_line = vl;
881 de190a2b 2021-07-17 op }
882 de190a2b 2021-07-17 op
883 de190a2b 2021-07-17 op void
884 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
885 de190a2b 2021-07-17 op {
886 de190a2b 2021-07-17 op struct vline *vl;
887 de190a2b 2021-07-17 op
888 de190a2b 2021-07-17 op if (!in_minibuffer)
889 de190a2b 2021-07-17 op return;
890 de190a2b 2021-07-17 op
891 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
892 de190a2b 2021-07-17 op
893 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
894 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
895 de190a2b 2021-07-17 op
896 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
897 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
898 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
899 de190a2b 2021-07-17 op
900 de190a2b 2021-07-17 op if (vl == NULL)
901 de190a2b 2021-07-17 op return;
902 de190a2b 2021-07-17 op
903 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
904 de190a2b 2021-07-17 op buffer->current_line = vl;
905 de190a2b 2021-07-17 op }