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 450a89f7 2021-07-12 op #include "minibuffer.h"
22 2b2d2872 2021-06-20 op #include "telescope.h"
24 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
25 c4c82003 2021-07-01 op static inline int
26 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
28 c4c82003 2021-07-01 op struct vline *vl;
31 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
33 963c680c 2021-07-05 op vl = buffer->current_line;
36 c4c82003 2021-07-01 op while (n != 0) {
38 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
39 c4c82003 2021-07-01 op if (vl == NULL)
41 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
43 c4c82003 2021-07-01 op buffer->current_line = vl;
46 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
47 c4c82003 2021-07-01 op if (vl == NULL)
49 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
51 c4c82003 2021-07-01 op if (buffer->current_line == buffer->top_line)
52 c4c82003 2021-07-01 op buffer->top_line = vl;
53 c4c82003 2021-07-01 op buffer->current_line = vl;
64 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
66 c4c82003 2021-07-01 op forward_line(buffer, -1);
70 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
72 c4c82003 2021-07-01 op forward_line(buffer, +1);
76 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
78 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
79 2b2d2872 2021-06-20 op buffer->cpoff--;
83 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
85 2b2d2872 2021-06-20 op size_t len = 0;
87 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
88 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
89 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
90 2b2d2872 2021-06-20 op buffer->cpoff = len;
94 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
97 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
98 2b2d2872 2021-06-20 op message("No previous paragraph");
101 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
102 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
106 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
109 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
110 2b2d2872 2021-06-20 op message("No next paragraph");
113 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
114 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
118 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
120 2b2d2872 2021-06-20 op buffer->cpoff = 0;
124 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
126 2b2d2872 2021-06-20 op struct vline *vl;
128 2b2d2872 2021-06-20 op vl = buffer->current_line;
129 2b2d2872 2021-06-20 op if (vl->line == NULL)
131 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
135 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
137 2b2d2872 2021-06-20 op ui_schedule_redraw();
141 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
143 e39920a9 2021-07-07 op struct vline *vl;
145 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
149 e39920a9 2021-07-07 op forward_line(buffer, -1);
151 2b2d2872 2021-06-20 op buffer->line_off--;
152 e39920a9 2021-07-07 op buffer->top_line = vl;
156 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
158 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
161 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
162 2b2d2872 2021-06-20 op buffer->line_off++;
166 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
168 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
172 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
174 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
178 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
180 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
181 c4c82003 2021-07-01 op buffer->cpoff = 0;
182 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
183 2b2d2872 2021-06-20 op buffer->line_off = 0;
187 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
189 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
190 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
194 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
196 2b2d2872 2021-06-20 op save_session();
197 2b2d2872 2021-06-20 op event_loopbreak();
201 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
203 2b2d2872 2021-06-20 op struct vline *vl;
204 963c680c 2021-07-05 op struct line *l;
206 2b2d2872 2021-06-20 op vl = buffer->current_line;
207 963c680c 2021-07-05 op switch (vl->parent->type) {
208 963c680c 2021-07-05 op case LINE_LINK:
209 963c680c 2021-07-05 op load_url_in_tab(current_tab(), vl->parent->alt);
211 963c680c 2021-07-05 op case LINE_PRE_START:
212 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
213 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
214 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
216 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
225 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
227 2b2d2872 2021-06-20 op struct vline *vl;
229 2b2d2872 2021-06-20 op vl = buffer->current_line;
230 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
233 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
237 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
239 5d0feb4b 2021-06-23 op struct excursion place;
241 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
244 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
245 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
246 2b2d2872 2021-06-20 op message("No previous link");
249 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
253 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
255 5d0feb4b 2021-06-23 op struct excursion place;
257 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
260 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
261 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
262 2b2d2872 2021-06-20 op message("No next link");
265 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
268 1c412d48 2021-06-25 op static inline int
269 1c412d48 2021-06-25 op is_heading(const struct line *l)
271 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
272 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
273 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
277 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
279 1c412d48 2021-06-25 op struct excursion place;
281 1c412d48 2021-06-25 op save_excursion(&place, buffer);
284 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
285 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
286 1c412d48 2021-06-25 op message("No previous heading");
289 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
293 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
295 1c412d48 2021-06-25 op struct excursion place;
297 1c412d48 2021-06-25 op save_excursion(&place, buffer);
300 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
301 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
302 1c412d48 2021-06-25 op message("No next heading");
305 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
309 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
311 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
313 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
314 2b2d2872 2021-06-20 op message("No previous page");
316 2b2d2872 2021-06-20 op start_loading_anim(tab);
320 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
322 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
324 2b2d2872 2021-06-20 op if (!load_next_page(tab))
325 2b2d2872 2021-06-20 op message("No next page");
327 2b2d2872 2021-06-20 op start_loading_anim(tab);
331 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
333 2b2d2872 2021-06-20 op message(NULL);
337 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
341 2b2d2872 2021-06-20 op if (in_minibuffer) {
342 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
346 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
347 2b2d2872 2021-06-20 op &eecmd_history);
349 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
350 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
352 2b2d2872 2021-06-20 op if (thiskey.meta)
353 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
355 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
357 2b2d2872 2021-06-20 op if (thiskey.meta)
358 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
362 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
364 2b2d2872 2021-06-20 op struct tab *tab, *t;
366 2b2d2872 2021-06-20 op tab = current_tab();
367 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
368 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
369 2b2d2872 2021-06-20 op message("Can't close the only tab.");
373 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
374 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
376 2b2d2872 2021-06-20 op stop_tab(tab);
378 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
379 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
380 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
383 2b2d2872 2021-06-20 op switch_to_tab(t);
387 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
389 2b2d2872 2021-06-20 op struct tab *t, *i;
391 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
392 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
396 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
402 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
404 2b2d2872 2021-06-20 op const char *url;
406 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
407 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
409 2b2d2872 2021-06-20 op new_tab(url);
413 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
415 2b2d2872 2021-06-20 op struct tab *tab, *t;
417 2b2d2872 2021-06-20 op tab = current_tab();
418 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
420 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
421 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
422 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
423 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
427 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
429 2b2d2872 2021-06-20 op struct tab *tab, *t;
431 2b2d2872 2021-06-20 op tab = current_tab();
432 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
434 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
435 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
436 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
437 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
441 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
443 2b2d2872 2021-06-20 op struct tab *tab, *t;
445 2b2d2872 2021-06-20 op tab = current_tab();
446 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
447 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
449 2b2d2872 2021-06-20 op if (t == NULL)
450 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
452 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
456 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
458 2b2d2872 2021-06-20 op struct tab *tab, *t;
460 2b2d2872 2021-06-20 op tab = current_tab();
461 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
462 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
464 2b2d2872 2021-06-20 op if (t == NULL) {
465 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
466 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
468 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
470 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
474 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
476 2b2d2872 2021-06-20 op if (in_minibuffer) {
477 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
481 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
482 2b2d2872 2021-06-20 op &lu_history);
483 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
484 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
485 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
489 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
491 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
493 2b2d2872 2021-06-20 op if (in_minibuffer) {
494 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
498 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
499 2b2d2872 2021-06-20 op &lu_history);
500 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
501 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
502 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
506 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
508 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
510 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
511 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
512 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
513 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
517 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
519 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
523 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
525 2b2d2872 2021-06-20 op ui_toggle_side_window();
529 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
531 61251035 2021-06-26 op if (fill_column == INT_MAX)
534 61251035 2021-06-26 op fill_column += 2;
535 61251035 2021-06-26 op message("fill-column: %d", fill_column);
537 61251035 2021-06-26 op ui_schedule_redraw();
541 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
543 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
546 61251035 2021-06-26 op fill_column -= 2;
547 61251035 2021-06-26 op message("fill-column: %d", fill_column);
549 61251035 2021-06-26 op ui_schedule_redraw();
553 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
555 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
556 2b2d2872 2021-06-20 op if (olivetti_mode)
557 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
559 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
561 2b2d2872 2021-06-20 op ui_schedule_redraw();
565 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
569 2b2d2872 2021-06-20 op if (!in_minibuffer) {
570 2b2d2872 2021-06-20 op message("text is read-only");
574 2b2d2872 2021-06-20 op minibuffer_taint_hist();
576 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
577 2b2d2872 2021-06-20 op if (*c == '\0')
579 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
581 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
585 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
587 2b2d2872 2021-06-20 op char *c, *p, *start;
589 2b2d2872 2021-06-20 op if (!in_minibuffer) {
590 2b2d2872 2021-06-20 op message("text is read-only");
594 2b2d2872 2021-06-20 op minibuffer_taint_hist();
596 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
597 2b2d2872 2021-06-20 op start = buffer->current_line->line;
598 2b2d2872 2021-06-20 op if (c == start)
600 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
602 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
603 2b2d2872 2021-06-20 op buffer->cpoff--;
607 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
611 2b2d2872 2021-06-20 op if (!in_minibuffer) {
612 2b2d2872 2021-06-20 op message("text is read-only");
616 2b2d2872 2021-06-20 op minibuffer_taint_hist();
617 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
622 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
624 2b2d2872 2021-06-20 op if (!in_minibuffer)
627 2b2d2872 2021-06-20 op ministate.abortfn();
631 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
633 2b2d2872 2021-06-20 op if (!in_minibuffer)
636 2b2d2872 2021-06-20 op minibuffer_taint_hist();
637 2b2d2872 2021-06-20 op ministate.donefn();
641 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
643 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
644 2b2d2872 2021-06-20 op message("No history");
648 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
649 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
650 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
651 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
652 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
653 2b2d2872 2021-06-20 op message("No prev item");
655 2b2d2872 2021-06-20 op ministate.hist_off--;
658 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
659 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
663 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
665 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
666 2b2d2872 2021-06-20 op message("No history");
670 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
671 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
672 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
673 2b2d2872 2021-06-20 op ministate.hist_off = 0;
674 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
675 2b2d2872 2021-06-20 op message("No next item");
677 2b2d2872 2021-06-20 op ministate.hist_off++;
680 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
681 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;