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 2b2d2872 2021-06-20 op #include "telescope.h"
27 d1a0f2a3 2021-07-12 op #include "ui.h"
28 5caf7d67 2021-07-12 op #include "utf8.h"
30 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
32 ca231710 2021-07-15 op if (in_minibuffer) { \
33 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
34 ca231710 2021-07-15 op "is not yet available."); \
39 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
41 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
42 5a3c3ede 2021-07-19 op message("text is read-only"); \
47 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
48 c4c82003 2021-07-01 op static inline int
49 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
51 c4c82003 2021-07-01 op struct vline *vl;
54 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
56 963c680c 2021-07-05 op vl = buffer->current_line;
59 c4c82003 2021-07-01 op while (n != 0) {
61 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
62 c4c82003 2021-07-01 op if (vl == NULL)
64 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
66 c4c82003 2021-07-01 op buffer->current_line = vl;
69 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
70 c4c82003 2021-07-01 op if (vl == NULL)
72 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
74 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
75 6e6c6afb 2021-07-14 op buffer->line_off--;
76 c4c82003 2021-07-01 op buffer->top_line = vl;
78 c4c82003 2021-07-01 op buffer->current_line = vl;
89 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
91 c4c82003 2021-07-01 op forward_line(buffer, -1);
95 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
97 c4c82003 2021-07-01 op forward_line(buffer, +1);
101 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
103 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
104 2b2d2872 2021-06-20 op buffer->cpoff--;
108 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
110 2b2d2872 2021-06-20 op size_t len = 0;
112 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
115 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
116 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
117 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
118 2b2d2872 2021-06-20 op buffer->cpoff = len;
122 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
125 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
126 2b2d2872 2021-06-20 op message("No previous paragraph");
129 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
130 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
134 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
137 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
138 2b2d2872 2021-06-20 op message("No next paragraph");
141 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
142 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
146 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
148 2b2d2872 2021-06-20 op buffer->cpoff = 0;
152 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
154 2b2d2872 2021-06-20 op struct vline *vl;
156 2b2d2872 2021-06-20 op vl = buffer->current_line;
157 a87cfde9 2021-07-19 op if (vl == NULL || vl->line == NULL)
159 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
163 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
165 2b2d2872 2021-06-20 op ui_schedule_redraw();
169 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
171 e39920a9 2021-07-07 op struct vline *vl;
174 028fff57 2021-07-30 op if (buffer->top_line == NULL)
177 028fff57 2021-07-30 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
181 028fff57 2021-07-30 op buffer->top_line = vl;
183 028fff57 2021-07-30 op if (vl->parent->flags & L_HIDDEN)
189 41b1ed04 2021-07-21 op buffer->line_off--;
191 028fff57 2021-07-30 op forward_line(buffer, -1);
195 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
197 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
201 028fff57 2021-07-30 op if (buffer->top_line == NULL)
204 028fff57 2021-07-30 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
205 028fff57 2021-07-30 op if (buffer->top_line->parent->flags & L_HIDDEN)
210 2b2d2872 2021-06-20 op buffer->line_off++;
214 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
216 64923c4b 2021-07-15 op struct vline *vl;
219 b471d670 2021-07-24 op if (buffer->top_line == NULL)
222 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
223 64923c4b 2021-07-15 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
224 64923c4b 2021-07-15 op if (vl == NULL)
226 eab11449 2021-07-19 op buffer->line_off--;
227 64923c4b 2021-07-15 op buffer->top_line = vl;
228 64923c4b 2021-07-15 op forward_line(buffer, -1);
233 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
237 b471d670 2021-07-24 op if (buffer->top_line == NULL)
240 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
241 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
244 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
246 eab11449 2021-07-19 op buffer->line_off++;
251 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
253 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
254 c4c82003 2021-07-01 op buffer->cpoff = 0;
255 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
256 2b2d2872 2021-06-20 op buffer->line_off = 0;
260 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
262 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
264 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
267 f04d2fc5 2021-07-18 op /* deal with invisible lines */
268 f04d2fc5 2021-07-18 op if (buffer->current_line->parent->flags & L_HIDDEN)
269 f04d2fc5 2021-07-18 op forward_line(buffer, -1);
271 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
275 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
277 2b2d2872 2021-06-20 op save_session();
278 2b2d2872 2021-06-20 op event_loopbreak();
282 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
284 2b2d2872 2021-06-20 op struct vline *vl;
285 963c680c 2021-07-05 op struct line *l;
287 2b2d2872 2021-06-20 op vl = buffer->current_line;
289 a87cfde9 2021-07-19 op if (vl == NULL)
292 963c680c 2021-07-05 op switch (vl->parent->type) {
293 963c680c 2021-07-05 op case LINE_LINK:
294 bd3a3a95 2021-07-20 op load_url_in_tab(current_tab, vl->parent->alt, NULL);
296 963c680c 2021-07-05 op case LINE_PRE_START:
297 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
298 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
299 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
301 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
302 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
303 6e6c6afb 2021-07-14 op buffer->line_max--;
305 6e6c6afb 2021-07-14 op buffer->line_max++;
314 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
316 2b2d2872 2021-06-20 op struct vline *vl;
318 2b2d2872 2021-06-20 op vl = buffer->current_line;
319 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
322 bd3a3a95 2021-07-20 op new_tab(vl->parent->alt, current_tab->hist_cur->h);
326 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
328 5d0feb4b 2021-06-23 op struct excursion place;
330 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
333 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
334 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
335 2b2d2872 2021-06-20 op message("No previous link");
338 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
342 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
344 5d0feb4b 2021-06-23 op struct excursion place;
346 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
349 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
350 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
351 2b2d2872 2021-06-20 op message("No next link");
354 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
357 1c412d48 2021-06-25 op static inline int
358 1c412d48 2021-06-25 op is_heading(const struct line *l)
360 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
361 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
362 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
366 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
368 1c412d48 2021-06-25 op struct excursion place;
370 1c412d48 2021-06-25 op save_excursion(&place, buffer);
373 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
374 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
375 1c412d48 2021-06-25 op message("No previous heading");
378 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
382 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
384 1c412d48 2021-06-25 op struct excursion place;
386 1c412d48 2021-06-25 op save_excursion(&place, buffer);
389 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
390 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
391 1c412d48 2021-06-25 op message("No next heading");
394 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
398 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
400 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
401 2b2d2872 2021-06-20 op message("No previous page");
403 83dce83d 2021-07-17 op start_loading_anim(current_tab);
407 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
409 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
410 2b2d2872 2021-06-20 op message("No next page");
412 83dce83d 2021-07-17 op start_loading_anim(current_tab);
416 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
418 2b2d2872 2021-06-20 op message(NULL);
422 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
426 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
428 004fe817 2021-07-24 op enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
429 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
431 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
432 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
434 2b2d2872 2021-06-20 op if (thiskey.meta)
435 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
437 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
439 2b2d2872 2021-06-20 op if (thiskey.meta)
440 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
444 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
446 2b2d2872 2021-06-20 op struct tab *tab, *t;
448 83dce83d 2021-07-17 op tab = current_tab;
450 90730426 2021-07-21 op if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
451 90730426 2021-07-21 op (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
452 90730426 2021-07-21 op switch_to_tab(t);
453 90730426 2021-07-21 op free_tab(tab);
455 90730426 2021-07-21 op message("Can't close the only tab.");
460 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
462 2b2d2872 2021-06-20 op struct tab *t, *i;
464 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
465 83dce83d 2021-07-17 op if (t == current_tab)
473 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
475 2b2d2872 2021-06-20 op const char *url;
477 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
478 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
480 bd3a3a95 2021-07-20 op new_tab(url, NULL);
484 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
486 83dce83d 2021-07-17 op struct tab *t;
488 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
489 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
490 2ddbda6b 2021-07-17 op switch_to_tab(t);
494 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
496 83dce83d 2021-07-17 op struct tab *t;
498 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
499 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
500 2ddbda6b 2021-07-17 op switch_to_tab(t);
504 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
506 83dce83d 2021-07-17 op struct tab *t;
508 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
509 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
511 2b2d2872 2021-06-20 op if (t == NULL)
512 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
514 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
518 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
520 83dce83d 2021-07-17 op struct tab *t;
522 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
523 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
525 2b2d2872 2021-06-20 op if (t == NULL) {
526 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
527 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
529 83dce83d 2021-07-17 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
531 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
535 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
537 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
539 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
540 65601367 2021-07-14 op NULL, compl_ts, NULL);
541 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
545 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
547 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
549 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
550 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
551 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
552 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
553 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
557 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
559 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
561 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
562 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
563 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
564 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
565 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
569 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
571 bd3a3a95 2021-07-20 op load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL);
575 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
577 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
579 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
581 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark 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 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
589 bd3a3a95 2021-07-20 op load_url_in_tab(current_tab, "about:bookmarks", NULL);
593 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
595 2b2d2872 2021-06-20 op ui_toggle_side_window();
599 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
601 c1a72389 2021-07-15 op struct line *l;
603 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
605 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
606 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
607 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
609 c1a72389 2021-07-15 op if (l == NULL) {
610 c1a72389 2021-07-15 op message("No links found");
614 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
615 c1a72389 2021-07-15 op NULL, compl_ls, l);
616 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
620 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
622 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
624 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
625 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
626 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
630 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
632 c1a72389 2021-07-15 op struct line *l;
634 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
636 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
637 c1a72389 2021-07-15 op while (l != NULL &&
638 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
639 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
640 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
641 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
643 c1a72389 2021-07-15 op if (l == NULL) {
644 c1a72389 2021-07-15 op message("No headings found");
648 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
649 c1a72389 2021-07-15 op NULL, compl_toc, l);
650 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
651 edd9a650 2021-07-15 op sizeof(ministate.prompt));
655 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
657 61251035 2021-06-26 op if (fill_column == INT_MAX)
660 61251035 2021-06-26 op fill_column += 2;
661 61251035 2021-06-26 op message("fill-column: %d", fill_column);
663 61251035 2021-06-26 op ui_schedule_redraw();
667 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
669 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
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 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
681 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
682 2b2d2872 2021-06-20 op if (olivetti_mode)
683 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
685 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
687 2b2d2872 2021-06-20 op ui_schedule_redraw();
691 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
695 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
697 2b2d2872 2021-06-20 op minibuffer_taint_hist();
699 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
700 2b2d2872 2021-06-20 op if (*c == '\0')
702 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
704 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
706 b1e1e41a 2021-07-14 op recompute_completions(0);
710 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
712 2b2d2872 2021-06-20 op char *c, *p, *start;
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 start = buffer->current_line->line;
720 2b2d2872 2021-06-20 op if (c == start)
722 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
724 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
725 2b2d2872 2021-06-20 op buffer->cpoff--;
727 b1e1e41a 2021-07-14 op recompute_completions(0);
731 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
735 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
737 2b2d2872 2021-06-20 op minibuffer_taint_hist();
738 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
741 b1e1e41a 2021-07-14 op recompute_completions(0);
745 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
747 2b2d2872 2021-06-20 op if (!in_minibuffer)
750 2b2d2872 2021-06-20 op ministate.abortfn();
754 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
756 2b2d2872 2021-06-20 op if (!in_minibuffer)
759 2b2d2872 2021-06-20 op minibuffer_taint_hist();
760 2b2d2872 2021-06-20 op ministate.donefn();
764 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
766 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
767 2b2d2872 2021-06-20 op message("No history");
771 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
772 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
773 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
774 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
775 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
776 fc14510d 2021-07-14 op message("No prev history item");
778 2b2d2872 2021-06-20 op ministate.hist_off--;
781 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
782 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
786 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
788 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
789 2b2d2872 2021-06-20 op message("No history");
793 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
794 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
795 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
796 2b2d2872 2021-06-20 op ministate.hist_off = 0;
797 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
798 fc14510d 2021-07-14 op message("No next history item");
800 2b2d2872 2021-06-20 op ministate.hist_off++;
803 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
804 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
808 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
810 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
813 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
815 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
816 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
818 e7b982f4 2021-07-14 op forward_line(buffer, -1);
820 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
821 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
825 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
827 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
830 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
832 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
833 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
835 e7b982f4 2021-07-14 op forward_line(buffer, +1);
837 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
838 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
842 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
844 e7b982f4 2021-07-14 op struct vline *vl;
846 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
849 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
850 e7b982f4 2021-07-14 op if ((vl = buffer->current_line) == NULL)
853 e7b982f4 2021-07-14 op minibuffer_taint_hist();
854 e7b982f4 2021-07-14 op strlcpy(ministate.buf, vl->parent->line, sizeof(ministate.buf));
855 e7b982f4 2021-07-14 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
859 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
861 8a3b5609 2021-07-15 op message("Zzz...");
862 8a3b5609 2021-07-15 op ui_suspend();
866 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
868 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
870 987d9c88 2021-07-15 op if (dont_wrap_pre)
871 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
873 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
875 987d9c88 2021-07-15 op ui_schedule_redraw();
879 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
881 de190a2b 2021-07-17 op struct vline *vl;
883 de190a2b 2021-07-17 op if (!in_minibuffer)
886 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
888 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
889 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
891 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
892 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
893 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
895 de190a2b 2021-07-17 op if (vl == NULL)
898 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
899 de190a2b 2021-07-17 op buffer->top_line = vl;
900 de190a2b 2021-07-17 op buffer->current_line = vl;
904 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
906 de190a2b 2021-07-17 op struct vline *vl;
908 de190a2b 2021-07-17 op if (!in_minibuffer)
911 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
913 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
914 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
916 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
917 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
918 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
920 de190a2b 2021-07-17 op if (vl == NULL)
923 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
924 de190a2b 2021-07-17 op buffer->current_line = vl;
928 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
930 65340174 2021-07-21 op ui_other_window();
934 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
936 167131d5 2021-07-24 op if (!in_minibuffer)
939 167131d5 2021-07-24 op buffer = &ministate.compl.buffer;
940 167131d5 2021-07-24 op if (buffer->current_line == NULL)
943 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
944 167131d5 2021-07-24 op cmd_scroll_up(buffer);
945 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
949 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
951 167131d5 2021-07-24 op if (!in_minibuffer)
954 167131d5 2021-07-24 op buffer = &ministate.compl.buffer;
955 167131d5 2021-07-24 op if (buffer->current_line == NULL)
958 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
959 167131d5 2021-07-24 op cmd_scroll_down(buffer);
960 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;