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"
23 d1a0f2a3 2021-07-12 op #include "ui.h"
24 5caf7d67 2021-07-12 op #include "utf8.h"
26 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
27 c4c82003 2021-07-01 op static inline int
28 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
30 c4c82003 2021-07-01 op struct vline *vl;
33 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
35 963c680c 2021-07-05 op vl = buffer->current_line;
38 c4c82003 2021-07-01 op while (n != 0) {
40 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
41 c4c82003 2021-07-01 op if (vl == NULL)
43 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
45 c4c82003 2021-07-01 op buffer->current_line = vl;
48 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
49 c4c82003 2021-07-01 op if (vl == NULL)
51 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
53 c4c82003 2021-07-01 op if (buffer->current_line == buffer->top_line)
54 c4c82003 2021-07-01 op buffer->top_line = vl;
55 c4c82003 2021-07-01 op buffer->current_line = vl;
66 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
68 c4c82003 2021-07-01 op forward_line(buffer, -1);
72 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
74 c4c82003 2021-07-01 op forward_line(buffer, +1);
78 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
80 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
81 2b2d2872 2021-06-20 op buffer->cpoff--;
85 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
87 2b2d2872 2021-06-20 op size_t len = 0;
89 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
90 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
91 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
92 2b2d2872 2021-06-20 op buffer->cpoff = len;
96 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
99 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
100 2b2d2872 2021-06-20 op message("No previous paragraph");
103 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
104 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
108 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
111 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
112 2b2d2872 2021-06-20 op message("No next paragraph");
115 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
116 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
120 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
122 2b2d2872 2021-06-20 op buffer->cpoff = 0;
126 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
128 2b2d2872 2021-06-20 op struct vline *vl;
130 2b2d2872 2021-06-20 op vl = buffer->current_line;
131 2b2d2872 2021-06-20 op if (vl->line == NULL)
133 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
137 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
139 2b2d2872 2021-06-20 op ui_schedule_redraw();
143 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
145 e39920a9 2021-07-07 op struct vline *vl;
147 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
151 e39920a9 2021-07-07 op forward_line(buffer, -1);
153 2b2d2872 2021-06-20 op buffer->line_off--;
154 e39920a9 2021-07-07 op buffer->top_line = vl;
158 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
160 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
163 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
164 2b2d2872 2021-06-20 op buffer->line_off++;
168 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
170 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
174 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
176 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
180 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
182 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
183 c4c82003 2021-07-01 op buffer->cpoff = 0;
184 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
185 2b2d2872 2021-06-20 op buffer->line_off = 0;
189 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
191 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
192 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
196 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
198 2b2d2872 2021-06-20 op save_session();
199 2b2d2872 2021-06-20 op event_loopbreak();
203 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
205 2b2d2872 2021-06-20 op struct vline *vl;
206 963c680c 2021-07-05 op struct line *l;
208 2b2d2872 2021-06-20 op vl = buffer->current_line;
209 963c680c 2021-07-05 op switch (vl->parent->type) {
210 963c680c 2021-07-05 op case LINE_LINK:
211 963c680c 2021-07-05 op load_url_in_tab(current_tab(), vl->parent->alt);
213 963c680c 2021-07-05 op case LINE_PRE_START:
214 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
215 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
216 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
218 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
227 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
229 2b2d2872 2021-06-20 op struct vline *vl;
231 2b2d2872 2021-06-20 op vl = buffer->current_line;
232 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
235 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
239 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
241 5d0feb4b 2021-06-23 op struct excursion place;
243 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
246 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
247 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
248 2b2d2872 2021-06-20 op message("No previous link");
251 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
255 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
257 5d0feb4b 2021-06-23 op struct excursion place;
259 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
262 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
263 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
264 2b2d2872 2021-06-20 op message("No next link");
267 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
270 1c412d48 2021-06-25 op static inline int
271 1c412d48 2021-06-25 op is_heading(const struct line *l)
273 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
274 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
275 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
279 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
281 1c412d48 2021-06-25 op struct excursion place;
283 1c412d48 2021-06-25 op save_excursion(&place, buffer);
286 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
287 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
288 1c412d48 2021-06-25 op message("No previous heading");
291 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
295 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
297 1c412d48 2021-06-25 op struct excursion place;
299 1c412d48 2021-06-25 op save_excursion(&place, buffer);
302 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
303 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
304 1c412d48 2021-06-25 op message("No next heading");
307 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
311 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
313 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
315 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
316 2b2d2872 2021-06-20 op message("No previous page");
318 2b2d2872 2021-06-20 op start_loading_anim(tab);
322 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
324 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
326 2b2d2872 2021-06-20 op if (!load_next_page(tab))
327 2b2d2872 2021-06-20 op message("No next page");
329 2b2d2872 2021-06-20 op start_loading_anim(tab);
333 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
335 2b2d2872 2021-06-20 op message(NULL);
339 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
343 2b2d2872 2021-06-20 op if (in_minibuffer) {
344 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
348 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
349 2b2d2872 2021-06-20 op &eecmd_history);
351 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
352 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
354 2b2d2872 2021-06-20 op if (thiskey.meta)
355 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
357 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
359 2b2d2872 2021-06-20 op if (thiskey.meta)
360 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
364 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
366 2b2d2872 2021-06-20 op struct tab *tab, *t;
368 2b2d2872 2021-06-20 op tab = current_tab();
369 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
370 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
371 2b2d2872 2021-06-20 op message("Can't close the only tab.");
375 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
376 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
378 2b2d2872 2021-06-20 op stop_tab(tab);
380 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
381 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
382 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
385 2b2d2872 2021-06-20 op switch_to_tab(t);
389 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
391 2b2d2872 2021-06-20 op struct tab *t, *i;
393 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
394 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
398 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
404 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
406 2b2d2872 2021-06-20 op const char *url;
408 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
409 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
411 2b2d2872 2021-06-20 op new_tab(url);
415 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
417 2b2d2872 2021-06-20 op struct tab *tab, *t;
419 2b2d2872 2021-06-20 op tab = current_tab();
420 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
422 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
423 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
424 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
425 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
429 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
431 2b2d2872 2021-06-20 op struct tab *tab, *t;
433 2b2d2872 2021-06-20 op tab = current_tab();
434 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
436 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
437 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
438 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
439 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
443 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
445 2b2d2872 2021-06-20 op struct tab *tab, *t;
447 2b2d2872 2021-06-20 op tab = current_tab();
448 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
449 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
451 2b2d2872 2021-06-20 op if (t == NULL)
452 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
454 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
458 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
460 2b2d2872 2021-06-20 op struct tab *tab, *t;
462 2b2d2872 2021-06-20 op tab = current_tab();
463 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
464 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
466 2b2d2872 2021-06-20 op if (t == NULL) {
467 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
468 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
470 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
472 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
476 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
478 2b2d2872 2021-06-20 op if (in_minibuffer) {
479 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
483 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
484 2b2d2872 2021-06-20 op &lu_history);
485 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
486 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
487 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
491 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
493 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
495 2b2d2872 2021-06-20 op if (in_minibuffer) {
496 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
500 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
501 2b2d2872 2021-06-20 op &lu_history);
502 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
503 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
504 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
508 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
510 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
512 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
513 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
514 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
515 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
519 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
521 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
525 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
527 2b2d2872 2021-06-20 op ui_toggle_side_window();
531 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
533 61251035 2021-06-26 op if (fill_column == INT_MAX)
536 61251035 2021-06-26 op fill_column += 2;
537 61251035 2021-06-26 op message("fill-column: %d", fill_column);
539 61251035 2021-06-26 op ui_schedule_redraw();
543 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
545 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
548 61251035 2021-06-26 op fill_column -= 2;
549 61251035 2021-06-26 op message("fill-column: %d", fill_column);
551 61251035 2021-06-26 op ui_schedule_redraw();
555 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
557 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
558 2b2d2872 2021-06-20 op if (olivetti_mode)
559 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
561 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
563 2b2d2872 2021-06-20 op ui_schedule_redraw();
567 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
571 2b2d2872 2021-06-20 op if (!in_minibuffer) {
572 2b2d2872 2021-06-20 op message("text is read-only");
576 2b2d2872 2021-06-20 op minibuffer_taint_hist();
578 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
579 2b2d2872 2021-06-20 op if (*c == '\0')
581 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
583 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
587 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
589 2b2d2872 2021-06-20 op char *c, *p, *start;
591 2b2d2872 2021-06-20 op if (!in_minibuffer) {
592 2b2d2872 2021-06-20 op message("text is read-only");
596 2b2d2872 2021-06-20 op minibuffer_taint_hist();
598 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
599 2b2d2872 2021-06-20 op start = buffer->current_line->line;
600 2b2d2872 2021-06-20 op if (c == start)
602 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
604 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
605 2b2d2872 2021-06-20 op buffer->cpoff--;
609 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
613 2b2d2872 2021-06-20 op if (!in_minibuffer) {
614 2b2d2872 2021-06-20 op message("text is read-only");
618 2b2d2872 2021-06-20 op minibuffer_taint_hist();
619 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
624 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
626 2b2d2872 2021-06-20 op if (!in_minibuffer)
629 2b2d2872 2021-06-20 op ministate.abortfn();
633 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
635 2b2d2872 2021-06-20 op if (!in_minibuffer)
638 2b2d2872 2021-06-20 op minibuffer_taint_hist();
639 2b2d2872 2021-06-20 op ministate.donefn();
643 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
645 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
646 2b2d2872 2021-06-20 op message("No history");
650 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
651 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
652 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
653 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
654 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
655 2b2d2872 2021-06-20 op message("No prev item");
657 2b2d2872 2021-06-20 op ministate.hist_off--;
660 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
661 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
665 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
667 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
668 2b2d2872 2021-06-20 op message("No history");
672 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
673 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
674 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
675 2b2d2872 2021-06-20 op ministate.hist_off = 0;
676 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
677 2b2d2872 2021-06-20 op message("No next item");
679 2b2d2872 2021-06-20 op ministate.hist_off++;
682 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
683 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;