Blame


1 2b2d2872 2021-06-20 op /*
2 a36bb43a 2024-01-15 op * Copyright (c) 2021, 2024 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 4fdc9933 2024-02-05 op #include "certs.h"
24 d252d87c 2024-02-05 op #include "cmd.h"
25 b1e1e41a 2021-07-14 op #include "compl.h"
26 e5a2797f 2021-07-13 op #include "defaults.h"
27 65c49665 2024-01-23 op #include "hist.h"
28 f7db6d13 2024-02-06 op #include "keymap.h"
29 eeebca22 2022-01-11 op #include "mcache.h"
30 450a89f7 2021-07-12 op #include "minibuffer.h"
31 1fce2e75 2021-08-14 op #include "session.h"
32 2b2d2872 2021-06-20 op #include "telescope.h"
33 d1a0f2a3 2021-07-12 op #include "ui.h"
34 5caf7d67 2021-07-12 op #include "utf8.h"
35 c8c572e4 2022-02-08 op #include "utils.h"
36 2b2d2872 2021-06-20 op
37 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
38 ca231710 2021-07-15 op do { \
39 ca231710 2021-07-15 op if (in_minibuffer) { \
40 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
41 ca231710 2021-07-15 op "is not yet available."); \
42 ca231710 2021-07-15 op return; \
43 ca231710 2021-07-15 op } \
44 ca231710 2021-07-15 op } while(0)
45 ca231710 2021-07-15 op
46 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
47 5a3c3ede 2021-07-19 op do { \
48 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
49 5a3c3ede 2021-07-19 op message("text is read-only"); \
50 5a3c3ede 2021-07-19 op return; \
51 5a3c3ede 2021-07-19 op } \
52 5a3c3ede 2021-07-19 op } while(0)
53 5a3c3ede 2021-07-19 op
54 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
55 c4c82003 2021-07-01 op static inline int
56 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
57 2b2d2872 2021-06-20 op {
58 c4c82003 2021-07-01 op struct vline *vl;
59 c4c82003 2021-07-01 op int did;
60 2b2d2872 2021-06-20 op
61 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
62 c4c82003 2021-07-01 op return 0;
63 963c680c 2021-07-05 op vl = buffer->current_line;
64 2b2d2872 2021-06-20 op
65 c4c82003 2021-07-01 op did = 0;
66 c4c82003 2021-07-01 op while (n != 0) {
67 c4c82003 2021-07-01 op if (n > 0) {
68 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
69 c4c82003 2021-07-01 op if (vl == NULL)
70 c4c82003 2021-07-01 op return did;
71 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
72 963c680c 2021-07-05 op continue;
73 c4c82003 2021-07-01 op buffer->current_line = vl;
74 c4c82003 2021-07-01 op n--;
75 c4c82003 2021-07-01 op } else {
76 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
77 c4c82003 2021-07-01 op if (vl == NULL)
78 c4c82003 2021-07-01 op return did;
79 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
80 963c680c 2021-07-05 op continue;
81 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
82 6e6c6afb 2021-07-14 op buffer->line_off--;
83 c4c82003 2021-07-01 op buffer->top_line = vl;
84 6e6c6afb 2021-07-14 op }
85 c4c82003 2021-07-01 op buffer->current_line = vl;
86 c4c82003 2021-07-01 op n++;
87 c4c82003 2021-07-01 op }
88 c4c82003 2021-07-01 op
89 c4c82003 2021-07-01 op did = 1;
90 2b2d2872 2021-06-20 op }
91 2b2d2872 2021-06-20 op
92 c4c82003 2021-07-01 op return did;
93 2b2d2872 2021-06-20 op }
94 2b2d2872 2021-06-20 op
95 2b2d2872 2021-06-20 op void
96 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
97 2b2d2872 2021-06-20 op {
98 c4c82003 2021-07-01 op forward_line(buffer, -1);
99 c4c82003 2021-07-01 op }
100 2b2d2872 2021-06-20 op
101 c4c82003 2021-07-01 op void
102 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
103 c4c82003 2021-07-01 op {
104 c4c82003 2021-07-01 op forward_line(buffer, +1);
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_backward_char(struct buffer *buffer)
109 2b2d2872 2021-06-20 op {
110 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
111 2b2d2872 2021-06-20 op buffer->cpoff--;
112 2b2d2872 2021-06-20 op }
113 2b2d2872 2021-06-20 op
114 2b2d2872 2021-06-20 op void
115 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
116 2b2d2872 2021-06-20 op {
117 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
118 aed6fae9 2021-07-19 op return;
119 bd4a08a7 2022-11-07 op if (buffer->current_line->cplen > buffer->cpoff)
120 bd4a08a7 2022-11-07 op buffer->cpoff++;
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 bd4a08a7 2022-11-07 op } while (buffer->current_line->len != 0 ||
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 bd4a08a7 2022-11-07 op } while (buffer->current_line->len != 0 ||
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 bd4a08a7 2022-11-07 op if (vl == NULL)
160 2b2d2872 2021-06-20 op return;
161 bd4a08a7 2022-11-07 op buffer->cpoff = vl->cplen;
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 65c49665 2024-01-23 op new_tab(vl->parent->alt, hist_cur(current_tab->hist), 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 65c49665 2024-01-23 op eecmd_history, compl_eecmd, NULL, 1);
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 27dbcaab 2022-04-13 op NULL, compl_ts, NULL, 1);
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 65c49665 2024-01-23 op lu_history, compl_lu, NULL, 0);
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 65c49665 2024-01-23 op lu_history, compl_lu, NULL, 0);
578 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
579 65c49665 2024-01-23 op strlcpy(ministate.buf, hist_cur(current_tab->hist), 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 65c49665 2024-01-23 op load_url_in_tab(current_tab, hist_cur(current_tab->hist), 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 27dbcaab 2022-04-13 op NULL, NULL, 0);
597 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
598 65c49665 2024-01-23 op strlcpy(ministate.buf, hist_cur(current_tab->hist),
599 65c49665 2024-01-23 op sizeof(ministate.buf));
600 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
601 2b2d2872 2021-06-20 op }
602 2b2d2872 2021-06-20 op
603 2b2d2872 2021-06-20 op void
604 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
605 2b2d2872 2021-06-20 op {
606 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
607 2b2d2872 2021-06-20 op }
608 2b2d2872 2021-06-20 op
609 2b2d2872 2021-06-20 op void
610 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
611 2b2d2872 2021-06-20 op {
612 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
613 753c6ac7 2021-07-14 op }
614 753c6ac7 2021-07-14 op
615 753c6ac7 2021-07-14 op void
616 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
617 753c6ac7 2021-07-14 op {
618 c1a72389 2021-07-15 op struct line *l;
619 c1a72389 2021-07-15 op
620 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
621 753c6ac7 2021-07-14 op
622 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
623 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
624 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
625 c1a72389 2021-07-15 op
626 c1a72389 2021-07-15 op if (l == NULL) {
627 c1a72389 2021-07-15 op message("No links found");
628 c1a72389 2021-07-15 op return;
629 c1a72389 2021-07-15 op }
630 c1a72389 2021-07-15 op
631 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
632 27dbcaab 2022-04-13 op NULL, compl_ls, l, 1);
633 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
634 753c6ac7 2021-07-14 op }
635 753c6ac7 2021-07-14 op
636 753c6ac7 2021-07-14 op void
637 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
638 753c6ac7 2021-07-14 op {
639 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
640 753c6ac7 2021-07-14 op
641 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
642 27dbcaab 2022-04-13 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head), 1);
643 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
644 edd9a650 2021-07-15 op }
645 edd9a650 2021-07-15 op
646 edd9a650 2021-07-15 op void
647 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
648 edd9a650 2021-07-15 op {
649 c1a72389 2021-07-15 op struct line *l;
650 c1a72389 2021-07-15 op
651 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
652 edd9a650 2021-07-15 op
653 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
654 c1a72389 2021-07-15 op while (l != NULL &&
655 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
656 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
657 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
658 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
659 c1a72389 2021-07-15 op
660 c1a72389 2021-07-15 op if (l == NULL) {
661 c1a72389 2021-07-15 op message("No headings found");
662 c1a72389 2021-07-15 op return;
663 c1a72389 2021-07-15 op }
664 c1a72389 2021-07-15 op
665 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
666 27dbcaab 2022-04-13 op NULL, compl_toc, l, 1);
667 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
668 edd9a650 2021-07-15 op sizeof(ministate.prompt));
669 2b2d2872 2021-06-20 op }
670 2b2d2872 2021-06-20 op
671 2b2d2872 2021-06-20 op void
672 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
673 61251035 2021-06-26 op {
674 61251035 2021-06-26 op if (fill_column == INT_MAX)
675 61251035 2021-06-26 op return;
676 61251035 2021-06-26 op
677 61251035 2021-06-26 op fill_column += 2;
678 61251035 2021-06-26 op message("fill-column: %d", fill_column);
679 61251035 2021-06-26 op
680 61251035 2021-06-26 op ui_schedule_redraw();
681 61251035 2021-06-26 op }
682 61251035 2021-06-26 op
683 61251035 2021-06-26 op void
684 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
685 61251035 2021-06-26 op {
686 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
687 61251035 2021-06-26 op return;
688 61251035 2021-06-26 op
689 61251035 2021-06-26 op fill_column -= 2;
690 61251035 2021-06-26 op message("fill-column: %d", fill_column);
691 61251035 2021-06-26 op
692 61251035 2021-06-26 op ui_schedule_redraw();
693 61251035 2021-06-26 op }
694 61251035 2021-06-26 op
695 61251035 2021-06-26 op void
696 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
697 2b2d2872 2021-06-20 op {
698 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
699 2b2d2872 2021-06-20 op if (olivetti_mode)
700 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
701 2b2d2872 2021-06-20 op else
702 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
703 2b2d2872 2021-06-20 op
704 2b2d2872 2021-06-20 op ui_schedule_redraw();
705 2b2d2872 2021-06-20 op }
706 2b2d2872 2021-06-20 op
707 2b2d2872 2021-06-20 op void
708 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
709 2b2d2872 2021-06-20 op {
710 bd4a08a7 2022-11-07 op char *line, *c, *n;
711 2b2d2872 2021-06-20 op
712 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
713 2b2d2872 2021-06-20 op
714 2b2d2872 2021-06-20 op minibuffer_taint_hist();
715 2b2d2872 2021-06-20 op
716 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
717 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
718 2b2d2872 2021-06-20 op if (*c == '\0')
719 2b2d2872 2021-06-20 op return;
720 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
721 2b2d2872 2021-06-20 op
722 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
723 b1e1e41a 2021-07-14 op
724 b1e1e41a 2021-07-14 op recompute_completions(0);
725 2b2d2872 2021-06-20 op }
726 2b2d2872 2021-06-20 op
727 2b2d2872 2021-06-20 op void
728 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
729 2b2d2872 2021-06-20 op {
730 bd4a08a7 2022-11-07 op char *line, *c, *p;
731 2b2d2872 2021-06-20 op
732 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
733 2b2d2872 2021-06-20 op
734 2b2d2872 2021-06-20 op minibuffer_taint_hist();
735 2b2d2872 2021-06-20 op
736 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
737 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
738 bd4a08a7 2022-11-07 op if (c == line)
739 2b2d2872 2021-06-20 op return;
740 bd4a08a7 2022-11-07 op p = utf8_prev_cp(c-1, line);
741 2b2d2872 2021-06-20 op
742 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
743 2b2d2872 2021-06-20 op buffer->cpoff--;
744 b1e1e41a 2021-07-14 op
745 b1e1e41a 2021-07-14 op recompute_completions(0);
746 2b2d2872 2021-06-20 op }
747 2b2d2872 2021-06-20 op
748 2b2d2872 2021-06-20 op void
749 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
750 2b2d2872 2021-06-20 op {
751 bd4a08a7 2022-11-07 op char *line, *c;
752 2b2d2872 2021-06-20 op
753 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
754 2b2d2872 2021-06-20 op
755 2b2d2872 2021-06-20 op minibuffer_taint_hist();
756 bd4a08a7 2022-11-07 op
757 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
758 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
759 2b2d2872 2021-06-20 op *c = '\0';
760 b1e1e41a 2021-07-14 op
761 b1e1e41a 2021-07-14 op recompute_completions(0);
762 067b7ffd 2022-04-15 op }
763 067b7ffd 2022-04-15 op
764 067b7ffd 2022-04-15 op void
765 067b7ffd 2022-04-15 op cmd_mini_kill_whole_line(struct buffer *buffer)
766 067b7ffd 2022-04-15 op {
767 067b7ffd 2022-04-15 op GUARD_READ_ONLY();
768 067b7ffd 2022-04-15 op
769 067b7ffd 2022-04-15 op minibuffer_taint_hist();
770 bd4a08a7 2022-11-07 op *buffer->current_line->parent->line = '\0';
771 067b7ffd 2022-04-15 op buffer->cpoff = 0;
772 2b2d2872 2021-06-20 op }
773 2b2d2872 2021-06-20 op
774 2b2d2872 2021-06-20 op void
775 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
776 2b2d2872 2021-06-20 op {
777 2b2d2872 2021-06-20 op if (!in_minibuffer)
778 2b2d2872 2021-06-20 op return;
779 2b2d2872 2021-06-20 op
780 2b2d2872 2021-06-20 op ministate.abortfn();
781 2b2d2872 2021-06-20 op }
782 2b2d2872 2021-06-20 op
783 2b2d2872 2021-06-20 op void
784 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
785 2b2d2872 2021-06-20 op {
786 27dbcaab 2022-04-13 op struct vline *vl;
787 27dbcaab 2022-04-13 op
788 2b2d2872 2021-06-20 op if (!in_minibuffer)
789 2b2d2872 2021-06-20 op return;
790 2b2d2872 2021-06-20 op
791 65c49665 2024-01-23 op if (ministate.compl.must_select && ministate.hist == NULL) {
792 27dbcaab 2022-04-13 op vl = ministate.compl.buffer.current_line;
793 27dbcaab 2022-04-13 op if (vl == NULL || vl->parent->flags & L_HIDDEN ||
794 27dbcaab 2022-04-13 op vl->parent->type == LINE_COMPL) {
795 27dbcaab 2022-04-13 op message("no match");
796 27dbcaab 2022-04-13 op return;
797 27dbcaab 2022-04-13 op }
798 27dbcaab 2022-04-13 op }
799 27dbcaab 2022-04-13 op
800 2b2d2872 2021-06-20 op minibuffer_taint_hist();
801 2b2d2872 2021-06-20 op ministate.donefn();
802 2b2d2872 2021-06-20 op }
803 2b2d2872 2021-06-20 op
804 2b2d2872 2021-06-20 op void
805 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
806 2b2d2872 2021-06-20 op {
807 65c49665 2024-01-23 op char *text;
808 65c49665 2024-01-23 op
809 65c49665 2024-01-23 op if (ministate.hist == NULL) {
810 2b2d2872 2021-06-20 op message("No history");
811 2b2d2872 2021-06-20 op return;
812 2b2d2872 2021-06-20 op }
813 2b2d2872 2021-06-20 op
814 65c49665 2024-01-23 op if (hist_prev(ministate.hist) == NULL) {
815 65c49665 2024-01-23 op message("No prev history item");
816 65c49665 2024-01-23 op return;
817 2b2d2872 2021-06-20 op }
818 2b2d2872 2021-06-20 op
819 65c49665 2024-01-23 op ministate.editing = 0;
820 65c49665 2024-01-23 op
821 65c49665 2024-01-23 op /* XXX the minibuffer line is never modified so this is fine */
822 65c49665 2024-01-23 op text = (char *)hist_cur(ministate.hist);
823 65c49665 2024-01-23 op buffer->current_line->parent->line = text;
824 65c49665 2024-01-23 op recompute_completions(0);
825 2b2d2872 2021-06-20 op }
826 2b2d2872 2021-06-20 op
827 2b2d2872 2021-06-20 op void
828 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
829 2b2d2872 2021-06-20 op {
830 65c49665 2024-01-23 op char *text;
831 65c49665 2024-01-23 op
832 65c49665 2024-01-23 op if (ministate.hist == NULL) {
833 2b2d2872 2021-06-20 op message("No history");
834 2b2d2872 2021-06-20 op return;
835 2b2d2872 2021-06-20 op }
836 2b2d2872 2021-06-20 op
837 65c49665 2024-01-23 op if (hist_next(ministate.hist) == NULL) {
838 65c49665 2024-01-23 op message("No next history item");
839 65c49665 2024-01-23 op return;
840 2b2d2872 2021-06-20 op }
841 2b2d2872 2021-06-20 op
842 65c49665 2024-01-23 op ministate.editing = 0;
843 65c49665 2024-01-23 op
844 65c49665 2024-01-23 op /* XXX the minibuffer line is never modified so this is fine */
845 65c49665 2024-01-23 op text = (char *)hist_cur(ministate.hist);
846 65c49665 2024-01-23 op buffer->current_line->parent->line = text;
847 65c49665 2024-01-23 op recompute_completions(0);
848 2b2d2872 2021-06-20 op }
849 e7b982f4 2021-07-14 op
850 e7b982f4 2021-07-14 op void
851 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
852 e7b982f4 2021-07-14 op {
853 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
854 e7b982f4 2021-07-14 op return;
855 e7b982f4 2021-07-14 op
856 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
857 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
858 fea02b0b 2022-04-13 op return;
859 e7b982f4 2021-07-14 op
860 fea02b0b 2022-04-13 op buffer->current_line->parent->type = LINE_COMPL;
861 fea02b0b 2022-04-13 op if (!forward_line(buffer, -1))
862 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
863 fea02b0b 2022-04-13 op else
864 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
865 e7b982f4 2021-07-14 op }
866 e7b982f4 2021-07-14 op
867 e7b982f4 2021-07-14 op void
868 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
869 e7b982f4 2021-07-14 op {
870 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
871 e7b982f4 2021-07-14 op return;
872 e7b982f4 2021-07-14 op
873 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
874 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
875 fea02b0b 2022-04-13 op return;
876 e7b982f4 2021-07-14 op
877 fea02b0b 2022-04-13 op if (buffer->current_line->parent->type == LINE_COMPL_CURRENT) {
878 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
879 fea02b0b 2022-04-13 op forward_line(buffer, +1);
880 fea02b0b 2022-04-13 op }
881 e7b982f4 2021-07-14 op
882 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
883 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
884 e7b982f4 2021-07-14 op }
885 e7b982f4 2021-07-14 op
886 e7b982f4 2021-07-14 op void
887 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
888 e7b982f4 2021-07-14 op {
889 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
890 e7b982f4 2021-07-14 op return;
891 e7b982f4 2021-07-14 op
892 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
893 e7b982f4 2021-07-14 op }
894 8a3b5609 2021-07-15 op
895 8a3b5609 2021-07-15 op void
896 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
897 8a3b5609 2021-07-15 op {
898 8a3b5609 2021-07-15 op message("Zzz...");
899 8a3b5609 2021-07-15 op ui_suspend();
900 8a3b5609 2021-07-15 op }
901 987d9c88 2021-07-15 op
902 987d9c88 2021-07-15 op void
903 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
904 987d9c88 2021-07-15 op {
905 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
906 987d9c88 2021-07-15 op
907 987d9c88 2021-07-15 op if (dont_wrap_pre)
908 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
909 987d9c88 2021-07-15 op else
910 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
911 987d9c88 2021-07-15 op
912 987d9c88 2021-07-15 op ui_schedule_redraw();
913 987d9c88 2021-07-15 op }
914 de190a2b 2021-07-17 op
915 de190a2b 2021-07-17 op void
916 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
917 de190a2b 2021-07-17 op {
918 de190a2b 2021-07-17 op struct vline *vl;
919 de190a2b 2021-07-17 op
920 de190a2b 2021-07-17 op if (!in_minibuffer)
921 de190a2b 2021-07-17 op return;
922 de190a2b 2021-07-17 op
923 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
924 de190a2b 2021-07-17 op
925 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
926 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
927 de190a2b 2021-07-17 op
928 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
929 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
930 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
931 de190a2b 2021-07-17 op
932 de190a2b 2021-07-17 op if (vl == NULL)
933 de190a2b 2021-07-17 op return;
934 de190a2b 2021-07-17 op
935 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
936 de190a2b 2021-07-17 op buffer->top_line = vl;
937 de190a2b 2021-07-17 op buffer->current_line = vl;
938 de190a2b 2021-07-17 op }
939 de190a2b 2021-07-17 op
940 de190a2b 2021-07-17 op void
941 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
942 de190a2b 2021-07-17 op {
943 de190a2b 2021-07-17 op struct vline *vl;
944 de190a2b 2021-07-17 op
945 de190a2b 2021-07-17 op if (!in_minibuffer)
946 de190a2b 2021-07-17 op return;
947 de190a2b 2021-07-17 op
948 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
949 de190a2b 2021-07-17 op
950 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
951 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
952 de190a2b 2021-07-17 op
953 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
954 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
955 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
956 de190a2b 2021-07-17 op
957 de190a2b 2021-07-17 op if (vl == NULL)
958 de190a2b 2021-07-17 op return;
959 de190a2b 2021-07-17 op
960 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
961 de190a2b 2021-07-17 op buffer->current_line = vl;
962 65340174 2021-07-21 op }
963 65340174 2021-07-21 op
964 65340174 2021-07-21 op void
965 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
966 65340174 2021-07-21 op {
967 65340174 2021-07-21 op ui_other_window();
968 167131d5 2021-07-24 op }
969 167131d5 2021-07-24 op
970 167131d5 2021-07-24 op void
971 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
972 167131d5 2021-07-24 op {
973 167131d5 2021-07-24 op if (!in_minibuffer)
974 167131d5 2021-07-24 op return;
975 167131d5 2021-07-24 op
976 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
977 167131d5 2021-07-24 op if (buffer->current_line == NULL)
978 167131d5 2021-07-24 op return;
979 167131d5 2021-07-24 op
980 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
981 167131d5 2021-07-24 op cmd_scroll_up(buffer);
982 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
983 167131d5 2021-07-24 op }
984 167131d5 2021-07-24 op
985 167131d5 2021-07-24 op void
986 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
987 167131d5 2021-07-24 op {
988 167131d5 2021-07-24 op if (!in_minibuffer)
989 167131d5 2021-07-24 op return;
990 167131d5 2021-07-24 op
991 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
992 167131d5 2021-07-24 op if (buffer->current_line == NULL)
993 167131d5 2021-07-24 op return;
994 167131d5 2021-07-24 op
995 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
996 167131d5 2021-07-24 op cmd_scroll_down(buffer);
997 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
998 3b5f459e 2021-11-05 op }
999 3b5f459e 2021-11-05 op
1000 3b5f459e 2021-11-05 op void
1001 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
1002 3b5f459e 2021-11-05 op {
1003 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1004 de190a2b 2021-07-17 op }
1005 eeebca22 2022-01-11 op
1006 eeebca22 2022-01-11 op void
1007 eeebca22 2022-01-11 op cmd_cache_info(struct buffer *buffer)
1008 eeebca22 2022-01-11 op {
1009 eeebca22 2022-01-11 op size_t npages, tot;
1010 eeebca22 2022-01-11 op char fmt[FMT_SCALED_STRSIZE];
1011 eeebca22 2022-01-11 op
1012 eeebca22 2022-01-11 op mcache_info(&npages, &tot);
1013 eeebca22 2022-01-11 op
1014 eeebca22 2022-01-11 op if (fmt_scaled(tot, fmt) == 0)
1015 bb5abe9f 2022-01-13 op message("pages: %zu, total: %s", npages, fmt);
1016 eeebca22 2022-01-11 op else
1017 bb5abe9f 2022-01-13 op message("pages: %zu, total: %zu", npages, tot);
1018 ed504b9e 2022-02-07 op }
1019 ed504b9e 2022-02-07 op
1020 ed504b9e 2022-02-07 op void
1021 ed504b9e 2022-02-07 op cmd_reply_last_input(struct buffer *buffer)
1022 ed504b9e 2022-02-07 op {
1023 ed504b9e 2022-02-07 op GUARD_RECURSIVE_MINIBUFFER();
1024 ed504b9e 2022-02-07 op
1025 ed504b9e 2022-02-07 op if (current_tab->last_input_url == NULL) {
1026 ed504b9e 2022-02-07 op message("there was no previous input request in this tab");
1027 acf9defe 2022-02-08 op return;
1028 acf9defe 2022-02-08 op }
1029 acf9defe 2022-02-08 op
1030 d89eb764 2022-04-24 op if (!strncmp(current_tab->last_input_url, "gopher", 6)) {
1031 acf9defe 2022-02-08 op load_url_in_tab(current_tab, current_tab->last_input_url,
1032 acf9defe 2022-02-08 op NULL, LU_MODE_NOCACHE);
1033 ed504b9e 2022-02-07 op return;
1034 ed504b9e 2022-02-07 op }
1035 ed504b9e 2022-02-07 op
1036 ed504b9e 2022-02-07 op message("%s", current_tab->last_input_url);
1037 ed504b9e 2022-02-07 op ui_require_input(current_tab, 0, ir_select_reply);
1038 eeebca22 2022-01-11 op }
1039 868b3a8f 2022-04-13 op
1040 868b3a8f 2022-04-13 op void
1041 868b3a8f 2022-04-13 op cmd_write_buffer(struct buffer *buffer)
1042 868b3a8f 2022-04-13 op {
1043 868b3a8f 2022-04-13 op const char *f, *url;
1044 868b3a8f 2022-04-13 op char path[PATH_MAX];
1045 868b3a8f 2022-04-13 op
1046 868b3a8f 2022-04-13 op GUARD_RECURSIVE_MINIBUFFER();
1047 868b3a8f 2022-04-13 op
1048 868b3a8f 2022-04-13 op if (safe_mode) {
1049 868b3a8f 2022-04-13 op message("Can't write buffer in safe-mode.");
1050 868b3a8f 2022-04-13 op return;
1051 868b3a8f 2022-04-13 op }
1052 868b3a8f 2022-04-13 op
1053 65c49665 2024-01-23 op url = hist_cur(current_tab->hist);
1054 868b3a8f 2022-04-13 op
1055 868b3a8f 2022-04-13 op if ((f = strrchr(url, '/')) != NULL)
1056 868b3a8f 2022-04-13 op f++;
1057 868b3a8f 2022-04-13 op if (f == NULL || *f == '\0') {
1058 868b3a8f 2022-04-13 op /* guess a decent file name based on the protocol used */
1059 868b3a8f 2022-04-13 op if (!strncmp(url, "gemini://", 9))
1060 868b3a8f 2022-04-13 op f = "index.gmi";
1061 868b3a8f 2022-04-13 op else
1062 868b3a8f 2022-04-13 op f = "index.txt";
1063 868b3a8f 2022-04-13 op }
1064 868b3a8f 2022-04-13 op
1065 868b3a8f 2022-04-13 op strlcpy(path, download_path, sizeof(path));
1066 868b3a8f 2022-04-13 op strlcat(path, f, sizeof(path));
1067 868b3a8f 2022-04-13 op
1068 868b3a8f 2022-04-13 op ui_read("Write file", write_buffer, current_tab, path);
1069 a36bb43a 2024-01-15 op }
1070 a36bb43a 2024-01-15 op
1071 a36bb43a 2024-01-15 op void
1072 a36bb43a 2024-01-15 op cmd_home(struct buffer *buffer)
1073 a36bb43a 2024-01-15 op {
1074 86294a09 2024-01-16 op char path[GEMINI_URL_LEN];
1075 86294a09 2024-01-16 op char *tilde, *t;
1076 86294a09 2024-01-16 op
1077 86294a09 2024-01-16 op strlcpy(path, current_tab->iri.iri_path, sizeof(path));
1078 86294a09 2024-01-16 op
1079 a526f3eb 2024-02-02 op if ((tilde = strstr(path, "/~")) != NULL &&
1080 a526f3eb 2024-02-02 op tilde[2] != '\0' && tilde[2] != '/') {
1081 a526f3eb 2024-02-02 op if ((t = strchr(tilde + 2, '/')) != NULL)
1082 86294a09 2024-01-16 op *++t = '\0';
1083 65c49665 2024-01-23 op load_url_in_tab(current_tab, path, NULL, LU_MODE_NOCACHE);
1084 86294a09 2024-01-16 op } else
1085 86294a09 2024-01-16 op cmd_root(buffer);
1086 a36bb43a 2024-01-15 op }
1087 a36bb43a 2024-01-15 op
1088 a36bb43a 2024-01-15 op void
1089 a36bb43a 2024-01-15 op cmd_root(struct buffer *buffer)
1090 a36bb43a 2024-01-15 op {
1091 65c49665 2024-01-23 op load_url_in_tab(current_tab, "/", NULL, LU_MODE_NOCACHE);
1092 868b3a8f 2022-04-13 op }
1093 a36bb43a 2024-01-15 op
1094 a36bb43a 2024-01-15 op void
1095 a36bb43a 2024-01-15 op cmd_up(struct buffer *buffer)
1096 a36bb43a 2024-01-15 op {
1097 65c49665 2024-01-23 op load_url_in_tab(current_tab, "..", NULL, LU_MODE_NOCACHE);
1098 a36bb43a 2024-01-15 op }
1099 5a39f593 2024-02-05 op
1100 5a39f593 2024-02-05 op void
1101 5a39f593 2024-02-05 op cmd_use_certificate(struct buffer *buffer)
1102 5a39f593 2024-02-05 op {
1103 5a39f593 2024-02-05 op GUARD_RECURSIVE_MINIBUFFER();
1104 5a39f593 2024-02-05 op
1105 5a39f593 2024-02-05 op enter_minibuffer(sensible_self_insert, uc_select, exit_minibuffer,
1106 5a39f593 2024-02-05 op NULL, compl_uc, NULL, 1);
1107 5a39f593 2024-02-05 op strlcpy(ministate.prompt, "Select certificate: ",
1108 5a39f593 2024-02-05 op sizeof(ministate.prompt));
1109 5a39f593 2024-02-05 op }
1110 4655add6 2024-02-05 op
1111 4655add6 2024-02-05 op void
1112 4655add6 2024-02-05 op cmd_client_certificate_info(struct buffer *buffer)
1113 4655add6 2024-02-05 op {
1114 4655add6 2024-02-05 op if (current_tab->client_cert)
1115 4655add6 2024-02-05 op message("Using certificate %s", current_tab->client_cert);
1116 4655add6 2024-02-05 op else
1117 4655add6 2024-02-05 op message("Not using any client certificate.");
1118 4fdc9933 2024-02-05 op }
1119 4fdc9933 2024-02-05 op
1120 4fdc9933 2024-02-05 op static void
1121 4fdc9933 2024-02-05 op unload_certificate_cb(int r, struct tab *tab)
1122 4fdc9933 2024-02-05 op {
1123 71bc1636 2024-02-06 op message("Won't use %s for this site.", tab->client_cert);
1124 4fdc9933 2024-02-05 op cert_delete_for(tab->client_cert, &tab->iri, r);
1125 4fdc9933 2024-02-05 op }
1126 4fdc9933 2024-02-05 op
1127 4fdc9933 2024-02-05 op void
1128 4fdc9933 2024-02-05 op cmd_unload_certificate(struct buffer *buffer)
1129 4fdc9933 2024-02-05 op {
1130 71bc1636 2024-02-06 op struct tab *tab = current_tab;
1131 71bc1636 2024-02-06 op
1132 4fdc9933 2024-02-05 op GUARD_RECURSIVE_MINIBUFFER();
1133 4fdc9933 2024-02-05 op
1134 71bc1636 2024-02-06 op if (tab->client_cert == NULL) {
1135 4fdc9933 2024-02-05 op message("No client certificate in use!");
1136 4fdc9933 2024-02-05 op return;
1137 4fdc9933 2024-02-05 op }
1138 4fdc9933 2024-02-05 op
1139 71bc1636 2024-02-06 op if (tab->client_cert_temp) {
1140 71bc1636 2024-02-06 op message("Won't use %s for this site.", tab->client_cert);
1141 71bc1636 2024-02-06 op cert_delete_for(tab->client_cert, &tab->iri, 0);
1142 71bc1636 2024-02-06 op return;
1143 71bc1636 2024-02-06 op }
1144 71bc1636 2024-02-06 op
1145 4fdc9933 2024-02-05 op yornp("Unload only for the current session?", unload_certificate_cb,
1146 4fdc9933 2024-02-05 op current_tab);
1147 fd6c540b 2024-02-12 op }
1148 fd6c540b 2024-02-12 op
1149 fd6c540b 2024-02-12 op void
1150 fd6c540b 2024-02-12 op cmd_search(struct buffer *buffer)
1151 fd6c540b 2024-02-12 op {
1152 fd6c540b 2024-02-12 op GUARD_RECURSIVE_MINIBUFFER();
1153 50fd8b26 2024-02-12 op
1154 50fd8b26 2024-02-12 op if (!strncmp(default_search_engine, "gopher://", 9)) {
1155 50fd8b26 2024-02-12 op load_url_in_tab(current_tab, default_search_engine, NULL,
1156 50fd8b26 2024-02-12 op LU_MODE_NOCACHE);
1157 50fd8b26 2024-02-12 op return;
1158 50fd8b26 2024-02-12 op }
1159 fd6c540b 2024-02-12 op
1160 fd6c540b 2024-02-12 op enter_minibuffer(sensible_self_insert, search_select, exit_minibuffer, NULL,
1161 fd6c540b 2024-02-12 op NULL, NULL, 0);
1162 fd6c540b 2024-02-12 op strlcpy(ministate.prompt, "Search: ", sizeof(ministate.prompt));
1163 4655add6 2024-02-05 op }