2 2b2d2872 2021-06-20 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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.
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.
17 786e6deb 2021-07-21 op #include "compat.h"
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>
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"
33 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
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."); \
42 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
44 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
45 5a3c3ede 2021-07-19 op message("text is read-only"); \
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)
54 c4c82003 2021-07-01 op struct vline *vl;
57 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
59 963c680c 2021-07-05 op vl = buffer->current_line;
62 c4c82003 2021-07-01 op while (n != 0) {
64 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
65 c4c82003 2021-07-01 op if (vl == NULL)
67 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
69 c4c82003 2021-07-01 op buffer->current_line = vl;
72 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
73 c4c82003 2021-07-01 op if (vl == NULL)
75 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
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;
81 c4c82003 2021-07-01 op buffer->current_line = vl;
92 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
94 c4c82003 2021-07-01 op forward_line(buffer, -1);
98 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
100 c4c82003 2021-07-01 op forward_line(buffer, +1);
104 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
106 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
107 2b2d2872 2021-06-20 op buffer->cpoff--;
111 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
113 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
115 bd4a08a7 2022-11-07 op if (buffer->current_line->cplen > buffer->cpoff)
116 bd4a08a7 2022-11-07 op buffer->cpoff++;
120 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
123 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
124 2b2d2872 2021-06-20 op message("No previous paragraph");
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);
132 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
135 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
136 2b2d2872 2021-06-20 op message("No next paragraph");
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);
144 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
146 2b2d2872 2021-06-20 op buffer->cpoff = 0;
150 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
152 2b2d2872 2021-06-20 op struct vline *vl;
154 2b2d2872 2021-06-20 op vl = buffer->current_line;
155 bd4a08a7 2022-11-07 op if (vl == NULL)
157 bd4a08a7 2022-11-07 op buffer->cpoff = vl->cplen;
161 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
163 95a8c791 2021-08-26 op ui_schedule_redraw();
167 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
169 e39920a9 2021-07-07 op struct vline *vl;
172 028fff57 2021-07-30 op if (buffer->top_line == NULL)
175 028fff57 2021-07-30 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
179 028fff57 2021-07-30 op buffer->top_line = vl;
181 028fff57 2021-07-30 op if (vl->parent->flags & L_HIDDEN)
187 41b1ed04 2021-07-21 op buffer->line_off--;
189 028fff57 2021-07-30 op forward_line(buffer, -1);
193 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
195 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
199 028fff57 2021-07-30 op if (buffer->top_line == NULL)
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)
208 2b2d2872 2021-06-20 op buffer->line_off++;
212 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
214 64923c4b 2021-07-15 op struct vline *vl;
217 b471d670 2021-07-24 op if (buffer->top_line == NULL)
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)
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);
231 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
235 b471d670 2021-07-24 op if (buffer->top_line == NULL)
238 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
239 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
242 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
244 eab11449 2021-07-19 op buffer->line_off++;
249 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
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;
258 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
260 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
262 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
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);
269 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
273 5b3e45c1 2021-01-02 op kill_telescope_cb(int r, struct tab *tab)
276 5b3e45c1 2021-01-02 op save_session();
277 5b3e45c1 2021-01-02 op event_loopbreak();
282 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
284 5b3e45c1 2021-01-02 op yornp("really quit?", kill_telescope_cb, NULL);
288 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
290 2b2d2872 2021-06-20 op struct vline *vl;
291 963c680c 2021-07-05 op struct line *l;
293 2b2d2872 2021-06-20 op vl = buffer->current_line;
295 a87cfde9 2021-07-19 op if (vl == NULL)
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);
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)
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--;
312 6e6c6afb 2021-07-14 op buffer->line_max++;
321 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
323 2b2d2872 2021-06-20 op struct vline *vl;
325 2b2d2872 2021-06-20 op vl = buffer->current_line;
326 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
329 55eb4d95 2021-08-12 op new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
333 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
335 5d0feb4b 2021-06-23 op struct excursion place;
337 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
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");
345 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
349 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
351 5d0feb4b 2021-06-23 op struct excursion place;
353 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
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");
361 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
364 1c412d48 2021-06-25 op static inline int
365 1c412d48 2021-06-25 op is_heading(const struct line *l)
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;
373 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
375 1c412d48 2021-06-25 op struct excursion place;
377 1c412d48 2021-06-25 op save_excursion(&place, buffer);
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");
385 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
389 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
391 1c412d48 2021-06-25 op struct excursion place;
393 1c412d48 2021-06-25 op save_excursion(&place, buffer);
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");
401 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
405 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
407 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
408 2b2d2872 2021-06-20 op message("No previous page");
412 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
414 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
415 2b2d2872 2021-06-20 op message("No next page");
419 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
421 95a8c791 2021-08-26 op message(NULL);
425 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
429 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
434 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
435 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
437 2b2d2872 2021-06-20 op if (thiskey.meta)
438 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
440 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
442 2b2d2872 2021-06-20 op if (thiskey.meta)
443 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
447 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
449 2b2d2872 2021-06-20 op struct tab *tab, *t;
451 83dce83d 2021-07-17 op tab = current_tab;
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);
458 90730426 2021-07-21 op message("Can't close the only tab.");
463 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
465 2b2d2872 2021-06-20 op struct tab *t, *i;
467 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
468 83dce83d 2021-07-17 op if (t == current_tab)
471 05de8ac3 2022-01-06 op kill_tab(t, 0);
476 6c74799d 2022-01-05 op cmd_tab_undo_close(struct buffer *buffer)
478 6c74799d 2022-01-05 op struct tab *t;
480 6c74799d 2022-01-05 op if ((t = unkill_tab()) == NULL) {
481 6c74799d 2022-01-05 op message("No recently-closed tabs");
485 6c74799d 2022-01-05 op switch_to_tab(t);
489 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
491 2b2d2872 2021-06-20 op const char *url;
493 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
494 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
496 55eb4d95 2021-08-12 op new_tab(url, NULL, NULL);
500 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
502 83dce83d 2021-07-17 op struct tab *t;
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);
510 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
512 83dce83d 2021-07-17 op struct tab *t;
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);
520 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
522 83dce83d 2021-07-17 op struct tab *t;
524 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
525 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
527 2b2d2872 2021-06-20 op if (t == NULL)
528 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
530 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
534 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
536 83dce83d 2021-07-17 op struct tab *t;
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);
541 32ac17a4 2021-08-12 op if (t == NULL)
542 32ac17a4 2021-08-12 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
544 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
548 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
550 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
558 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
560 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
568 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
570 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
580 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
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);
587 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
589 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
599 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
601 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
605 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
607 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
611 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
613 c1a72389 2021-07-15 op struct line *l;
615 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
621 c1a72389 2021-07-15 op if (l == NULL) {
622 c1a72389 2021-07-15 op message("No links found");
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));
632 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
634 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
642 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
644 c1a72389 2021-07-15 op struct line *l;
646 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
655 c1a72389 2021-07-15 op if (l == NULL) {
656 c1a72389 2021-07-15 op message("No headings found");
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));
667 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
669 61251035 2021-06-26 op if (fill_column == INT_MAX)
672 61251035 2021-06-26 op fill_column += 2;
673 61251035 2021-06-26 op message("fill-column: %d", fill_column);
675 61251035 2021-06-26 op ui_schedule_redraw();
679 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
681 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
684 61251035 2021-06-26 op fill_column -= 2;
685 61251035 2021-06-26 op message("fill-column: %d", fill_column);
687 61251035 2021-06-26 op ui_schedule_redraw();
691 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
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");
697 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
699 2b2d2872 2021-06-20 op ui_schedule_redraw();
703 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
705 bd4a08a7 2022-11-07 op char *line, *c, *n;
707 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
709 2b2d2872 2021-06-20 op minibuffer_taint_hist();
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')
715 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
717 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
719 b1e1e41a 2021-07-14 op recompute_completions(0);
723 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
725 bd4a08a7 2022-11-07 op char *line, *c, *p;
727 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
729 2b2d2872 2021-06-20 op minibuffer_taint_hist();
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)
735 bd4a08a7 2022-11-07 op p = utf8_prev_cp(c-1, line);
737 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
738 2b2d2872 2021-06-20 op buffer->cpoff--;
740 b1e1e41a 2021-07-14 op recompute_completions(0);
744 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
746 bd4a08a7 2022-11-07 op char *line, *c;
748 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
750 2b2d2872 2021-06-20 op minibuffer_taint_hist();
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);
756 b1e1e41a 2021-07-14 op recompute_completions(0);
760 067b7ffd 2022-04-15 op cmd_mini_kill_whole_line(struct buffer *buffer)
762 067b7ffd 2022-04-15 op GUARD_READ_ONLY();
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;
770 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
772 2b2d2872 2021-06-20 op if (!in_minibuffer)
775 2b2d2872 2021-06-20 op ministate.abortfn();
779 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
781 27dbcaab 2022-04-13 op struct vline *vl;
783 2b2d2872 2021-06-20 op if (!in_minibuffer)
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");
795 2b2d2872 2021-06-20 op minibuffer_taint_hist();
796 2b2d2872 2021-06-20 op ministate.donefn();
800 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
802 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
803 2b2d2872 2021-06-20 op message("No history");
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");
814 2b2d2872 2021-06-20 op ministate.hist_off--;
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);
824 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
826 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
827 2b2d2872 2021-06-20 op message("No history");
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");
838 2b2d2872 2021-06-20 op ministate.hist_off++;
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);
848 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
850 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
853 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
854 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
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;
861 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
865 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
867 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
870 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
871 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
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);
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;
884 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
886 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
889 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
893 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
895 8a3b5609 2021-07-15 op message("Zzz...");
896 8a3b5609 2021-07-15 op ui_suspend();
900 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
902 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
904 987d9c88 2021-07-15 op if (dont_wrap_pre)
905 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
907 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
909 987d9c88 2021-07-15 op ui_schedule_redraw();
913 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
915 de190a2b 2021-07-17 op struct vline *vl;
917 de190a2b 2021-07-17 op if (!in_minibuffer)
920 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
922 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
923 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
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);
929 de190a2b 2021-07-17 op if (vl == NULL)
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;
938 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
940 de190a2b 2021-07-17 op struct vline *vl;
942 de190a2b 2021-07-17 op if (!in_minibuffer)
945 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
947 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
948 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
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);
954 de190a2b 2021-07-17 op if (vl == NULL)
957 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
958 de190a2b 2021-07-17 op buffer->current_line = vl;
962 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
964 65340174 2021-07-21 op ui_other_window();
968 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
970 167131d5 2021-07-24 op if (!in_minibuffer)
973 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
974 167131d5 2021-07-24 op if (buffer->current_line == NULL)
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;
983 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
985 167131d5 2021-07-24 op if (!in_minibuffer)
988 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
989 167131d5 2021-07-24 op if (buffer->current_line == NULL)
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;
998 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
1000 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1004 eeebca22 2022-01-11 op cmd_cache_info(struct buffer *buffer)
1006 eeebca22 2022-01-11 op size_t npages, tot;
1007 eeebca22 2022-01-11 op char fmt[FMT_SCALED_STRSIZE];
1009 eeebca22 2022-01-11 op mcache_info(&npages, &tot);
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);
1014 bb5abe9f 2022-01-13 op message("pages: %zu, total: %zu", npages, tot);
1018 ed504b9e 2022-02-07 op cmd_reply_last_input(struct buffer *buffer)
1020 ed504b9e 2022-02-07 op GUARD_RECURSIVE_MINIBUFFER();
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");
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);
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);
1038 868b3a8f 2022-04-13 op cmd_write_buffer(struct buffer *buffer)
1040 868b3a8f 2022-04-13 op const char *f, *url;
1041 868b3a8f 2022-04-13 op char path[PATH_MAX];
1043 868b3a8f 2022-04-13 op GUARD_RECURSIVE_MINIBUFFER();
1045 868b3a8f 2022-04-13 op if (safe_mode) {
1046 868b3a8f 2022-04-13 op message("Can't write buffer in safe-mode.");
1050 868b3a8f 2022-04-13 op url = current_tab->hist_cur->h;
1052 868b3a8f 2022-04-13 op if ((f = strrchr(url, '/')) != NULL)
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";
1059 868b3a8f 2022-04-13 op f = "index.txt";
1062 868b3a8f 2022-04-13 op strlcpy(path, download_path, sizeof(path));
1063 868b3a8f 2022-04-13 op strlcat(path, f, sizeof(path));
1065 868b3a8f 2022-04-13 op ui_read("Write file", write_buffer, current_tab, path);