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 61251035 2021-06-26 op #include <limits.h>
18 2b2d2872 2021-06-20 op #include <stdlib.h>
19 61251035 2021-06-26 op #include <string.h>
21 b1e1e41a 2021-07-14 op #include "compl.h"
22 e5a2797f 2021-07-13 op #include "defaults.h"
23 450a89f7 2021-07-12 op #include "minibuffer.h"
24 2b2d2872 2021-06-20 op #include "telescope.h"
25 d1a0f2a3 2021-07-12 op #include "ui.h"
26 5caf7d67 2021-07-12 op #include "utf8.h"
28 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
30 ca231710 2021-07-15 op if (in_minibuffer) { \
31 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
32 ca231710 2021-07-15 op "is not yet available."); \
37 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
38 c4c82003 2021-07-01 op static inline int
39 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
41 c4c82003 2021-07-01 op struct vline *vl;
44 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
46 963c680c 2021-07-05 op vl = buffer->current_line;
49 c4c82003 2021-07-01 op while (n != 0) {
51 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
52 c4c82003 2021-07-01 op if (vl == NULL)
54 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
56 c4c82003 2021-07-01 op buffer->current_line = vl;
59 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
60 c4c82003 2021-07-01 op if (vl == NULL)
62 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
64 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
65 6e6c6afb 2021-07-14 op buffer->line_off--;
66 c4c82003 2021-07-01 op buffer->top_line = vl;
68 c4c82003 2021-07-01 op buffer->current_line = vl;
79 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
81 c4c82003 2021-07-01 op forward_line(buffer, -1);
85 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
87 c4c82003 2021-07-01 op forward_line(buffer, +1);
91 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
93 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
94 2b2d2872 2021-06-20 op buffer->cpoff--;
98 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
100 2b2d2872 2021-06-20 op size_t len = 0;
102 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
103 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
104 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
105 2b2d2872 2021-06-20 op buffer->cpoff = len;
109 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
112 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
113 2b2d2872 2021-06-20 op message("No previous paragraph");
116 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
117 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
121 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
124 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
125 2b2d2872 2021-06-20 op message("No next paragraph");
128 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
129 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
133 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
135 2b2d2872 2021-06-20 op buffer->cpoff = 0;
139 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
141 2b2d2872 2021-06-20 op struct vline *vl;
143 2b2d2872 2021-06-20 op vl = buffer->current_line;
144 2b2d2872 2021-06-20 op if (vl->line == NULL)
146 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
150 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
152 2b2d2872 2021-06-20 op ui_schedule_redraw();
156 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
158 e39920a9 2021-07-07 op struct vline *vl;
160 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
164 e39920a9 2021-07-07 op forward_line(buffer, -1);
166 e39920a9 2021-07-07 op buffer->top_line = vl;
170 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
172 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
175 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
176 2b2d2872 2021-06-20 op buffer->line_off++;
180 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
182 64923c4b 2021-07-15 op struct vline *vl;
185 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
186 64923c4b 2021-07-15 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
187 64923c4b 2021-07-15 op if (vl == NULL)
189 64923c4b 2021-07-15 op buffer->top_line = vl;
190 64923c4b 2021-07-15 op forward_line(buffer, -1);
195 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
199 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
200 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
203 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
209 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
211 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
212 c4c82003 2021-07-01 op buffer->cpoff = 0;
213 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
214 2b2d2872 2021-06-20 op buffer->line_off = 0;
218 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
220 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
221 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
225 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
227 2b2d2872 2021-06-20 op save_session();
228 2b2d2872 2021-06-20 op event_loopbreak();
232 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
234 2b2d2872 2021-06-20 op struct vline *vl;
235 963c680c 2021-07-05 op struct line *l;
237 2b2d2872 2021-06-20 op vl = buffer->current_line;
238 963c680c 2021-07-05 op switch (vl->parent->type) {
239 963c680c 2021-07-05 op case LINE_LINK:
240 83dce83d 2021-07-17 op load_url_in_tab(current_tab, vl->parent->alt);
242 963c680c 2021-07-05 op case LINE_PRE_START:
243 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
244 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
245 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
247 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
248 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
249 6e6c6afb 2021-07-14 op buffer->line_max--;
251 6e6c6afb 2021-07-14 op buffer->line_max++;
260 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
262 2b2d2872 2021-06-20 op struct vline *vl;
264 2b2d2872 2021-06-20 op vl = buffer->current_line;
265 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
268 fbadd395 2021-07-16 op new_tab(vl->parent->alt);
272 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
274 5d0feb4b 2021-06-23 op struct excursion place;
276 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
279 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
280 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
281 2b2d2872 2021-06-20 op message("No previous link");
284 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
288 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
290 5d0feb4b 2021-06-23 op struct excursion place;
292 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
295 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
296 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
297 2b2d2872 2021-06-20 op message("No next link");
300 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
303 1c412d48 2021-06-25 op static inline int
304 1c412d48 2021-06-25 op is_heading(const struct line *l)
306 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
307 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
308 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
312 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
314 1c412d48 2021-06-25 op struct excursion place;
316 1c412d48 2021-06-25 op save_excursion(&place, buffer);
319 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
320 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
321 1c412d48 2021-06-25 op message("No previous heading");
324 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
328 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
330 1c412d48 2021-06-25 op struct excursion place;
332 1c412d48 2021-06-25 op save_excursion(&place, buffer);
335 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
336 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
337 1c412d48 2021-06-25 op message("No next heading");
340 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
344 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
346 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
347 2b2d2872 2021-06-20 op message("No previous page");
349 83dce83d 2021-07-17 op start_loading_anim(current_tab);
353 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
355 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
356 2b2d2872 2021-06-20 op message("No next page");
358 83dce83d 2021-07-17 op start_loading_anim(current_tab);
362 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
364 2b2d2872 2021-06-20 op message(NULL);
368 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
372 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
374 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
375 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
377 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
378 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
380 2b2d2872 2021-06-20 op if (thiskey.meta)
381 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
383 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
385 2b2d2872 2021-06-20 op if (thiskey.meta)
386 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
390 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
392 2b2d2872 2021-06-20 op struct tab *tab, *t;
394 83dce83d 2021-07-17 op tab = current_tab;
395 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
396 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
397 2b2d2872 2021-06-20 op message("Can't close the only tab.");
401 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
402 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
404 2b2d2872 2021-06-20 op stop_tab(tab);
406 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
407 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
408 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
411 2b2d2872 2021-06-20 op switch_to_tab(t);
415 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
417 2b2d2872 2021-06-20 op struct tab *t, *i;
419 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
420 83dce83d 2021-07-17 op if (t == current_tab)
424 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
430 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
432 2b2d2872 2021-06-20 op const char *url;
434 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
435 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
437 2b2d2872 2021-06-20 op new_tab(url);
441 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
443 83dce83d 2021-07-17 op struct tab *t;
445 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
446 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
447 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
448 83dce83d 2021-07-17 op current_tab = t;
452 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
454 83dce83d 2021-07-17 op struct tab *t;
456 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
457 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
458 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
459 83dce83d 2021-07-17 op current_tab = t;
463 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
465 83dce83d 2021-07-17 op struct tab *t;
467 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
468 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
470 2b2d2872 2021-06-20 op if (t == NULL)
471 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
473 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
477 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
479 83dce83d 2021-07-17 op struct tab *t;
481 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
482 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
484 2b2d2872 2021-06-20 op if (t == NULL) {
485 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
486 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
488 83dce83d 2021-07-17 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
490 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
494 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
496 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
498 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
499 65601367 2021-07-14 op NULL, compl_ts, NULL);
500 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
504 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
506 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
508 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
509 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
510 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
511 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
512 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
516 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
518 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
520 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
521 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
522 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
523 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
524 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
528 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
530 83dce83d 2021-07-17 op load_url_in_tab(current_tab, current_tab->hist_cur->h);
534 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
536 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
538 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
540 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
541 83dce83d 2021-07-17 op strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
542 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
546 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
548 83dce83d 2021-07-17 op load_url_in_tab(current_tab, "about:bookmarks");
552 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
554 2b2d2872 2021-06-20 op ui_toggle_side_window();
558 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
560 c1a72389 2021-07-15 op struct line *l;
562 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
564 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
565 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
566 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
568 c1a72389 2021-07-15 op if (l == NULL) {
569 c1a72389 2021-07-15 op message("No links found");
573 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
574 c1a72389 2021-07-15 op NULL, compl_ls, l);
575 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
579 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
581 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
583 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
584 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
585 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
589 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
591 c1a72389 2021-07-15 op struct line *l;
593 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
595 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
596 c1a72389 2021-07-15 op while (l != NULL &&
597 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
598 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
599 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
600 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
602 c1a72389 2021-07-15 op if (l == NULL) {
603 c1a72389 2021-07-15 op message("No headings found");
607 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
608 c1a72389 2021-07-15 op NULL, compl_toc, l);
609 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
610 edd9a650 2021-07-15 op sizeof(ministate.prompt));
614 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
616 61251035 2021-06-26 op if (fill_column == INT_MAX)
619 61251035 2021-06-26 op fill_column += 2;
620 61251035 2021-06-26 op message("fill-column: %d", fill_column);
622 61251035 2021-06-26 op ui_schedule_redraw();
626 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
628 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
631 61251035 2021-06-26 op fill_column -= 2;
632 61251035 2021-06-26 op message("fill-column: %d", fill_column);
634 61251035 2021-06-26 op ui_schedule_redraw();
638 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
640 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
641 2b2d2872 2021-06-20 op if (olivetti_mode)
642 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
644 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
646 2b2d2872 2021-06-20 op ui_schedule_redraw();
650 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
654 2b2d2872 2021-06-20 op if (!in_minibuffer) {
655 2b2d2872 2021-06-20 op message("text is read-only");
659 2b2d2872 2021-06-20 op minibuffer_taint_hist();
661 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
662 2b2d2872 2021-06-20 op if (*c == '\0')
664 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
666 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
668 b1e1e41a 2021-07-14 op recompute_completions(0);
672 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
674 2b2d2872 2021-06-20 op char *c, *p, *start;
676 2b2d2872 2021-06-20 op if (!in_minibuffer) {
677 2b2d2872 2021-06-20 op message("text is read-only");
681 2b2d2872 2021-06-20 op minibuffer_taint_hist();
683 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
684 2b2d2872 2021-06-20 op start = buffer->current_line->line;
685 2b2d2872 2021-06-20 op if (c == start)
687 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
689 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
690 2b2d2872 2021-06-20 op buffer->cpoff--;
692 b1e1e41a 2021-07-14 op recompute_completions(0);
696 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
700 2b2d2872 2021-06-20 op if (!in_minibuffer) {
701 2b2d2872 2021-06-20 op message("text is read-only");
705 2b2d2872 2021-06-20 op minibuffer_taint_hist();
706 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
709 b1e1e41a 2021-07-14 op recompute_completions(0);
713 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
715 2b2d2872 2021-06-20 op if (!in_minibuffer)
718 2b2d2872 2021-06-20 op ministate.abortfn();
722 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
724 2b2d2872 2021-06-20 op if (!in_minibuffer)
727 2b2d2872 2021-06-20 op minibuffer_taint_hist();
728 2b2d2872 2021-06-20 op ministate.donefn();
732 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
734 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
735 2b2d2872 2021-06-20 op message("No history");
739 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
740 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
741 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
742 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
743 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
744 fc14510d 2021-07-14 op message("No prev history item");
746 2b2d2872 2021-06-20 op ministate.hist_off--;
749 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
750 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
754 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
756 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
757 2b2d2872 2021-06-20 op message("No history");
761 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
762 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
763 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
764 2b2d2872 2021-06-20 op ministate.hist_off = 0;
765 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
766 fc14510d 2021-07-14 op message("No next history item");
768 2b2d2872 2021-06-20 op ministate.hist_off++;
771 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
772 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
776 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
778 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
781 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
783 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
784 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
786 e7b982f4 2021-07-14 op forward_line(buffer, -1);
788 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
789 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
793 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
795 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
798 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
800 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
801 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
803 e7b982f4 2021-07-14 op forward_line(buffer, +1);
805 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
806 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
810 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
812 e7b982f4 2021-07-14 op struct vline *vl;
814 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
817 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
818 e7b982f4 2021-07-14 op if ((vl = buffer->current_line) == NULL)
821 e7b982f4 2021-07-14 op minibuffer_taint_hist();
822 e7b982f4 2021-07-14 op strlcpy(ministate.buf, vl->parent->line, sizeof(ministate.buf));
823 e7b982f4 2021-07-14 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
827 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
829 8a3b5609 2021-07-15 op message("Zzz...");
830 8a3b5609 2021-07-15 op ui_suspend();
834 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
836 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
838 987d9c88 2021-07-15 op if (dont_wrap_pre)
839 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
841 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
843 987d9c88 2021-07-15 op ui_schedule_redraw();
847 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
849 de190a2b 2021-07-17 op struct vline *vl;
851 de190a2b 2021-07-17 op if (!in_minibuffer)
854 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
856 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
857 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
859 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
860 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
861 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
863 de190a2b 2021-07-17 op if (vl == NULL)
866 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
867 de190a2b 2021-07-17 op buffer->top_line = vl;
868 de190a2b 2021-07-17 op buffer->current_line = vl;
872 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
874 de190a2b 2021-07-17 op struct vline *vl;
876 de190a2b 2021-07-17 op if (!in_minibuffer)
879 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
881 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
882 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
884 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
885 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
886 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
888 de190a2b 2021-07-17 op if (vl == NULL)
891 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
892 de190a2b 2021-07-17 op buffer->current_line = vl;