Blame


1 2b2d2872 2021-06-20 op /*
2 2b2d2872 2021-06-20 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 2b2d2872 2021-06-20 op *
4 2b2d2872 2021-06-20 op * Permission to use, copy, modify, and distribute this software for any
5 2b2d2872 2021-06-20 op * purpose with or without fee is hereby granted, provided that the above
6 2b2d2872 2021-06-20 op * copyright notice and this permission notice appear in all copies.
7 2b2d2872 2021-06-20 op *
8 2b2d2872 2021-06-20 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 2b2d2872 2021-06-20 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 2b2d2872 2021-06-20 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 2b2d2872 2021-06-20 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 2b2d2872 2021-06-20 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 2b2d2872 2021-06-20 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 2b2d2872 2021-06-20 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 2b2d2872 2021-06-20 op */
16 786e6deb 2021-07-21 op
17 786e6deb 2021-07-21 op #include "compat.h"
18 2b2d2872 2021-06-20 op
19 61251035 2021-06-26 op #include <limits.h>
20 2b2d2872 2021-06-20 op #include <stdlib.h>
21 61251035 2021-06-26 op #include <string.h>
22 2b2d2872 2021-06-20 op
23 b1e1e41a 2021-07-14 op #include "compl.h"
24 e5a2797f 2021-07-13 op #include "defaults.h"
25 eeebca22 2022-01-11 op #include "mcache.h"
26 450a89f7 2021-07-12 op #include "minibuffer.h"
27 1fce2e75 2021-08-14 op #include "session.h"
28 2b2d2872 2021-06-20 op #include "telescope.h"
29 d1a0f2a3 2021-07-12 op #include "ui.h"
30 5caf7d67 2021-07-12 op #include "utf8.h"
31 c8c572e4 2022-02-08 op #include "utils.h"
32 2b2d2872 2021-06-20 op
33 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
34 ca231710 2021-07-15 op do { \
35 ca231710 2021-07-15 op if (in_minibuffer) { \
36 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
37 ca231710 2021-07-15 op "is not yet available."); \
38 ca231710 2021-07-15 op return; \
39 ca231710 2021-07-15 op } \
40 ca231710 2021-07-15 op } while(0)
41 ca231710 2021-07-15 op
42 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
43 5a3c3ede 2021-07-19 op do { \
44 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
45 5a3c3ede 2021-07-19 op message("text is read-only"); \
46 5a3c3ede 2021-07-19 op return; \
47 5a3c3ede 2021-07-19 op } \
48 5a3c3ede 2021-07-19 op } while(0)
49 5a3c3ede 2021-07-19 op
50 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
51 c4c82003 2021-07-01 op static inline int
52 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
53 2b2d2872 2021-06-20 op {
54 c4c82003 2021-07-01 op struct vline *vl;
55 c4c82003 2021-07-01 op int did;
56 2b2d2872 2021-06-20 op
57 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
58 c4c82003 2021-07-01 op return 0;
59 963c680c 2021-07-05 op vl = buffer->current_line;
60 2b2d2872 2021-06-20 op
61 c4c82003 2021-07-01 op did = 0;
62 c4c82003 2021-07-01 op while (n != 0) {
63 c4c82003 2021-07-01 op if (n > 0) {
64 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
65 c4c82003 2021-07-01 op if (vl == NULL)
66 c4c82003 2021-07-01 op return did;
67 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
68 963c680c 2021-07-05 op continue;
69 c4c82003 2021-07-01 op buffer->current_line = vl;
70 c4c82003 2021-07-01 op n--;
71 c4c82003 2021-07-01 op } else {
72 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
73 c4c82003 2021-07-01 op if (vl == NULL)
74 c4c82003 2021-07-01 op return did;
75 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
76 963c680c 2021-07-05 op continue;
77 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
78 6e6c6afb 2021-07-14 op buffer->line_off--;
79 c4c82003 2021-07-01 op buffer->top_line = vl;
80 6e6c6afb 2021-07-14 op }
81 c4c82003 2021-07-01 op buffer->current_line = vl;
82 c4c82003 2021-07-01 op n++;
83 c4c82003 2021-07-01 op }
84 c4c82003 2021-07-01 op
85 c4c82003 2021-07-01 op did = 1;
86 2b2d2872 2021-06-20 op }
87 2b2d2872 2021-06-20 op
88 c4c82003 2021-07-01 op return did;
89 2b2d2872 2021-06-20 op }
90 2b2d2872 2021-06-20 op
91 2b2d2872 2021-06-20 op void
92 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
93 2b2d2872 2021-06-20 op {
94 c4c82003 2021-07-01 op forward_line(buffer, -1);
95 c4c82003 2021-07-01 op }
96 2b2d2872 2021-06-20 op
97 c4c82003 2021-07-01 op void
98 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
99 c4c82003 2021-07-01 op {
100 c4c82003 2021-07-01 op forward_line(buffer, +1);
101 2b2d2872 2021-06-20 op }
102 2b2d2872 2021-06-20 op
103 2b2d2872 2021-06-20 op void
104 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
105 2b2d2872 2021-06-20 op {
106 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
107 2b2d2872 2021-06-20 op buffer->cpoff--;
108 2b2d2872 2021-06-20 op }
109 2b2d2872 2021-06-20 op
110 2b2d2872 2021-06-20 op void
111 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
112 2b2d2872 2021-06-20 op {
113 2b2d2872 2021-06-20 op size_t len = 0;
114 2b2d2872 2021-06-20 op
115 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
116 aed6fae9 2021-07-19 op return;
117 aed6fae9 2021-07-19 op
118 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
119 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
120 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
121 2b2d2872 2021-06-20 op buffer->cpoff = len;
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 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
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 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
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 a87cfde9 2021-07-19 op if (vl == NULL || vl->line == NULL)
161 2b2d2872 2021-06-20 op return;
162 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
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 5b3e45c1 2021-01-02 op event_loopbreak();
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 8f90b214 2022-08-16 op }
291 8f90b214 2022-08-16 op
292 8f90b214 2022-08-16 op #include <curses.h>
293 8f90b214 2022-08-16 op #include <unistd.h>
294 8f90b214 2022-08-16 op #include <sys/wait.h>
295 8f90b214 2022-08-16 op #include <errno.h>
296 8f90b214 2022-08-16 op static void
297 8f90b214 2022-08-16 op do_exec_command(const char *cmd, struct tab *t)
298 8f90b214 2022-08-16 op {
299 8f90b214 2022-08-16 op int s;
300 8f90b214 2022-08-16 op pid_t p;
301 8f90b214 2022-08-16 op
302 8f90b214 2022-08-16 op if (cmd == NULL)
303 8f90b214 2022-08-16 op return;
304 8f90b214 2022-08-16 op
305 8f90b214 2022-08-16 op endwin();
306 8f90b214 2022-08-16 op
307 8f90b214 2022-08-16 op switch (p = fork()) {
308 8f90b214 2022-08-16 op case -1:
309 8f90b214 2022-08-16 op message("failed to fork: %s", strerror(errno));
310 8f90b214 2022-08-16 op return;
311 8f90b214 2022-08-16 op case 0:
312 8f90b214 2022-08-16 op execl("/bin/sh", "sh", "-c", cmd, NULL);
313 8f90b214 2022-08-16 op warn("exec \"%s\" failed", cmd);
314 8f90b214 2022-08-16 op _exit(1);
315 8f90b214 2022-08-16 op }
316 8f90b214 2022-08-16 op
317 8f90b214 2022-08-16 op again:
318 8f90b214 2022-08-16 op if (waitpid(p, &s, 0) == -1) {
319 8f90b214 2022-08-16 op if (errno == EINTR)
320 8f90b214 2022-08-16 op goto again;
321 8f90b214 2022-08-16 op }
322 8f90b214 2022-08-16 op
323 8f90b214 2022-08-16 op refresh();
324 8f90b214 2022-08-16 op clear();
325 8f90b214 2022-08-16 op ui_schedule_redraw();
326 8f90b214 2022-08-16 op /* rearrange_windows(); */
327 2b2d2872 2021-06-20 op }
328 2b2d2872 2021-06-20 op
329 2b2d2872 2021-06-20 op void
330 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
331 2b2d2872 2021-06-20 op {
332 2b2d2872 2021-06-20 op struct vline *vl;
333 963c680c 2021-07-05 op struct line *l;
334 2b2d2872 2021-06-20 op
335 2b2d2872 2021-06-20 op vl = buffer->current_line;
336 a87cfde9 2021-07-19 op
337 a87cfde9 2021-07-19 op if (vl == NULL)
338 a87cfde9 2021-07-19 op return;
339 a87cfde9 2021-07-19 op
340 963c680c 2021-07-05 op switch (vl->parent->type) {
341 963c680c 2021-07-05 op case LINE_LINK:
342 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, vl->parent->alt, NULL,
343 ed21a9a1 2022-01-11 op LU_MODE_NOCACHE);
344 963c680c 2021-07-05 op break;
345 963c680c 2021-07-05 op case LINE_PRE_START:
346 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
347 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
348 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
349 963c680c 2021-07-05 op break;
350 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
351 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
352 6e6c6afb 2021-07-14 op buffer->line_max--;
353 6e6c6afb 2021-07-14 op else
354 6e6c6afb 2021-07-14 op buffer->line_max++;
355 963c680c 2021-07-05 op }
356 8f90b214 2022-08-16 op break;
357 8f90b214 2022-08-16 op case LINE_DOWNLOAD:
358 8f90b214 2022-08-16 op case LINE_DOWNLOAD_DONE:
359 8f90b214 2022-08-16 op minibuffer_read("Execute: ", do_exec_command,
360 8f90b214 2022-08-16 op NULL);
361 8f90b214 2022-08-16 op snprintf(ministate.buf, sizeof(ministate.buf),
362 8f90b214 2022-08-16 op "xdg-open %s", vl->parent->alt);
363 963c680c 2021-07-05 op break;
364 963c680c 2021-07-05 op default:
365 963c680c 2021-07-05 op break;
366 963c680c 2021-07-05 op }
367 2b2d2872 2021-06-20 op }
368 2b2d2872 2021-06-20 op
369 2b2d2872 2021-06-20 op void
370 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
371 2b2d2872 2021-06-20 op {
372 2b2d2872 2021-06-20 op struct vline *vl;
373 2b2d2872 2021-06-20 op
374 2b2d2872 2021-06-20 op vl = buffer->current_line;
375 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
376 2b2d2872 2021-06-20 op return;
377 2b2d2872 2021-06-20 op
378 55eb4d95 2021-08-12 op new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
379 2b2d2872 2021-06-20 op }
380 2b2d2872 2021-06-20 op
381 2b2d2872 2021-06-20 op void
382 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
383 2b2d2872 2021-06-20 op {
384 5d0feb4b 2021-06-23 op struct excursion place;
385 5d0feb4b 2021-06-23 op
386 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
387 5d0feb4b 2021-06-23 op
388 2b2d2872 2021-06-20 op do {
389 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
390 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
391 2b2d2872 2021-06-20 op message("No previous link");
392 2b2d2872 2021-06-20 op return;
393 2b2d2872 2021-06-20 op }
394 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
395 2b2d2872 2021-06-20 op }
396 2b2d2872 2021-06-20 op
397 2b2d2872 2021-06-20 op void
398 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
399 2b2d2872 2021-06-20 op {
400 5d0feb4b 2021-06-23 op struct excursion place;
401 5d0feb4b 2021-06-23 op
402 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
403 5d0feb4b 2021-06-23 op
404 2b2d2872 2021-06-20 op do {
405 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
406 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
407 2b2d2872 2021-06-20 op message("No next link");
408 2b2d2872 2021-06-20 op return;
409 2b2d2872 2021-06-20 op }
410 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
411 1c412d48 2021-06-25 op }
412 1c412d48 2021-06-25 op
413 1c412d48 2021-06-25 op static inline int
414 1c412d48 2021-06-25 op is_heading(const struct line *l)
415 1c412d48 2021-06-25 op {
416 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
417 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
418 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
419 1c412d48 2021-06-25 op }
420 1c412d48 2021-06-25 op
421 1c412d48 2021-06-25 op void
422 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
423 1c412d48 2021-06-25 op {
424 1c412d48 2021-06-25 op struct excursion place;
425 1c412d48 2021-06-25 op
426 1c412d48 2021-06-25 op save_excursion(&place, buffer);
427 1c412d48 2021-06-25 op
428 1c412d48 2021-06-25 op do {
429 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
430 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
431 1c412d48 2021-06-25 op message("No previous heading");
432 1c412d48 2021-06-25 op return;
433 1c412d48 2021-06-25 op }
434 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
435 2b2d2872 2021-06-20 op }
436 2b2d2872 2021-06-20 op
437 2b2d2872 2021-06-20 op void
438 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
439 1c412d48 2021-06-25 op {
440 1c412d48 2021-06-25 op struct excursion place;
441 1c412d48 2021-06-25 op
442 1c412d48 2021-06-25 op save_excursion(&place, buffer);
443 1c412d48 2021-06-25 op
444 1c412d48 2021-06-25 op do {
445 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
446 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
447 1c412d48 2021-06-25 op message("No next heading");
448 1c412d48 2021-06-25 op return;
449 1c412d48 2021-06-25 op }
450 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
451 1c412d48 2021-06-25 op }
452 1c412d48 2021-06-25 op
453 1c412d48 2021-06-25 op void
454 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
455 2b2d2872 2021-06-20 op {
456 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
457 2b2d2872 2021-06-20 op message("No previous page");
458 2b2d2872 2021-06-20 op }
459 2b2d2872 2021-06-20 op
460 2b2d2872 2021-06-20 op void
461 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
462 2b2d2872 2021-06-20 op {
463 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
464 2b2d2872 2021-06-20 op message("No next page");
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_clear_minibuf(struct buffer *buffer)
469 2b2d2872 2021-06-20 op {
470 95a8c791 2021-08-26 op message(NULL);
471 2b2d2872 2021-06-20 op }
472 2b2d2872 2021-06-20 op
473 2b2d2872 2021-06-20 op void
474 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
475 2b2d2872 2021-06-20 op {
476 2b2d2872 2021-06-20 op size_t len;
477 2b2d2872 2021-06-20 op
478 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
479 2b2d2872 2021-06-20 op
480 004fe817 2021-07-24 op enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
481 27dbcaab 2022-04-13 op &eecmd_history, compl_eecmd, NULL, 1);
482 2b2d2872 2021-06-20 op
483 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
484 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
485 2b2d2872 2021-06-20 op
486 2b2d2872 2021-06-20 op if (thiskey.meta)
487 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
488 2b2d2872 2021-06-20 op
489 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
490 2b2d2872 2021-06-20 op
491 2b2d2872 2021-06-20 op if (thiskey.meta)
492 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
493 2b2d2872 2021-06-20 op }
494 2b2d2872 2021-06-20 op
495 2b2d2872 2021-06-20 op void
496 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
497 2b2d2872 2021-06-20 op {
498 2b2d2872 2021-06-20 op struct tab *tab, *t;
499 2b2d2872 2021-06-20 op
500 83dce83d 2021-07-17 op tab = current_tab;
501 2b2d2872 2021-06-20 op
502 90730426 2021-07-21 op if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
503 90730426 2021-07-21 op (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
504 90730426 2021-07-21 op switch_to_tab(t);
505 05de8ac3 2022-01-06 op kill_tab(tab, 0);
506 90730426 2021-07-21 op } else
507 90730426 2021-07-21 op message("Can't close the only tab.");
508 2b2d2872 2021-06-20 op
509 2b2d2872 2021-06-20 op }
510 2b2d2872 2021-06-20 op
511 2b2d2872 2021-06-20 op void
512 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
513 2b2d2872 2021-06-20 op {
514 2b2d2872 2021-06-20 op struct tab *t, *i;
515 2b2d2872 2021-06-20 op
516 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
517 83dce83d 2021-07-17 op if (t == current_tab)
518 2b2d2872 2021-06-20 op continue;
519 2b2d2872 2021-06-20 op
520 05de8ac3 2022-01-06 op kill_tab(t, 0);
521 2b2d2872 2021-06-20 op }
522 2b2d2872 2021-06-20 op }
523 2b2d2872 2021-06-20 op
524 2b2d2872 2021-06-20 op void
525 6c74799d 2022-01-05 op cmd_tab_undo_close(struct buffer *buffer)
526 6c74799d 2022-01-05 op {
527 6c74799d 2022-01-05 op struct tab *t;
528 6c74799d 2022-01-05 op
529 6c74799d 2022-01-05 op if ((t = unkill_tab()) == NULL) {
530 6c74799d 2022-01-05 op message("No recently-closed tabs");
531 6c74799d 2022-01-05 op return;
532 6c74799d 2022-01-05 op }
533 6c74799d 2022-01-05 op
534 6c74799d 2022-01-05 op switch_to_tab(t);
535 6c74799d 2022-01-05 op }
536 6c74799d 2022-01-05 op
537 6c74799d 2022-01-05 op void
538 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
539 2b2d2872 2021-06-20 op {
540 2b2d2872 2021-06-20 op const char *url;
541 2b2d2872 2021-06-20 op
542 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
543 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
544 2b2d2872 2021-06-20 op
545 55eb4d95 2021-08-12 op new_tab(url, NULL, NULL);
546 2b2d2872 2021-06-20 op }
547 2b2d2872 2021-06-20 op
548 2b2d2872 2021-06-20 op void
549 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
550 2b2d2872 2021-06-20 op {
551 83dce83d 2021-07-17 op struct tab *t;
552 2b2d2872 2021-06-20 op
553 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
554 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
555 2ddbda6b 2021-07-17 op switch_to_tab(t);
556 2b2d2872 2021-06-20 op }
557 2b2d2872 2021-06-20 op
558 2b2d2872 2021-06-20 op void
559 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
560 2b2d2872 2021-06-20 op {
561 83dce83d 2021-07-17 op struct tab *t;
562 2b2d2872 2021-06-20 op
563 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
564 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
565 2ddbda6b 2021-07-17 op switch_to_tab(t);
566 2b2d2872 2021-06-20 op }
567 2b2d2872 2021-06-20 op
568 2b2d2872 2021-06-20 op void
569 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
570 2b2d2872 2021-06-20 op {
571 83dce83d 2021-07-17 op struct tab *t;
572 2b2d2872 2021-06-20 op
573 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
574 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
575 2b2d2872 2021-06-20 op
576 2b2d2872 2021-06-20 op if (t == NULL)
577 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
578 2b2d2872 2021-06-20 op else
579 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
580 2b2d2872 2021-06-20 op }
581 2b2d2872 2021-06-20 op
582 2b2d2872 2021-06-20 op void
583 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
584 2b2d2872 2021-06-20 op {
585 83dce83d 2021-07-17 op struct tab *t;
586 2b2d2872 2021-06-20 op
587 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
588 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
589 2b2d2872 2021-06-20 op
590 32ac17a4 2021-08-12 op if (t == NULL)
591 32ac17a4 2021-08-12 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
592 32ac17a4 2021-08-12 op else
593 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
594 2b2d2872 2021-06-20 op }
595 2b2d2872 2021-06-20 op
596 2b2d2872 2021-06-20 op void
597 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
598 65601367 2021-07-14 op {
599 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
600 65601367 2021-07-14 op
601 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
602 27dbcaab 2022-04-13 op NULL, compl_ts, NULL, 1);
603 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
604 65601367 2021-07-14 op }
605 65601367 2021-07-14 op
606 65601367 2021-07-14 op void
607 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
608 2b2d2872 2021-06-20 op {
609 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
610 2b2d2872 2021-06-20 op
611 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
612 27dbcaab 2022-04-13 op &lu_history, compl_lu, NULL, 0);
613 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
614 2b2d2872 2021-06-20 op }
615 2b2d2872 2021-06-20 op
616 2b2d2872 2021-06-20 op void
617 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
618 2b2d2872 2021-06-20 op {
619 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
620 2b2d2872 2021-06-20 op
621 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
622 27dbcaab 2022-04-13 op &lu_history, compl_lu, NULL, 0);
623 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
624 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
625 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
626 2b2d2872 2021-06-20 op }
627 2b2d2872 2021-06-20 op
628 2b2d2872 2021-06-20 op void
629 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
630 661233ed 2021-07-14 op {
631 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL,
632 ed21a9a1 2022-01-11 op LU_MODE_NOHIST|LU_MODE_NOCACHE);
633 661233ed 2021-07-14 op }
634 661233ed 2021-07-14 op
635 661233ed 2021-07-14 op void
636 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
637 2b2d2872 2021-06-20 op {
638 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
639 ca231710 2021-07-15 op
640 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
641 27dbcaab 2022-04-13 op NULL, NULL, 0);
642 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
643 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
644 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
645 2b2d2872 2021-06-20 op }
646 2b2d2872 2021-06-20 op
647 2b2d2872 2021-06-20 op void
648 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
649 2b2d2872 2021-06-20 op {
650 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
651 2b2d2872 2021-06-20 op }
652 2b2d2872 2021-06-20 op
653 2b2d2872 2021-06-20 op void
654 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
655 2b2d2872 2021-06-20 op {
656 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
657 753c6ac7 2021-07-14 op }
658 753c6ac7 2021-07-14 op
659 753c6ac7 2021-07-14 op void
660 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
661 753c6ac7 2021-07-14 op {
662 c1a72389 2021-07-15 op struct line *l;
663 c1a72389 2021-07-15 op
664 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
665 753c6ac7 2021-07-14 op
666 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
667 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
668 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
669 c1a72389 2021-07-15 op
670 c1a72389 2021-07-15 op if (l == NULL) {
671 c1a72389 2021-07-15 op message("No links found");
672 c1a72389 2021-07-15 op return;
673 c1a72389 2021-07-15 op }
674 c1a72389 2021-07-15 op
675 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
676 27dbcaab 2022-04-13 op NULL, compl_ls, l, 1);
677 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
678 753c6ac7 2021-07-14 op }
679 753c6ac7 2021-07-14 op
680 753c6ac7 2021-07-14 op void
681 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
682 753c6ac7 2021-07-14 op {
683 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
684 753c6ac7 2021-07-14 op
685 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
686 27dbcaab 2022-04-13 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head), 1);
687 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
688 edd9a650 2021-07-15 op }
689 edd9a650 2021-07-15 op
690 edd9a650 2021-07-15 op void
691 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
692 edd9a650 2021-07-15 op {
693 c1a72389 2021-07-15 op struct line *l;
694 c1a72389 2021-07-15 op
695 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
696 edd9a650 2021-07-15 op
697 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
698 c1a72389 2021-07-15 op while (l != NULL &&
699 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
700 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
701 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
702 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
703 c1a72389 2021-07-15 op
704 c1a72389 2021-07-15 op if (l == NULL) {
705 c1a72389 2021-07-15 op message("No headings found");
706 c1a72389 2021-07-15 op return;
707 c1a72389 2021-07-15 op }
708 c1a72389 2021-07-15 op
709 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
710 27dbcaab 2022-04-13 op NULL, compl_toc, l, 1);
711 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
712 edd9a650 2021-07-15 op sizeof(ministate.prompt));
713 2b2d2872 2021-06-20 op }
714 2b2d2872 2021-06-20 op
715 2b2d2872 2021-06-20 op void
716 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
717 61251035 2021-06-26 op {
718 61251035 2021-06-26 op if (fill_column == INT_MAX)
719 61251035 2021-06-26 op return;
720 61251035 2021-06-26 op
721 61251035 2021-06-26 op fill_column += 2;
722 61251035 2021-06-26 op message("fill-column: %d", fill_column);
723 61251035 2021-06-26 op
724 61251035 2021-06-26 op ui_schedule_redraw();
725 61251035 2021-06-26 op }
726 61251035 2021-06-26 op
727 61251035 2021-06-26 op void
728 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
729 61251035 2021-06-26 op {
730 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
731 61251035 2021-06-26 op return;
732 61251035 2021-06-26 op
733 61251035 2021-06-26 op fill_column -= 2;
734 61251035 2021-06-26 op message("fill-column: %d", fill_column);
735 61251035 2021-06-26 op
736 61251035 2021-06-26 op ui_schedule_redraw();
737 61251035 2021-06-26 op }
738 61251035 2021-06-26 op
739 61251035 2021-06-26 op void
740 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
741 2b2d2872 2021-06-20 op {
742 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
743 2b2d2872 2021-06-20 op if (olivetti_mode)
744 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
745 2b2d2872 2021-06-20 op else
746 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
747 2b2d2872 2021-06-20 op
748 2b2d2872 2021-06-20 op ui_schedule_redraw();
749 2b2d2872 2021-06-20 op }
750 2b2d2872 2021-06-20 op
751 2b2d2872 2021-06-20 op void
752 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
753 2b2d2872 2021-06-20 op {
754 2b2d2872 2021-06-20 op char *c, *n;
755 2b2d2872 2021-06-20 op
756 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
757 2b2d2872 2021-06-20 op
758 2b2d2872 2021-06-20 op minibuffer_taint_hist();
759 2b2d2872 2021-06-20 op
760 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
761 2b2d2872 2021-06-20 op if (*c == '\0')
762 2b2d2872 2021-06-20 op return;
763 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
764 2b2d2872 2021-06-20 op
765 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
766 b1e1e41a 2021-07-14 op
767 b1e1e41a 2021-07-14 op recompute_completions(0);
768 2b2d2872 2021-06-20 op }
769 2b2d2872 2021-06-20 op
770 2b2d2872 2021-06-20 op void
771 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
772 2b2d2872 2021-06-20 op {
773 2b2d2872 2021-06-20 op char *c, *p, *start;
774 2b2d2872 2021-06-20 op
775 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
776 2b2d2872 2021-06-20 op
777 2b2d2872 2021-06-20 op minibuffer_taint_hist();
778 2b2d2872 2021-06-20 op
779 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
780 2b2d2872 2021-06-20 op start = buffer->current_line->line;
781 2b2d2872 2021-06-20 op if (c == start)
782 2b2d2872 2021-06-20 op return;
783 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
784 2b2d2872 2021-06-20 op
785 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
786 2b2d2872 2021-06-20 op buffer->cpoff--;
787 b1e1e41a 2021-07-14 op
788 b1e1e41a 2021-07-14 op recompute_completions(0);
789 2b2d2872 2021-06-20 op }
790 2b2d2872 2021-06-20 op
791 2b2d2872 2021-06-20 op void
792 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
793 2b2d2872 2021-06-20 op {
794 2b2d2872 2021-06-20 op char *c;
795 2b2d2872 2021-06-20 op
796 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
797 2b2d2872 2021-06-20 op
798 2b2d2872 2021-06-20 op minibuffer_taint_hist();
799 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
800 2b2d2872 2021-06-20 op *c = '\0';
801 b1e1e41a 2021-07-14 op
802 b1e1e41a 2021-07-14 op recompute_completions(0);
803 067b7ffd 2022-04-15 op }
804 067b7ffd 2022-04-15 op
805 067b7ffd 2022-04-15 op void
806 067b7ffd 2022-04-15 op cmd_mini_kill_whole_line(struct buffer *buffer)
807 067b7ffd 2022-04-15 op {
808 067b7ffd 2022-04-15 op GUARD_READ_ONLY();
809 067b7ffd 2022-04-15 op
810 067b7ffd 2022-04-15 op minibuffer_taint_hist();
811 067b7ffd 2022-04-15 op *buffer->current_line->line = '\0';
812 067b7ffd 2022-04-15 op buffer->cpoff = 0;
813 2b2d2872 2021-06-20 op }
814 2b2d2872 2021-06-20 op
815 2b2d2872 2021-06-20 op void
816 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
817 2b2d2872 2021-06-20 op {
818 2b2d2872 2021-06-20 op if (!in_minibuffer)
819 2b2d2872 2021-06-20 op return;
820 2b2d2872 2021-06-20 op
821 2b2d2872 2021-06-20 op ministate.abortfn();
822 2b2d2872 2021-06-20 op }
823 2b2d2872 2021-06-20 op
824 2b2d2872 2021-06-20 op void
825 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
826 2b2d2872 2021-06-20 op {
827 27dbcaab 2022-04-13 op struct vline *vl;
828 27dbcaab 2022-04-13 op
829 2b2d2872 2021-06-20 op if (!in_minibuffer)
830 2b2d2872 2021-06-20 op return;
831 2b2d2872 2021-06-20 op
832 47eb6cd7 2022-04-15 op if (ministate.compl.must_select && ministate.hist_cur == NULL) {
833 27dbcaab 2022-04-13 op vl = ministate.compl.buffer.current_line;
834 27dbcaab 2022-04-13 op if (vl == NULL || vl->parent->flags & L_HIDDEN ||
835 27dbcaab 2022-04-13 op vl->parent->type == LINE_COMPL) {
836 27dbcaab 2022-04-13 op message("no match");
837 27dbcaab 2022-04-13 op return;
838 27dbcaab 2022-04-13 op }
839 27dbcaab 2022-04-13 op }
840 27dbcaab 2022-04-13 op
841 2b2d2872 2021-06-20 op minibuffer_taint_hist();
842 2b2d2872 2021-06-20 op ministate.donefn();
843 2b2d2872 2021-06-20 op }
844 2b2d2872 2021-06-20 op
845 2b2d2872 2021-06-20 op void
846 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
847 2b2d2872 2021-06-20 op {
848 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
849 2b2d2872 2021-06-20 op message("No history");
850 2b2d2872 2021-06-20 op return;
851 2b2d2872 2021-06-20 op }
852 2b2d2872 2021-06-20 op
853 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
854 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
855 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
856 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
857 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
858 fc14510d 2021-07-14 op message("No prev history item");
859 2b2d2872 2021-06-20 op } else {
860 2b2d2872 2021-06-20 op ministate.hist_off--;
861 2b2d2872 2021-06-20 op }
862 2b2d2872 2021-06-20 op
863 595564da 2022-04-15 op if (ministate.hist_cur != NULL) {
864 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
865 595564da 2022-04-15 op recompute_completions(0);
866 595564da 2022-04-15 op }
867 2b2d2872 2021-06-20 op }
868 2b2d2872 2021-06-20 op
869 2b2d2872 2021-06-20 op void
870 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
871 2b2d2872 2021-06-20 op {
872 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
873 2b2d2872 2021-06-20 op message("No history");
874 2b2d2872 2021-06-20 op return;
875 2b2d2872 2021-06-20 op }
876 2b2d2872 2021-06-20 op
877 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
878 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
879 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
880 2b2d2872 2021-06-20 op ministate.hist_off = 0;
881 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
882 fc14510d 2021-07-14 op message("No next history item");
883 2b2d2872 2021-06-20 op } else {
884 2b2d2872 2021-06-20 op ministate.hist_off++;
885 2b2d2872 2021-06-20 op }
886 2b2d2872 2021-06-20 op
887 595564da 2022-04-15 op if (ministate.hist_cur != NULL) {
888 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
889 595564da 2022-04-15 op recompute_completions(0);
890 595564da 2022-04-15 op }
891 2b2d2872 2021-06-20 op }
892 e7b982f4 2021-07-14 op
893 e7b982f4 2021-07-14 op void
894 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
895 e7b982f4 2021-07-14 op {
896 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
897 e7b982f4 2021-07-14 op return;
898 e7b982f4 2021-07-14 op
899 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
900 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
901 fea02b0b 2022-04-13 op return;
902 e7b982f4 2021-07-14 op
903 fea02b0b 2022-04-13 op buffer->current_line->parent->type = LINE_COMPL;
904 fea02b0b 2022-04-13 op if (!forward_line(buffer, -1))
905 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
906 fea02b0b 2022-04-13 op else
907 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
908 e7b982f4 2021-07-14 op }
909 e7b982f4 2021-07-14 op
910 e7b982f4 2021-07-14 op void
911 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
912 e7b982f4 2021-07-14 op {
913 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
914 e7b982f4 2021-07-14 op return;
915 e7b982f4 2021-07-14 op
916 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
917 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
918 fea02b0b 2022-04-13 op return;
919 e7b982f4 2021-07-14 op
920 fea02b0b 2022-04-13 op if (buffer->current_line->parent->type == LINE_COMPL_CURRENT) {
921 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
922 fea02b0b 2022-04-13 op forward_line(buffer, +1);
923 fea02b0b 2022-04-13 op }
924 e7b982f4 2021-07-14 op
925 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
926 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
927 e7b982f4 2021-07-14 op }
928 e7b982f4 2021-07-14 op
929 e7b982f4 2021-07-14 op void
930 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
931 e7b982f4 2021-07-14 op {
932 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
933 e7b982f4 2021-07-14 op return;
934 e7b982f4 2021-07-14 op
935 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
936 e7b982f4 2021-07-14 op }
937 8a3b5609 2021-07-15 op
938 8a3b5609 2021-07-15 op void
939 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
940 8a3b5609 2021-07-15 op {
941 8a3b5609 2021-07-15 op message("Zzz...");
942 8a3b5609 2021-07-15 op ui_suspend();
943 8a3b5609 2021-07-15 op }
944 987d9c88 2021-07-15 op
945 987d9c88 2021-07-15 op void
946 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
947 987d9c88 2021-07-15 op {
948 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
949 987d9c88 2021-07-15 op
950 987d9c88 2021-07-15 op if (dont_wrap_pre)
951 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
952 987d9c88 2021-07-15 op else
953 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
954 987d9c88 2021-07-15 op
955 987d9c88 2021-07-15 op ui_schedule_redraw();
956 987d9c88 2021-07-15 op }
957 de190a2b 2021-07-17 op
958 de190a2b 2021-07-17 op void
959 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
960 de190a2b 2021-07-17 op {
961 de190a2b 2021-07-17 op struct vline *vl;
962 de190a2b 2021-07-17 op
963 de190a2b 2021-07-17 op if (!in_minibuffer)
964 de190a2b 2021-07-17 op return;
965 de190a2b 2021-07-17 op
966 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
967 de190a2b 2021-07-17 op
968 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
969 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
970 de190a2b 2021-07-17 op
971 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
972 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
973 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
974 de190a2b 2021-07-17 op
975 de190a2b 2021-07-17 op if (vl == NULL)
976 de190a2b 2021-07-17 op return;
977 de190a2b 2021-07-17 op
978 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
979 de190a2b 2021-07-17 op buffer->top_line = vl;
980 de190a2b 2021-07-17 op buffer->current_line = vl;
981 de190a2b 2021-07-17 op }
982 de190a2b 2021-07-17 op
983 de190a2b 2021-07-17 op void
984 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
985 de190a2b 2021-07-17 op {
986 de190a2b 2021-07-17 op struct vline *vl;
987 de190a2b 2021-07-17 op
988 de190a2b 2021-07-17 op if (!in_minibuffer)
989 de190a2b 2021-07-17 op return;
990 de190a2b 2021-07-17 op
991 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
992 de190a2b 2021-07-17 op
993 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
994 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
995 de190a2b 2021-07-17 op
996 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
997 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
998 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
999 de190a2b 2021-07-17 op
1000 de190a2b 2021-07-17 op if (vl == NULL)
1001 de190a2b 2021-07-17 op return;
1002 de190a2b 2021-07-17 op
1003 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
1004 de190a2b 2021-07-17 op buffer->current_line = vl;
1005 65340174 2021-07-21 op }
1006 65340174 2021-07-21 op
1007 65340174 2021-07-21 op void
1008 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
1009 65340174 2021-07-21 op {
1010 65340174 2021-07-21 op ui_other_window();
1011 167131d5 2021-07-24 op }
1012 167131d5 2021-07-24 op
1013 167131d5 2021-07-24 op void
1014 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
1015 167131d5 2021-07-24 op {
1016 167131d5 2021-07-24 op if (!in_minibuffer)
1017 167131d5 2021-07-24 op return;
1018 167131d5 2021-07-24 op
1019 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
1020 167131d5 2021-07-24 op if (buffer->current_line == NULL)
1021 167131d5 2021-07-24 op return;
1022 167131d5 2021-07-24 op
1023 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
1024 167131d5 2021-07-24 op cmd_scroll_up(buffer);
1025 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
1026 167131d5 2021-07-24 op }
1027 167131d5 2021-07-24 op
1028 167131d5 2021-07-24 op void
1029 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
1030 167131d5 2021-07-24 op {
1031 167131d5 2021-07-24 op if (!in_minibuffer)
1032 167131d5 2021-07-24 op return;
1033 167131d5 2021-07-24 op
1034 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
1035 167131d5 2021-07-24 op if (buffer->current_line == NULL)
1036 167131d5 2021-07-24 op return;
1037 167131d5 2021-07-24 op
1038 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
1039 167131d5 2021-07-24 op cmd_scroll_down(buffer);
1040 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
1041 3b5f459e 2021-11-05 op }
1042 3b5f459e 2021-11-05 op
1043 3b5f459e 2021-11-05 op void
1044 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
1045 3b5f459e 2021-11-05 op {
1046 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1047 de190a2b 2021-07-17 op }
1048 eeebca22 2022-01-11 op
1049 eeebca22 2022-01-11 op void
1050 eeebca22 2022-01-11 op cmd_cache_info(struct buffer *buffer)
1051 eeebca22 2022-01-11 op {
1052 eeebca22 2022-01-11 op size_t npages, tot;
1053 eeebca22 2022-01-11 op char fmt[FMT_SCALED_STRSIZE];
1054 eeebca22 2022-01-11 op
1055 eeebca22 2022-01-11 op mcache_info(&npages, &tot);
1056 eeebca22 2022-01-11 op
1057 eeebca22 2022-01-11 op if (fmt_scaled(tot, fmt) == 0)
1058 bb5abe9f 2022-01-13 op message("pages: %zu, total: %s", npages, fmt);
1059 eeebca22 2022-01-11 op else
1060 bb5abe9f 2022-01-13 op message("pages: %zu, total: %zu", npages, tot);
1061 ed504b9e 2022-02-07 op }
1062 ed504b9e 2022-02-07 op
1063 ed504b9e 2022-02-07 op void
1064 ed504b9e 2022-02-07 op cmd_reply_last_input(struct buffer *buffer)
1065 ed504b9e 2022-02-07 op {
1066 ed504b9e 2022-02-07 op GUARD_RECURSIVE_MINIBUFFER();
1067 ed504b9e 2022-02-07 op
1068 ed504b9e 2022-02-07 op if (current_tab->last_input_url == NULL) {
1069 ed504b9e 2022-02-07 op message("there was no previous input request in this tab");
1070 acf9defe 2022-02-08 op return;
1071 acf9defe 2022-02-08 op }
1072 acf9defe 2022-02-08 op
1073 d89eb764 2022-04-24 op if (!strncmp(current_tab->last_input_url, "gopher", 6)) {
1074 acf9defe 2022-02-08 op load_url_in_tab(current_tab, current_tab->last_input_url,
1075 acf9defe 2022-02-08 op NULL, LU_MODE_NOCACHE);
1076 ed504b9e 2022-02-07 op return;
1077 ed504b9e 2022-02-07 op }
1078 ed504b9e 2022-02-07 op
1079 ed504b9e 2022-02-07 op message("%s", current_tab->last_input_url);
1080 ed504b9e 2022-02-07 op ui_require_input(current_tab, 0, ir_select_reply);
1081 eeebca22 2022-01-11 op }
1082 868b3a8f 2022-04-13 op
1083 868b3a8f 2022-04-13 op void
1084 868b3a8f 2022-04-13 op cmd_write_buffer(struct buffer *buffer)
1085 868b3a8f 2022-04-13 op {
1086 868b3a8f 2022-04-13 op const char *f, *url;
1087 868b3a8f 2022-04-13 op char path[PATH_MAX];
1088 868b3a8f 2022-04-13 op
1089 868b3a8f 2022-04-13 op GUARD_RECURSIVE_MINIBUFFER();
1090 868b3a8f 2022-04-13 op
1091 868b3a8f 2022-04-13 op if (safe_mode) {
1092 868b3a8f 2022-04-13 op message("Can't write buffer in safe-mode.");
1093 868b3a8f 2022-04-13 op return;
1094 868b3a8f 2022-04-13 op }
1095 868b3a8f 2022-04-13 op
1096 868b3a8f 2022-04-13 op url = current_tab->hist_cur->h;
1097 868b3a8f 2022-04-13 op
1098 868b3a8f 2022-04-13 op if ((f = strrchr(url, '/')) != NULL)
1099 868b3a8f 2022-04-13 op f++;
1100 868b3a8f 2022-04-13 op if (f == NULL || *f == '\0') {
1101 868b3a8f 2022-04-13 op /* guess a decent file name based on the protocol used */
1102 868b3a8f 2022-04-13 op if (!strncmp(url, "gemini://", 9))
1103 868b3a8f 2022-04-13 op f = "index.gmi";
1104 868b3a8f 2022-04-13 op else
1105 868b3a8f 2022-04-13 op f = "index.txt";
1106 868b3a8f 2022-04-13 op }
1107 868b3a8f 2022-04-13 op
1108 868b3a8f 2022-04-13 op strlcpy(path, download_path, sizeof(path));
1109 868b3a8f 2022-04-13 op strlcat(path, f, sizeof(path));
1110 868b3a8f 2022-04-13 op
1111 868b3a8f 2022-04-13 op ui_read("Write file", write_buffer, current_tab, path);
1112 868b3a8f 2022-04-13 op }