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