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