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