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