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 450a89f7 2021-07-12 op #include "minibuffer.h"
26 1fce2e75 2021-08-14 op #include "session.h"
27 2b2d2872 2021-06-20 op #include "telescope.h"
28 d1a0f2a3 2021-07-12 op #include "ui.h"
29 5caf7d67 2021-07-12 op #include "utf8.h"
31 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
33 ca231710 2021-07-15 op if (in_minibuffer) { \
34 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
35 ca231710 2021-07-15 op "is not yet available."); \
40 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
42 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
43 5a3c3ede 2021-07-19 op message("text is read-only"); \
48 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
49 c4c82003 2021-07-01 op static inline int
50 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
52 c4c82003 2021-07-01 op struct vline *vl;
55 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
57 963c680c 2021-07-05 op vl = buffer->current_line;
60 c4c82003 2021-07-01 op while (n != 0) {
62 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
63 c4c82003 2021-07-01 op if (vl == NULL)
65 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
67 c4c82003 2021-07-01 op buffer->current_line = vl;
70 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
71 c4c82003 2021-07-01 op if (vl == NULL)
73 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
75 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
76 6e6c6afb 2021-07-14 op buffer->line_off--;
77 c4c82003 2021-07-01 op buffer->top_line = vl;
79 c4c82003 2021-07-01 op buffer->current_line = vl;
90 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
92 c4c82003 2021-07-01 op forward_line(buffer, -1);
96 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
98 c4c82003 2021-07-01 op forward_line(buffer, +1);
102 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
104 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
105 2b2d2872 2021-06-20 op buffer->cpoff--;
109 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
111 2b2d2872 2021-06-20 op size_t len = 0;
113 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
116 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
117 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
118 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
119 2b2d2872 2021-06-20 op buffer->cpoff = len;
123 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
126 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
127 2b2d2872 2021-06-20 op message("No previous paragraph");
130 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
131 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
135 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
138 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
139 2b2d2872 2021-06-20 op message("No next paragraph");
142 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
143 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
147 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
149 2b2d2872 2021-06-20 op buffer->cpoff = 0;
153 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
155 2b2d2872 2021-06-20 op struct vline *vl;
157 2b2d2872 2021-06-20 op vl = buffer->current_line;
158 a87cfde9 2021-07-19 op if (vl == NULL || vl->line == NULL)
160 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
164 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
166 95a8c791 2021-08-26 op ui_schedule_redraw();
170 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
172 e39920a9 2021-07-07 op struct vline *vl;
175 028fff57 2021-07-30 op if (buffer->top_line == NULL)
178 028fff57 2021-07-30 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
182 028fff57 2021-07-30 op buffer->top_line = vl;
184 028fff57 2021-07-30 op if (vl->parent->flags & L_HIDDEN)
190 41b1ed04 2021-07-21 op buffer->line_off--;
192 028fff57 2021-07-30 op forward_line(buffer, -1);
196 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
198 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
202 028fff57 2021-07-30 op if (buffer->top_line == NULL)
205 028fff57 2021-07-30 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
206 028fff57 2021-07-30 op if (buffer->top_line->parent->flags & L_HIDDEN)
211 2b2d2872 2021-06-20 op buffer->line_off++;
215 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
217 64923c4b 2021-07-15 op struct vline *vl;
220 b471d670 2021-07-24 op if (buffer->top_line == NULL)
223 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
224 64923c4b 2021-07-15 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
225 64923c4b 2021-07-15 op if (vl == NULL)
227 eab11449 2021-07-19 op buffer->line_off--;
228 64923c4b 2021-07-15 op buffer->top_line = vl;
229 64923c4b 2021-07-15 op forward_line(buffer, -1);
234 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
238 b471d670 2021-07-24 op if (buffer->top_line == NULL)
241 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
242 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
245 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
247 eab11449 2021-07-19 op buffer->line_off++;
252 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
254 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
255 c4c82003 2021-07-01 op buffer->cpoff = 0;
256 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
257 2b2d2872 2021-06-20 op buffer->line_off = 0;
261 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
263 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
265 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
268 f04d2fc5 2021-07-18 op /* deal with invisible lines */
269 f04d2fc5 2021-07-18 op if (buffer->current_line->parent->flags & L_HIDDEN)
270 f04d2fc5 2021-07-18 op forward_line(buffer, -1);
272 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
276 5b3e45c1 2021-01-02 op kill_telescope_cb(int r, struct tab *tab)
279 5b3e45c1 2021-01-02 op save_session();
280 5b3e45c1 2021-01-02 op event_loopbreak();
285 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
287 5b3e45c1 2021-01-02 op yornp("really quit?", kill_telescope_cb, NULL);
291 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
293 2b2d2872 2021-06-20 op struct vline *vl;
294 963c680c 2021-07-05 op struct line *l;
296 2b2d2872 2021-06-20 op vl = buffer->current_line;
298 a87cfde9 2021-07-19 op if (vl == NULL)
301 963c680c 2021-07-05 op switch (vl->parent->type) {
302 963c680c 2021-07-05 op case LINE_LINK:
303 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, vl->parent->alt, NULL,
304 ed21a9a1 2022-01-11 op LU_MODE_NOCACHE);
306 963c680c 2021-07-05 op case LINE_PRE_START:
307 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
308 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
309 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
311 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
312 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
313 6e6c6afb 2021-07-14 op buffer->line_max--;
315 6e6c6afb 2021-07-14 op buffer->line_max++;
324 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
326 2b2d2872 2021-06-20 op struct vline *vl;
328 2b2d2872 2021-06-20 op vl = buffer->current_line;
329 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
332 55eb4d95 2021-08-12 op new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
336 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
338 5d0feb4b 2021-06-23 op struct excursion place;
340 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
343 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
344 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
345 2b2d2872 2021-06-20 op message("No previous link");
348 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
352 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
354 5d0feb4b 2021-06-23 op struct excursion place;
356 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
359 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
360 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
361 2b2d2872 2021-06-20 op message("No next link");
364 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
367 1c412d48 2021-06-25 op static inline int
368 1c412d48 2021-06-25 op is_heading(const struct line *l)
370 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
371 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
372 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
376 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
378 1c412d48 2021-06-25 op struct excursion place;
380 1c412d48 2021-06-25 op save_excursion(&place, buffer);
383 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
384 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
385 1c412d48 2021-06-25 op message("No previous heading");
388 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
392 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
394 1c412d48 2021-06-25 op struct excursion place;
396 1c412d48 2021-06-25 op save_excursion(&place, buffer);
399 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
400 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
401 1c412d48 2021-06-25 op message("No next heading");
404 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
408 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
410 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
411 2b2d2872 2021-06-20 op message("No previous page");
413 83dce83d 2021-07-17 op start_loading_anim(current_tab);
417 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
419 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
420 2b2d2872 2021-06-20 op message("No next page");
422 83dce83d 2021-07-17 op start_loading_anim(current_tab);
426 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
428 95a8c791 2021-08-26 op message(NULL);
432 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
436 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
438 004fe817 2021-07-24 op enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
439 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
441 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
442 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
444 2b2d2872 2021-06-20 op if (thiskey.meta)
445 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
447 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
449 2b2d2872 2021-06-20 op if (thiskey.meta)
450 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
454 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
456 2b2d2872 2021-06-20 op struct tab *tab, *t;
458 83dce83d 2021-07-17 op tab = current_tab;
460 90730426 2021-07-21 op if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
461 90730426 2021-07-21 op (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
462 90730426 2021-07-21 op switch_to_tab(t);
463 05de8ac3 2022-01-06 op kill_tab(tab, 0);
465 90730426 2021-07-21 op message("Can't close the only tab.");
470 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
472 2b2d2872 2021-06-20 op struct tab *t, *i;
474 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
475 83dce83d 2021-07-17 op if (t == current_tab)
478 05de8ac3 2022-01-06 op kill_tab(t, 0);
483 6c74799d 2022-01-05 op cmd_tab_undo_close(struct buffer *buffer)
485 6c74799d 2022-01-05 op struct tab *t;
487 6c74799d 2022-01-05 op if ((t = unkill_tab()) == NULL) {
488 6c74799d 2022-01-05 op message("No recently-closed tabs");
492 6c74799d 2022-01-05 op switch_to_tab(t);
496 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
498 2b2d2872 2021-06-20 op const char *url;
500 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
501 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
503 55eb4d95 2021-08-12 op new_tab(url, NULL, NULL);
507 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
509 83dce83d 2021-07-17 op struct tab *t;
511 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
512 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
513 2ddbda6b 2021-07-17 op switch_to_tab(t);
517 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
519 83dce83d 2021-07-17 op struct tab *t;
521 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
522 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
523 2ddbda6b 2021-07-17 op switch_to_tab(t);
527 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
529 83dce83d 2021-07-17 op struct tab *t;
531 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
532 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
534 2b2d2872 2021-06-20 op if (t == NULL)
535 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
537 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
541 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
543 83dce83d 2021-07-17 op struct tab *t;
545 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
546 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
548 32ac17a4 2021-08-12 op if (t == NULL)
549 32ac17a4 2021-08-12 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
551 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
555 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
557 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
559 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
560 65601367 2021-07-14 op NULL, compl_ts, NULL);
561 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
565 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
567 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
569 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
570 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
571 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
575 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
577 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
579 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
580 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
581 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
582 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
583 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
587 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
589 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL,
590 ed21a9a1 2022-01-11 op LU_MODE_NOHIST|LU_MODE_NOCACHE);
594 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
596 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
598 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
600 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
601 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
602 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
606 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
608 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
612 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
614 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
618 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
620 c1a72389 2021-07-15 op struct line *l;
622 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
624 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
625 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
626 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
628 c1a72389 2021-07-15 op if (l == NULL) {
629 c1a72389 2021-07-15 op message("No links found");
633 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
634 c1a72389 2021-07-15 op NULL, compl_ls, l);
635 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
639 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
641 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
643 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
644 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
645 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
649 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
651 c1a72389 2021-07-15 op struct line *l;
653 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
655 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
656 c1a72389 2021-07-15 op while (l != NULL &&
657 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
658 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
659 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
660 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
662 c1a72389 2021-07-15 op if (l == NULL) {
663 c1a72389 2021-07-15 op message("No headings found");
667 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
668 c1a72389 2021-07-15 op NULL, compl_toc, l);
669 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
670 edd9a650 2021-07-15 op sizeof(ministate.prompt));
674 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
676 61251035 2021-06-26 op if (fill_column == INT_MAX)
679 61251035 2021-06-26 op fill_column += 2;
680 61251035 2021-06-26 op message("fill-column: %d", fill_column);
682 61251035 2021-06-26 op ui_schedule_redraw();
686 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
688 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
691 61251035 2021-06-26 op fill_column -= 2;
692 61251035 2021-06-26 op message("fill-column: %d", fill_column);
694 61251035 2021-06-26 op ui_schedule_redraw();
698 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
700 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
701 2b2d2872 2021-06-20 op if (olivetti_mode)
702 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
704 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
706 2b2d2872 2021-06-20 op ui_schedule_redraw();
710 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
714 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
716 2b2d2872 2021-06-20 op minibuffer_taint_hist();
718 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
719 2b2d2872 2021-06-20 op if (*c == '\0')
721 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
723 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
725 b1e1e41a 2021-07-14 op recompute_completions(0);
729 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
731 2b2d2872 2021-06-20 op char *c, *p, *start;
733 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
735 2b2d2872 2021-06-20 op minibuffer_taint_hist();
737 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
738 2b2d2872 2021-06-20 op start = buffer->current_line->line;
739 2b2d2872 2021-06-20 op if (c == start)
741 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
743 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
744 2b2d2872 2021-06-20 op buffer->cpoff--;
746 b1e1e41a 2021-07-14 op recompute_completions(0);
750 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
754 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
756 2b2d2872 2021-06-20 op minibuffer_taint_hist();
757 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
760 b1e1e41a 2021-07-14 op recompute_completions(0);
764 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
766 2b2d2872 2021-06-20 op if (!in_minibuffer)
769 2b2d2872 2021-06-20 op ministate.abortfn();
773 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
775 2b2d2872 2021-06-20 op if (!in_minibuffer)
778 2b2d2872 2021-06-20 op minibuffer_taint_hist();
779 2b2d2872 2021-06-20 op ministate.donefn();
783 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
785 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
786 2b2d2872 2021-06-20 op message("No history");
790 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
791 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
792 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
793 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
794 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
795 fc14510d 2021-07-14 op message("No prev history item");
797 2b2d2872 2021-06-20 op ministate.hist_off--;
800 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
801 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
805 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
807 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
808 2b2d2872 2021-06-20 op message("No history");
812 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
813 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
814 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
815 2b2d2872 2021-06-20 op ministate.hist_off = 0;
816 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
817 fc14510d 2021-07-14 op message("No next history item");
819 2b2d2872 2021-06-20 op ministate.hist_off++;
822 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
823 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
827 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
829 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
832 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
834 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
835 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
837 e7b982f4 2021-07-14 op forward_line(buffer, -1);
839 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
840 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
844 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
846 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
849 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
851 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
852 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
854 e7b982f4 2021-07-14 op forward_line(buffer, +1);
856 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
857 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
861 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
863 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
866 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
870 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
872 8a3b5609 2021-07-15 op message("Zzz...");
873 8a3b5609 2021-07-15 op ui_suspend();
877 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
879 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
881 987d9c88 2021-07-15 op if (dont_wrap_pre)
882 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
884 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
886 987d9c88 2021-07-15 op ui_schedule_redraw();
890 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
892 de190a2b 2021-07-17 op struct vline *vl;
894 de190a2b 2021-07-17 op if (!in_minibuffer)
897 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
899 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
900 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
902 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
903 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
904 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
906 de190a2b 2021-07-17 op if (vl == NULL)
909 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
910 de190a2b 2021-07-17 op buffer->top_line = vl;
911 de190a2b 2021-07-17 op buffer->current_line = vl;
915 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
917 de190a2b 2021-07-17 op struct vline *vl;
919 de190a2b 2021-07-17 op if (!in_minibuffer)
922 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
924 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
925 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
927 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
928 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
929 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
931 de190a2b 2021-07-17 op if (vl == NULL)
934 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
935 de190a2b 2021-07-17 op buffer->current_line = vl;
939 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
941 65340174 2021-07-21 op ui_other_window();
945 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
947 167131d5 2021-07-24 op if (!in_minibuffer)
950 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
951 167131d5 2021-07-24 op if (buffer->current_line == NULL)
954 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
955 167131d5 2021-07-24 op cmd_scroll_up(buffer);
956 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
960 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
962 167131d5 2021-07-24 op if (!in_minibuffer)
965 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
966 167131d5 2021-07-24 op if (buffer->current_line == NULL)
969 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
970 167131d5 2021-07-24 op cmd_scroll_down(buffer);
971 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
975 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
977 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);