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 c4c82003 2021-07-01 op if (!forward_line(buffer, -1))
145 2b2d2872 2021-06-20 op buffer->line_off--;
146 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_PREV(buffer->top_line, vhead, vlines);
150 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
152 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
155 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
156 2b2d2872 2021-06-20 op buffer->line_off++;
160 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
162 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
166 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
168 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
172 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
174 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
175 c4c82003 2021-07-01 op buffer->cpoff = 0;
176 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
177 2b2d2872 2021-06-20 op buffer->line_off = 0;
181 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
183 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
184 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
188 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
190 2b2d2872 2021-06-20 op save_session();
191 2b2d2872 2021-06-20 op event_loopbreak();
195 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
197 2b2d2872 2021-06-20 op struct vline *vl;
198 963c680c 2021-07-05 op struct line *l;
200 2b2d2872 2021-06-20 op vl = buffer->current_line;
201 963c680c 2021-07-05 op switch (vl->parent->type) {
202 963c680c 2021-07-05 op case LINE_LINK:
203 963c680c 2021-07-05 op load_url_in_tab(current_tab(), vl->parent->alt);
205 963c680c 2021-07-05 op case LINE_PRE_START:
206 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
207 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
208 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
210 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
219 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
221 2b2d2872 2021-06-20 op struct vline *vl;
223 2b2d2872 2021-06-20 op vl = buffer->current_line;
224 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
227 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
231 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
233 5d0feb4b 2021-06-23 op struct excursion place;
235 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
238 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
239 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
240 2b2d2872 2021-06-20 op message("No previous link");
243 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
247 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
249 5d0feb4b 2021-06-23 op struct excursion place;
251 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
254 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
255 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
256 2b2d2872 2021-06-20 op message("No next link");
259 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
262 1c412d48 2021-06-25 op static inline int
263 1c412d48 2021-06-25 op is_heading(const struct line *l)
265 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
266 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
267 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
271 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
273 1c412d48 2021-06-25 op struct excursion place;
275 1c412d48 2021-06-25 op save_excursion(&place, buffer);
278 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
279 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
280 1c412d48 2021-06-25 op message("No previous heading");
283 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
287 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
289 1c412d48 2021-06-25 op struct excursion place;
291 1c412d48 2021-06-25 op save_excursion(&place, buffer);
294 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
295 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
296 1c412d48 2021-06-25 op message("No next heading");
299 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
303 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
305 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
307 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
308 2b2d2872 2021-06-20 op message("No previous page");
310 2b2d2872 2021-06-20 op start_loading_anim(tab);
314 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
316 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
318 2b2d2872 2021-06-20 op if (!load_next_page(tab))
319 2b2d2872 2021-06-20 op message("No next page");
321 2b2d2872 2021-06-20 op start_loading_anim(tab);
325 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
327 2b2d2872 2021-06-20 op message(NULL);
331 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
335 2b2d2872 2021-06-20 op if (in_minibuffer) {
336 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
340 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
341 2b2d2872 2021-06-20 op &eecmd_history);
343 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
344 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
346 2b2d2872 2021-06-20 op if (thiskey.meta)
347 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
349 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
351 2b2d2872 2021-06-20 op if (thiskey.meta)
352 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
356 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
358 2b2d2872 2021-06-20 op struct tab *tab, *t;
360 2b2d2872 2021-06-20 op tab = current_tab();
361 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
362 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
363 2b2d2872 2021-06-20 op message("Can't close the only tab.");
367 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
368 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
370 2b2d2872 2021-06-20 op stop_tab(tab);
372 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
373 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
374 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
377 2b2d2872 2021-06-20 op switch_to_tab(t);
381 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
383 2b2d2872 2021-06-20 op struct tab *t, *i;
385 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
386 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
390 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
396 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
398 2b2d2872 2021-06-20 op const char *url;
400 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
401 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
403 2b2d2872 2021-06-20 op new_tab(url);
407 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
409 2b2d2872 2021-06-20 op struct tab *tab, *t;
411 2b2d2872 2021-06-20 op tab = current_tab();
412 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
414 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
415 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
416 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
417 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
421 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
423 2b2d2872 2021-06-20 op struct tab *tab, *t;
425 2b2d2872 2021-06-20 op tab = current_tab();
426 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
428 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
429 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
430 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
431 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
435 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
437 2b2d2872 2021-06-20 op struct tab *tab, *t;
439 2b2d2872 2021-06-20 op tab = current_tab();
440 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
441 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
443 2b2d2872 2021-06-20 op if (t == NULL)
444 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
446 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
450 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
452 2b2d2872 2021-06-20 op struct tab *tab, *t;
454 2b2d2872 2021-06-20 op tab = current_tab();
455 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
456 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
458 2b2d2872 2021-06-20 op if (t == NULL) {
459 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
460 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
462 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
464 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
468 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
470 2b2d2872 2021-06-20 op if (in_minibuffer) {
471 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
475 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
476 2b2d2872 2021-06-20 op &lu_history);
477 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
478 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
479 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
483 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
485 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
487 2b2d2872 2021-06-20 op if (in_minibuffer) {
488 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
492 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
493 2b2d2872 2021-06-20 op &lu_history);
494 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
495 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
496 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
500 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
502 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
504 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
505 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
506 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
507 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
511 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
513 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
517 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
519 2b2d2872 2021-06-20 op ui_toggle_side_window();
523 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
525 61251035 2021-06-26 op if (fill_column == INT_MAX)
528 61251035 2021-06-26 op fill_column += 2;
529 61251035 2021-06-26 op message("fill-column: %d", fill_column);
531 61251035 2021-06-26 op ui_schedule_redraw();
535 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
537 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
540 61251035 2021-06-26 op fill_column -= 2;
541 61251035 2021-06-26 op message("fill-column: %d", fill_column);
543 61251035 2021-06-26 op ui_schedule_redraw();
547 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
549 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
550 2b2d2872 2021-06-20 op if (olivetti_mode)
551 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
553 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
555 2b2d2872 2021-06-20 op ui_schedule_redraw();
559 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
563 2b2d2872 2021-06-20 op if (!in_minibuffer) {
564 2b2d2872 2021-06-20 op message("text is read-only");
568 2b2d2872 2021-06-20 op minibuffer_taint_hist();
570 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
571 2b2d2872 2021-06-20 op if (*c == '\0')
573 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
575 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
579 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
581 2b2d2872 2021-06-20 op char *c, *p, *start;
583 2b2d2872 2021-06-20 op if (!in_minibuffer) {
584 2b2d2872 2021-06-20 op message("text is read-only");
588 2b2d2872 2021-06-20 op minibuffer_taint_hist();
590 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
591 2b2d2872 2021-06-20 op start = buffer->current_line->line;
592 2b2d2872 2021-06-20 op if (c == start)
594 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
596 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
597 2b2d2872 2021-06-20 op buffer->cpoff--;
601 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
605 2b2d2872 2021-06-20 op if (!in_minibuffer) {
606 2b2d2872 2021-06-20 op message("text is read-only");
610 2b2d2872 2021-06-20 op minibuffer_taint_hist();
611 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
616 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
618 2b2d2872 2021-06-20 op if (!in_minibuffer)
621 2b2d2872 2021-06-20 op ministate.abortfn();
625 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
627 2b2d2872 2021-06-20 op if (!in_minibuffer)
630 2b2d2872 2021-06-20 op minibuffer_taint_hist();
631 2b2d2872 2021-06-20 op ministate.donefn();
635 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
637 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
638 2b2d2872 2021-06-20 op message("No history");
642 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
643 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
644 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
645 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
646 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
647 2b2d2872 2021-06-20 op message("No prev item");
649 2b2d2872 2021-06-20 op ministate.hist_off--;
652 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
653 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
657 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
659 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
660 2b2d2872 2021-06-20 op message("No history");
664 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
665 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
666 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
667 2b2d2872 2021-06-20 op ministate.hist_off = 0;
668 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
669 2b2d2872 2021-06-20 op message("No next item");
671 2b2d2872 2021-06-20 op ministate.hist_off++;
674 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
675 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;