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