Blame


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