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 e5a2797f 2021-07-13 op #include "defaults.h"
22 450a89f7 2021-07-12 op #include "minibuffer.h"
23 2b2d2872 2021-06-20 op #include "telescope.h"
24 d1a0f2a3 2021-07-12 op #include "ui.h"
25 5caf7d67 2021-07-12 op #include "utf8.h"
27 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
28 c4c82003 2021-07-01 op static inline int
29 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
31 c4c82003 2021-07-01 op struct vline *vl;
34 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
36 963c680c 2021-07-05 op vl = buffer->current_line;
39 c4c82003 2021-07-01 op while (n != 0) {
41 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
42 c4c82003 2021-07-01 op if (vl == NULL)
44 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
46 c4c82003 2021-07-01 op buffer->current_line = vl;
49 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
50 c4c82003 2021-07-01 op if (vl == NULL)
52 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
54 c4c82003 2021-07-01 op if (buffer->current_line == buffer->top_line)
55 c4c82003 2021-07-01 op buffer->top_line = vl;
56 c4c82003 2021-07-01 op buffer->current_line = vl;
67 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
69 c4c82003 2021-07-01 op forward_line(buffer, -1);
73 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
75 c4c82003 2021-07-01 op forward_line(buffer, +1);
79 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
81 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
82 2b2d2872 2021-06-20 op buffer->cpoff--;
86 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
88 2b2d2872 2021-06-20 op size_t len = 0;
90 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
91 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
92 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
93 2b2d2872 2021-06-20 op buffer->cpoff = len;
97 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
100 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
101 2b2d2872 2021-06-20 op message("No previous paragraph");
104 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
105 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
109 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
112 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
113 2b2d2872 2021-06-20 op message("No next 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_move_beginning_of_line(struct buffer *buffer)
123 2b2d2872 2021-06-20 op buffer->cpoff = 0;
127 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
129 2b2d2872 2021-06-20 op struct vline *vl;
131 2b2d2872 2021-06-20 op vl = buffer->current_line;
132 2b2d2872 2021-06-20 op if (vl->line == NULL)
134 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
138 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
140 2b2d2872 2021-06-20 op ui_schedule_redraw();
144 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
146 e39920a9 2021-07-07 op struct vline *vl;
148 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
152 e39920a9 2021-07-07 op forward_line(buffer, -1);
154 2b2d2872 2021-06-20 op buffer->line_off--;
155 e39920a9 2021-07-07 op buffer->top_line = vl;
159 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
161 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
164 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
165 2b2d2872 2021-06-20 op buffer->line_off++;
169 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
171 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
175 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
177 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
181 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
183 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
184 c4c82003 2021-07-01 op buffer->cpoff = 0;
185 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
186 2b2d2872 2021-06-20 op buffer->line_off = 0;
190 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
192 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
193 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
197 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
199 2b2d2872 2021-06-20 op save_session();
200 2b2d2872 2021-06-20 op event_loopbreak();
204 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
206 2b2d2872 2021-06-20 op struct vline *vl;
207 963c680c 2021-07-05 op struct line *l;
209 2b2d2872 2021-06-20 op vl = buffer->current_line;
210 963c680c 2021-07-05 op switch (vl->parent->type) {
211 963c680c 2021-07-05 op case LINE_LINK:
212 963c680c 2021-07-05 op load_url_in_tab(current_tab(), vl->parent->alt);
214 963c680c 2021-07-05 op case LINE_PRE_START:
215 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
216 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
217 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
219 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
228 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
230 2b2d2872 2021-06-20 op struct vline *vl;
232 2b2d2872 2021-06-20 op vl = buffer->current_line;
233 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
236 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
240 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
242 5d0feb4b 2021-06-23 op struct excursion place;
244 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
247 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
248 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
249 2b2d2872 2021-06-20 op message("No previous link");
252 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
256 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
258 5d0feb4b 2021-06-23 op struct excursion place;
260 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
263 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
264 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
265 2b2d2872 2021-06-20 op message("No next link");
268 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
271 1c412d48 2021-06-25 op static inline int
272 1c412d48 2021-06-25 op is_heading(const struct line *l)
274 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
275 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
276 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
280 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
282 1c412d48 2021-06-25 op struct excursion place;
284 1c412d48 2021-06-25 op save_excursion(&place, buffer);
287 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
288 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
289 1c412d48 2021-06-25 op message("No previous heading");
292 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
296 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
298 1c412d48 2021-06-25 op struct excursion place;
300 1c412d48 2021-06-25 op save_excursion(&place, buffer);
303 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
304 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
305 1c412d48 2021-06-25 op message("No next heading");
308 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
312 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
314 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
316 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
317 2b2d2872 2021-06-20 op message("No previous page");
319 2b2d2872 2021-06-20 op start_loading_anim(tab);
323 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
325 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
327 2b2d2872 2021-06-20 op if (!load_next_page(tab))
328 2b2d2872 2021-06-20 op message("No next page");
330 2b2d2872 2021-06-20 op start_loading_anim(tab);
334 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
336 2b2d2872 2021-06-20 op message(NULL);
340 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
344 2b2d2872 2021-06-20 op if (in_minibuffer) {
345 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
349 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
350 e5a2797f 2021-07-13 op &eecmd_history, NULL, NULL);
352 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
353 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
355 2b2d2872 2021-06-20 op if (thiskey.meta)
356 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
358 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
360 2b2d2872 2021-06-20 op if (thiskey.meta)
361 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
365 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
367 2b2d2872 2021-06-20 op struct tab *tab, *t;
369 2b2d2872 2021-06-20 op tab = current_tab();
370 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
371 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
372 2b2d2872 2021-06-20 op message("Can't close the only tab.");
376 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
377 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
379 2b2d2872 2021-06-20 op stop_tab(tab);
381 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
382 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
383 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
386 2b2d2872 2021-06-20 op switch_to_tab(t);
390 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
392 2b2d2872 2021-06-20 op struct tab *t, *i;
394 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
395 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
399 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
405 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
407 2b2d2872 2021-06-20 op const char *url;
409 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
410 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
412 2b2d2872 2021-06-20 op new_tab(url);
416 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
418 2b2d2872 2021-06-20 op struct tab *tab, *t;
420 2b2d2872 2021-06-20 op tab = current_tab();
421 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
423 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
424 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
425 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
426 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
430 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
432 2b2d2872 2021-06-20 op struct tab *tab, *t;
434 2b2d2872 2021-06-20 op tab = current_tab();
435 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
437 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
438 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
439 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
440 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
444 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
446 2b2d2872 2021-06-20 op struct tab *tab, *t;
448 2b2d2872 2021-06-20 op tab = current_tab();
449 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
450 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
452 2b2d2872 2021-06-20 op if (t == NULL)
453 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
455 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
459 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
461 2b2d2872 2021-06-20 op struct tab *tab, *t;
463 2b2d2872 2021-06-20 op tab = current_tab();
464 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
465 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
467 2b2d2872 2021-06-20 op if (t == NULL) {
468 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
469 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
471 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
473 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
477 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
479 2b2d2872 2021-06-20 op if (in_minibuffer) {
480 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
484 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
485 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
486 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
487 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
488 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
492 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
494 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
496 2b2d2872 2021-06-20 op if (in_minibuffer) {
497 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
501 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
502 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
503 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
504 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
505 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
509 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
511 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
513 e5a2797f 2021-07-13 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL,
515 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
516 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
517 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
521 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
523 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
527 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
529 2b2d2872 2021-06-20 op ui_toggle_side_window();
533 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
535 61251035 2021-06-26 op if (fill_column == INT_MAX)
538 61251035 2021-06-26 op fill_column += 2;
539 61251035 2021-06-26 op message("fill-column: %d", fill_column);
541 61251035 2021-06-26 op ui_schedule_redraw();
545 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
547 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
550 61251035 2021-06-26 op fill_column -= 2;
551 61251035 2021-06-26 op message("fill-column: %d", fill_column);
553 61251035 2021-06-26 op ui_schedule_redraw();
557 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
559 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
560 2b2d2872 2021-06-20 op if (olivetti_mode)
561 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
563 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
565 2b2d2872 2021-06-20 op ui_schedule_redraw();
569 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
573 2b2d2872 2021-06-20 op if (!in_minibuffer) {
574 2b2d2872 2021-06-20 op message("text is read-only");
578 2b2d2872 2021-06-20 op minibuffer_taint_hist();
580 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
581 2b2d2872 2021-06-20 op if (*c == '\0')
583 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
585 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
589 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
591 2b2d2872 2021-06-20 op char *c, *p, *start;
593 2b2d2872 2021-06-20 op if (!in_minibuffer) {
594 2b2d2872 2021-06-20 op message("text is read-only");
598 2b2d2872 2021-06-20 op minibuffer_taint_hist();
600 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
601 2b2d2872 2021-06-20 op start = buffer->current_line->line;
602 2b2d2872 2021-06-20 op if (c == start)
604 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
606 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
607 2b2d2872 2021-06-20 op buffer->cpoff--;
611 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
615 2b2d2872 2021-06-20 op if (!in_minibuffer) {
616 2b2d2872 2021-06-20 op message("text is read-only");
620 2b2d2872 2021-06-20 op minibuffer_taint_hist();
621 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
626 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
628 2b2d2872 2021-06-20 op if (!in_minibuffer)
631 2b2d2872 2021-06-20 op ministate.abortfn();
635 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
637 2b2d2872 2021-06-20 op if (!in_minibuffer)
640 2b2d2872 2021-06-20 op minibuffer_taint_hist();
641 2b2d2872 2021-06-20 op ministate.donefn();
645 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
647 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
648 2b2d2872 2021-06-20 op message("No history");
652 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
653 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
654 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
655 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
656 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
657 2b2d2872 2021-06-20 op message("No prev item");
659 2b2d2872 2021-06-20 op ministate.hist_off--;
662 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
663 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
667 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
669 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
670 2b2d2872 2021-06-20 op message("No history");
674 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
675 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
676 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
677 2b2d2872 2021-06-20 op ministate.hist_off = 0;
678 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
679 2b2d2872 2021-06-20 op message("No next item");
681 2b2d2872 2021-06-20 op ministate.hist_off++;
684 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
685 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;