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 2b2d2872 2021-06-20 op #include "telescope.h"
23 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
24 c4c82003 2021-07-01 op static inline int
25 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
27 c4c82003 2021-07-01 op struct vline *vl;
30 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
32 963c680c 2021-07-05 op vl = buffer->current_line;
35 c4c82003 2021-07-01 op while (n != 0) {
37 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
38 c4c82003 2021-07-01 op if (vl == NULL)
40 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
42 c4c82003 2021-07-01 op buffer->current_line = vl;
45 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
46 c4c82003 2021-07-01 op if (vl == NULL)
48 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
50 c4c82003 2021-07-01 op if (buffer->current_line == buffer->top_line)
51 c4c82003 2021-07-01 op buffer->top_line = vl;
52 c4c82003 2021-07-01 op buffer->current_line = vl;
63 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
65 c4c82003 2021-07-01 op forward_line(buffer, -1);
69 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
71 c4c82003 2021-07-01 op forward_line(buffer, +1);
75 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
77 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
78 2b2d2872 2021-06-20 op buffer->cpoff--;
82 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
84 2b2d2872 2021-06-20 op size_t len = 0;
86 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
87 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
88 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
89 2b2d2872 2021-06-20 op buffer->cpoff = len;
93 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
96 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
97 2b2d2872 2021-06-20 op message("No previous paragraph");
100 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
101 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
105 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
108 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
109 2b2d2872 2021-06-20 op message("No next paragraph");
112 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
113 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
117 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
119 2b2d2872 2021-06-20 op buffer->cpoff = 0;
123 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
125 2b2d2872 2021-06-20 op struct vline *vl;
127 2b2d2872 2021-06-20 op vl = buffer->current_line;
128 2b2d2872 2021-06-20 op if (vl->line == NULL)
130 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
134 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
136 2b2d2872 2021-06-20 op ui_schedule_redraw();
140 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
142 e39920a9 2021-07-07 op struct vline *vl;
144 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
148 e39920a9 2021-07-07 op forward_line(buffer, -1);
150 2b2d2872 2021-06-20 op buffer->line_off--;
151 e39920a9 2021-07-07 op buffer->top_line = vl;
155 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
157 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
160 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
161 2b2d2872 2021-06-20 op buffer->line_off++;
165 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
167 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
171 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
173 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
177 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
179 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
180 c4c82003 2021-07-01 op buffer->cpoff = 0;
181 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
182 2b2d2872 2021-06-20 op buffer->line_off = 0;
186 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
188 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
189 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
193 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
195 2b2d2872 2021-06-20 op save_session();
196 2b2d2872 2021-06-20 op event_loopbreak();
200 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
202 2b2d2872 2021-06-20 op struct vline *vl;
203 963c680c 2021-07-05 op struct line *l;
205 2b2d2872 2021-06-20 op vl = buffer->current_line;
206 963c680c 2021-07-05 op switch (vl->parent->type) {
207 963c680c 2021-07-05 op case LINE_LINK:
208 963c680c 2021-07-05 op load_url_in_tab(current_tab(), vl->parent->alt);
210 963c680c 2021-07-05 op case LINE_PRE_START:
211 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
212 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
213 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
215 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
224 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
226 2b2d2872 2021-06-20 op struct vline *vl;
228 2b2d2872 2021-06-20 op vl = buffer->current_line;
229 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
232 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
236 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
238 5d0feb4b 2021-06-23 op struct excursion place;
240 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
243 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
244 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
245 2b2d2872 2021-06-20 op message("No previous link");
248 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
252 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
254 5d0feb4b 2021-06-23 op struct excursion place;
256 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
259 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
260 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
261 2b2d2872 2021-06-20 op message("No next link");
264 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
267 1c412d48 2021-06-25 op static inline int
268 1c412d48 2021-06-25 op is_heading(const struct line *l)
270 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
271 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
272 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
276 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
278 1c412d48 2021-06-25 op struct excursion place;
280 1c412d48 2021-06-25 op save_excursion(&place, buffer);
283 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
284 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
285 1c412d48 2021-06-25 op message("No previous heading");
288 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
292 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
294 1c412d48 2021-06-25 op struct excursion place;
296 1c412d48 2021-06-25 op save_excursion(&place, buffer);
299 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
300 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
301 1c412d48 2021-06-25 op message("No next heading");
304 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
308 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
310 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
312 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
313 2b2d2872 2021-06-20 op message("No previous page");
315 2b2d2872 2021-06-20 op start_loading_anim(tab);
319 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
321 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
323 2b2d2872 2021-06-20 op if (!load_next_page(tab))
324 2b2d2872 2021-06-20 op message("No next page");
326 2b2d2872 2021-06-20 op start_loading_anim(tab);
330 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
332 2b2d2872 2021-06-20 op message(NULL);
336 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
340 2b2d2872 2021-06-20 op if (in_minibuffer) {
341 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
345 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
346 2b2d2872 2021-06-20 op &eecmd_history);
348 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
349 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
351 2b2d2872 2021-06-20 op if (thiskey.meta)
352 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
354 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
356 2b2d2872 2021-06-20 op if (thiskey.meta)
357 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
361 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
363 2b2d2872 2021-06-20 op struct tab *tab, *t;
365 2b2d2872 2021-06-20 op tab = current_tab();
366 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
367 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
368 2b2d2872 2021-06-20 op message("Can't close the only tab.");
372 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
373 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
375 2b2d2872 2021-06-20 op stop_tab(tab);
377 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
378 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
379 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
382 2b2d2872 2021-06-20 op switch_to_tab(t);
386 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
388 2b2d2872 2021-06-20 op struct tab *t, *i;
390 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
391 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
395 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
401 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
403 2b2d2872 2021-06-20 op const char *url;
405 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
406 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
408 2b2d2872 2021-06-20 op new_tab(url);
412 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
414 2b2d2872 2021-06-20 op struct tab *tab, *t;
416 2b2d2872 2021-06-20 op tab = current_tab();
417 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
419 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
420 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
421 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
422 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
426 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
428 2b2d2872 2021-06-20 op struct tab *tab, *t;
430 2b2d2872 2021-06-20 op tab = current_tab();
431 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
433 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
434 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
435 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
436 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
440 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
442 2b2d2872 2021-06-20 op struct tab *tab, *t;
444 2b2d2872 2021-06-20 op tab = current_tab();
445 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
446 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
448 2b2d2872 2021-06-20 op if (t == NULL)
449 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
451 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
455 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
457 2b2d2872 2021-06-20 op struct tab *tab, *t;
459 2b2d2872 2021-06-20 op tab = current_tab();
460 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
461 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
463 2b2d2872 2021-06-20 op if (t == NULL) {
464 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
465 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
467 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
469 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
473 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
475 2b2d2872 2021-06-20 op if (in_minibuffer) {
476 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
480 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
481 2b2d2872 2021-06-20 op &lu_history);
482 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
483 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
484 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
488 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
490 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
492 2b2d2872 2021-06-20 op if (in_minibuffer) {
493 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
497 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
498 2b2d2872 2021-06-20 op &lu_history);
499 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
500 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
501 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
505 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
507 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
509 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
510 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
511 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
512 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
516 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
518 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
522 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
524 2b2d2872 2021-06-20 op ui_toggle_side_window();
528 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
530 61251035 2021-06-26 op if (fill_column == INT_MAX)
533 61251035 2021-06-26 op fill_column += 2;
534 61251035 2021-06-26 op message("fill-column: %d", fill_column);
536 61251035 2021-06-26 op ui_schedule_redraw();
540 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
542 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
545 61251035 2021-06-26 op fill_column -= 2;
546 61251035 2021-06-26 op message("fill-column: %d", fill_column);
548 61251035 2021-06-26 op ui_schedule_redraw();
552 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
554 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
555 2b2d2872 2021-06-20 op if (olivetti_mode)
556 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
558 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
560 2b2d2872 2021-06-20 op ui_schedule_redraw();
564 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
568 2b2d2872 2021-06-20 op if (!in_minibuffer) {
569 2b2d2872 2021-06-20 op message("text is read-only");
573 2b2d2872 2021-06-20 op minibuffer_taint_hist();
575 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
576 2b2d2872 2021-06-20 op if (*c == '\0')
578 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
580 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
584 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
586 2b2d2872 2021-06-20 op char *c, *p, *start;
588 2b2d2872 2021-06-20 op if (!in_minibuffer) {
589 2b2d2872 2021-06-20 op message("text is read-only");
593 2b2d2872 2021-06-20 op minibuffer_taint_hist();
595 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
596 2b2d2872 2021-06-20 op start = buffer->current_line->line;
597 2b2d2872 2021-06-20 op if (c == start)
599 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
601 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
602 2b2d2872 2021-06-20 op buffer->cpoff--;
606 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
610 2b2d2872 2021-06-20 op if (!in_minibuffer) {
611 2b2d2872 2021-06-20 op message("text is read-only");
615 2b2d2872 2021-06-20 op minibuffer_taint_hist();
616 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
621 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
623 2b2d2872 2021-06-20 op if (!in_minibuffer)
626 2b2d2872 2021-06-20 op ministate.abortfn();
630 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
632 2b2d2872 2021-06-20 op if (!in_minibuffer)
635 2b2d2872 2021-06-20 op minibuffer_taint_hist();
636 2b2d2872 2021-06-20 op ministate.donefn();
640 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
642 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
643 2b2d2872 2021-06-20 op message("No history");
647 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
648 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
649 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
650 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
651 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
652 2b2d2872 2021-06-20 op message("No prev item");
654 2b2d2872 2021-06-20 op ministate.hist_off--;
657 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
658 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
662 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
664 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
665 2b2d2872 2021-06-20 op message("No history");
669 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
670 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
671 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
672 2b2d2872 2021-06-20 op ministate.hist_off = 0;
673 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
674 2b2d2872 2021-06-20 op message("No next item");
676 2b2d2872 2021-06-20 op ministate.hist_off++;
679 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
680 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;