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 2b2d2872 2021-06-20 op size_t len = 0;
115 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
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;
125 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
128 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
129 2b2d2872 2021-06-20 op message("No previous paragraph");
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);
137 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
140 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
141 2b2d2872 2021-06-20 op message("No next paragraph");
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);
149 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
151 2b2d2872 2021-06-20 op buffer->cpoff = 0;
155 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
157 2b2d2872 2021-06-20 op struct vline *vl;
159 2b2d2872 2021-06-20 op vl = buffer->current_line;
160 a87cfde9 2021-07-19 op if (vl == NULL || vl->line == NULL)
162 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
166 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
168 95a8c791 2021-08-26 op ui_schedule_redraw();
172 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
174 e39920a9 2021-07-07 op struct vline *vl;
177 028fff57 2021-07-30 op if (buffer->top_line == NULL)
180 028fff57 2021-07-30 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
184 028fff57 2021-07-30 op buffer->top_line = vl;
186 028fff57 2021-07-30 op if (vl->parent->flags & L_HIDDEN)
192 41b1ed04 2021-07-21 op buffer->line_off--;
194 028fff57 2021-07-30 op forward_line(buffer, -1);
198 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
200 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
204 028fff57 2021-07-30 op if (buffer->top_line == NULL)
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)
213 2b2d2872 2021-06-20 op buffer->line_off++;
217 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
219 64923c4b 2021-07-15 op struct vline *vl;
222 b471d670 2021-07-24 op if (buffer->top_line == NULL)
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)
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);
236 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
240 b471d670 2021-07-24 op if (buffer->top_line == NULL)
243 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
244 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
247 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
249 eab11449 2021-07-19 op buffer->line_off++;
254 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
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;
263 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
265 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
267 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
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);
274 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
278 5b3e45c1 2021-01-02 op kill_telescope_cb(int r, struct tab *tab)
281 5b3e45c1 2021-01-02 op save_session();
282 5b3e45c1 2021-01-02 op event_loopbreak();
287 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
289 5b3e45c1 2021-01-02 op yornp("really quit?", kill_telescope_cb, NULL);
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>
297 8f90b214 2022-08-16 op do_exec_command(const char *cmd, struct tab *t)
302 8f90b214 2022-08-16 op if (cmd == NULL)
307 8f90b214 2022-08-16 op switch (p = fork()) {
309 8f90b214 2022-08-16 op message("failed to fork: %s", strerror(errno));
312 8f90b214 2022-08-16 op execl("/bin/sh", "sh", "-c", cmd, NULL);
313 8f90b214 2022-08-16 op warn("exec \"%s\" failed", cmd);
318 8f90b214 2022-08-16 op if (waitpid(p, &s, 0) == -1) {
319 8f90b214 2022-08-16 op if (errno == EINTR)
325 8f90b214 2022-08-16 op ui_schedule_redraw();
326 8f90b214 2022-08-16 op /* rearrange_windows(); */
330 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
332 2b2d2872 2021-06-20 op struct vline *vl;
333 963c680c 2021-07-05 op struct line *l;
335 2b2d2872 2021-06-20 op vl = buffer->current_line;
337 a87cfde9 2021-07-19 op if (vl == NULL)
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);
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)
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--;
354 6e6c6afb 2021-07-14 op buffer->line_max++;
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,
361 8f90b214 2022-08-16 op snprintf(ministate.buf, sizeof(ministate.buf),
362 8f90b214 2022-08-16 op "xdg-open %s", vl->parent->alt);
370 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
372 2b2d2872 2021-06-20 op struct vline *vl;
374 2b2d2872 2021-06-20 op vl = buffer->current_line;
375 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
378 55eb4d95 2021-08-12 op new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
382 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
384 5d0feb4b 2021-06-23 op struct excursion place;
386 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
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");
394 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
398 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
400 5d0feb4b 2021-06-23 op struct excursion place;
402 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
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");
410 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
413 1c412d48 2021-06-25 op static inline int
414 1c412d48 2021-06-25 op is_heading(const struct line *l)
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;
422 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
424 1c412d48 2021-06-25 op struct excursion place;
426 1c412d48 2021-06-25 op save_excursion(&place, buffer);
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");
434 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
438 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
440 1c412d48 2021-06-25 op struct excursion place;
442 1c412d48 2021-06-25 op save_excursion(&place, buffer);
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");
450 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
454 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
456 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
457 2b2d2872 2021-06-20 op message("No previous page");
461 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
463 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
464 2b2d2872 2021-06-20 op message("No next page");
468 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
470 95a8c791 2021-08-26 op message(NULL);
474 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
478 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
483 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
484 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
486 2b2d2872 2021-06-20 op if (thiskey.meta)
487 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
489 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
491 2b2d2872 2021-06-20 op if (thiskey.meta)
492 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
496 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
498 2b2d2872 2021-06-20 op struct tab *tab, *t;
500 83dce83d 2021-07-17 op tab = current_tab;
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);
507 90730426 2021-07-21 op message("Can't close the only tab.");
512 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
514 2b2d2872 2021-06-20 op struct tab *t, *i;
516 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
517 83dce83d 2021-07-17 op if (t == current_tab)
520 05de8ac3 2022-01-06 op kill_tab(t, 0);
525 6c74799d 2022-01-05 op cmd_tab_undo_close(struct buffer *buffer)
527 6c74799d 2022-01-05 op struct tab *t;
529 6c74799d 2022-01-05 op if ((t = unkill_tab()) == NULL) {
530 6c74799d 2022-01-05 op message("No recently-closed tabs");
534 6c74799d 2022-01-05 op switch_to_tab(t);
538 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
540 2b2d2872 2021-06-20 op const char *url;
542 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
543 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
545 55eb4d95 2021-08-12 op new_tab(url, NULL, NULL);
549 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
551 83dce83d 2021-07-17 op struct tab *t;
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);
559 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
561 83dce83d 2021-07-17 op struct tab *t;
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);
569 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
571 83dce83d 2021-07-17 op struct tab *t;
573 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
574 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
576 2b2d2872 2021-06-20 op if (t == NULL)
577 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
579 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
583 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
585 83dce83d 2021-07-17 op struct tab *t;
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);
590 32ac17a4 2021-08-12 op if (t == NULL)
591 32ac17a4 2021-08-12 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
593 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
597 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
599 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
607 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
609 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
617 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
619 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
629 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
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);
636 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
638 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
648 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
650 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
654 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
656 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
660 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
662 c1a72389 2021-07-15 op struct line *l;
664 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
670 c1a72389 2021-07-15 op if (l == NULL) {
671 c1a72389 2021-07-15 op message("No links found");
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));
681 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
683 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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));
691 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
693 c1a72389 2021-07-15 op struct line *l;
695 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
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);
704 c1a72389 2021-07-15 op if (l == NULL) {
705 c1a72389 2021-07-15 op message("No headings found");
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));
716 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
718 61251035 2021-06-26 op if (fill_column == INT_MAX)
721 61251035 2021-06-26 op fill_column += 2;
722 61251035 2021-06-26 op message("fill-column: %d", fill_column);
724 61251035 2021-06-26 op ui_schedule_redraw();
728 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
730 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
733 61251035 2021-06-26 op fill_column -= 2;
734 61251035 2021-06-26 op message("fill-column: %d", fill_column);
736 61251035 2021-06-26 op ui_schedule_redraw();
740 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
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");
746 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
748 2b2d2872 2021-06-20 op ui_schedule_redraw();
752 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
756 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
758 2b2d2872 2021-06-20 op minibuffer_taint_hist();
760 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
761 2b2d2872 2021-06-20 op if (*c == '\0')
763 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
765 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
767 b1e1e41a 2021-07-14 op recompute_completions(0);
771 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
773 2b2d2872 2021-06-20 op char *c, *p, *start;
775 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
777 2b2d2872 2021-06-20 op minibuffer_taint_hist();
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)
783 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
785 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
786 2b2d2872 2021-06-20 op buffer->cpoff--;
788 b1e1e41a 2021-07-14 op recompute_completions(0);
792 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
796 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
798 2b2d2872 2021-06-20 op minibuffer_taint_hist();
799 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
802 b1e1e41a 2021-07-14 op recompute_completions(0);
806 067b7ffd 2022-04-15 op cmd_mini_kill_whole_line(struct buffer *buffer)
808 067b7ffd 2022-04-15 op GUARD_READ_ONLY();
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;
816 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
818 2b2d2872 2021-06-20 op if (!in_minibuffer)
821 2b2d2872 2021-06-20 op ministate.abortfn();
825 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
827 27dbcaab 2022-04-13 op struct vline *vl;
829 2b2d2872 2021-06-20 op if (!in_minibuffer)
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");
841 2b2d2872 2021-06-20 op minibuffer_taint_hist();
842 2b2d2872 2021-06-20 op ministate.donefn();
846 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
848 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
849 2b2d2872 2021-06-20 op message("No history");
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");
860 2b2d2872 2021-06-20 op ministate.hist_off--;
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);
870 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
872 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
873 2b2d2872 2021-06-20 op message("No history");
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");
884 2b2d2872 2021-06-20 op ministate.hist_off++;
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);
894 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
896 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
899 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
900 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
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;
907 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
911 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
913 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
916 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
917 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
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);
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;
930 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
932 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
935 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
939 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
941 8a3b5609 2021-07-15 op message("Zzz...");
942 8a3b5609 2021-07-15 op ui_suspend();
946 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
948 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
950 987d9c88 2021-07-15 op if (dont_wrap_pre)
951 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
953 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
955 987d9c88 2021-07-15 op ui_schedule_redraw();
959 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
961 de190a2b 2021-07-17 op struct vline *vl;
963 de190a2b 2021-07-17 op if (!in_minibuffer)
966 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
968 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
969 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
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);
975 de190a2b 2021-07-17 op if (vl == NULL)
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;
984 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
986 de190a2b 2021-07-17 op struct vline *vl;
988 de190a2b 2021-07-17 op if (!in_minibuffer)
991 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
993 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
994 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
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);
1000 de190a2b 2021-07-17 op if (vl == NULL)
1003 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
1004 de190a2b 2021-07-17 op buffer->current_line = vl;
1008 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
1010 65340174 2021-07-21 op ui_other_window();
1014 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
1016 167131d5 2021-07-24 op if (!in_minibuffer)
1019 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
1020 167131d5 2021-07-24 op if (buffer->current_line == NULL)
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;
1029 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
1031 167131d5 2021-07-24 op if (!in_minibuffer)
1034 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
1035 167131d5 2021-07-24 op if (buffer->current_line == NULL)
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;
1044 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
1046 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1050 eeebca22 2022-01-11 op cmd_cache_info(struct buffer *buffer)
1052 eeebca22 2022-01-11 op size_t npages, tot;
1053 eeebca22 2022-01-11 op char fmt[FMT_SCALED_STRSIZE];
1055 eeebca22 2022-01-11 op mcache_info(&npages, &tot);
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);
1060 bb5abe9f 2022-01-13 op message("pages: %zu, total: %zu", npages, tot);
1064 ed504b9e 2022-02-07 op cmd_reply_last_input(struct buffer *buffer)
1066 ed504b9e 2022-02-07 op GUARD_RECURSIVE_MINIBUFFER();
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");
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);
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);
1084 868b3a8f 2022-04-13 op cmd_write_buffer(struct buffer *buffer)
1086 868b3a8f 2022-04-13 op const char *f, *url;
1087 868b3a8f 2022-04-13 op char path[PATH_MAX];
1089 868b3a8f 2022-04-13 op GUARD_RECURSIVE_MINIBUFFER();
1091 868b3a8f 2022-04-13 op if (safe_mode) {
1092 868b3a8f 2022-04-13 op message("Can't write buffer in safe-mode.");
1096 868b3a8f 2022-04-13 op url = current_tab->hist_cur->h;
1098 868b3a8f 2022-04-13 op if ((f = strrchr(url, '/')) != NULL)
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";
1105 868b3a8f 2022-04-13 op f = "index.txt";
1108 868b3a8f 2022-04-13 op strlcpy(path, download_path, sizeof(path));
1109 868b3a8f 2022-04-13 op strlcat(path, f, sizeof(path));
1111 868b3a8f 2022-04-13 op ui_read("Write file", write_buffer, current_tab, path);