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