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 2b2d2872 2021-06-20 op #include <string.h>
18 2b2d2872 2021-06-20 op #include <stdlib.h>
20 2b2d2872 2021-06-20 op #include "telescope.h"
23 2b2d2872 2021-06-20 op cmd_previous_line(struct buffer *buffer)
25 2b2d2872 2021-06-20 op struct vline *vl;
27 2b2d2872 2021-06-20 op if (buffer->current_line == NULL
28 2b2d2872 2021-06-20 op || (vl = TAILQ_PREV(buffer->current_line, vhead, vlines)) == NULL)
31 2b2d2872 2021-06-20 op if (--buffer->curs_y < 0) {
32 2b2d2872 2021-06-20 op buffer->curs_y = 0;
33 2b2d2872 2021-06-20 op cmd_scroll_line_up(buffer);
37 2b2d2872 2021-06-20 op buffer->current_line = vl;
38 2b2d2872 2021-06-20 op restore_cursor(buffer);
42 2b2d2872 2021-06-20 op cmd_next_line(struct buffer *buffer)
44 2b2d2872 2021-06-20 op struct vline *vl;
46 2b2d2872 2021-06-20 op if (buffer->current_line == NULL
47 2b2d2872 2021-06-20 op || (vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL)
50 2b2d2872 2021-06-20 op if (++buffer->curs_y > body_lines-1) {
51 2b2d2872 2021-06-20 op buffer->curs_y = body_lines-1;
52 2b2d2872 2021-06-20 op cmd_scroll_line_down(buffer);
56 2b2d2872 2021-06-20 op buffer->current_line = vl;
57 2b2d2872 2021-06-20 op restore_cursor(buffer);
61 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
63 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
64 2b2d2872 2021-06-20 op buffer->cpoff--;
65 2b2d2872 2021-06-20 op restore_cursor(buffer);
69 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
71 2b2d2872 2021-06-20 op size_t len = 0;
73 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
74 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
75 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
76 2b2d2872 2021-06-20 op buffer->cpoff = len;
77 2b2d2872 2021-06-20 op restore_cursor(buffer);
81 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
84 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
85 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
86 2b2d2872 2021-06-20 op message("No previous paragraph");
89 2b2d2872 2021-06-20 op cmd_previous_line(buffer);
90 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
91 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
95 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
98 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
99 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
100 2b2d2872 2021-06-20 op message("No next paragraph");
103 2b2d2872 2021-06-20 op cmd_next_line(buffer);
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_move_beginning_of_line(struct buffer *buffer)
111 2b2d2872 2021-06-20 op buffer->cpoff = 0;
112 2b2d2872 2021-06-20 op restore_cursor(buffer);
116 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
118 2b2d2872 2021-06-20 op struct vline *vl;
120 2b2d2872 2021-06-20 op vl = buffer->current_line;
121 2b2d2872 2021-06-20 op if (vl->line == NULL)
123 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
124 2b2d2872 2021-06-20 op restore_cursor(buffer);
128 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
130 2b2d2872 2021-06-20 op ui_schedule_redraw();
134 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
136 2b2d2872 2021-06-20 op if (buffer->current_line == NULL)
139 28eca2fc 2021-06-20 op if (buffer->line_off == 0)
142 2b2d2872 2021-06-20 op buffer->line_off--;
143 28eca2fc 2021-06-20 op buffer->current_line = TAILQ_PREV(buffer->current_line, vhead, vlines);
144 2b2d2872 2021-06-20 op restore_cursor(buffer);
148 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
150 2b2d2872 2021-06-20 op struct vline *vl;
152 2b2d2872 2021-06-20 op if (buffer->current_line == NULL)
155 2b2d2872 2021-06-20 op if ((vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL)
158 2b2d2872 2021-06-20 op buffer->current_line = vl;
159 2b2d2872 2021-06-20 op buffer->line_off++;
160 2b2d2872 2021-06-20 op restore_cursor(buffer);
164 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
168 2b2d2872 2021-06-20 op off = body_lines-1;
170 2b2d2872 2021-06-20 op for (; off > 0; --off)
171 2b2d2872 2021-06-20 op cmd_scroll_line_up(buffer);
175 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
179 2b2d2872 2021-06-20 op off = body_lines-1;
181 2b2d2872 2021-06-20 op for (; off > 0; --off)
182 2b2d2872 2021-06-20 op cmd_scroll_line_down(buffer);
186 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
188 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
189 2b2d2872 2021-06-20 op buffer->line_off = 0;
190 2b2d2872 2021-06-20 op buffer->curs_y = 0;
191 2b2d2872 2021-06-20 op buffer->cpoff = 0;
192 2b2d2872 2021-06-20 op restore_cursor(buffer);
196 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
200 2b2d2872 2021-06-20 op off = buffer->line_max - body_lines;
201 2b2d2872 2021-06-20 op off = MAX(0, off);
203 2b2d2872 2021-06-20 op buffer->line_off = off;
204 4f0158a7 2021-06-20 op buffer->curs_y = MIN((size_t)body_lines-1, buffer->line_max-1);
206 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
207 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
208 2b2d2872 2021-06-20 op restore_cursor(buffer);
212 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
214 2b2d2872 2021-06-20 op save_session();
215 2b2d2872 2021-06-20 op event_loopbreak();
219 2b2d2872 2021-06-20 op cmd_push_button(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 load_url_in_tab(current_tab(), vl->parent->alt);
231 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
233 2b2d2872 2021-06-20 op struct vline *vl;
235 2b2d2872 2021-06-20 op vl = buffer->current_line;
236 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
239 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
243 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
245 5d0feb4b 2021-06-23 op struct excursion place;
247 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
250 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
251 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
252 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
253 2b2d2872 2021-06-20 op message("No previous link");
256 2b2d2872 2021-06-20 op cmd_previous_line(buffer);
257 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
261 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
263 5d0feb4b 2021-06-23 op struct excursion place;
265 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
268 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
269 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
270 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
271 2b2d2872 2021-06-20 op message("No next link");
274 2b2d2872 2021-06-20 op cmd_next_line(buffer);
275 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
278 1c412d48 2021-06-25 op static inline int
279 1c412d48 2021-06-25 op is_heading(const struct line *l)
281 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
282 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
283 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
287 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
289 1c412d48 2021-06-25 op struct excursion place;
291 1c412d48 2021-06-25 op save_excursion(&place, buffer);
294 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
295 1c412d48 2021-06-25 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
296 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
297 1c412d48 2021-06-25 op message("No previous heading");
300 1c412d48 2021-06-25 op cmd_previous_line(buffer);
301 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
305 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
307 1c412d48 2021-06-25 op struct excursion place;
309 1c412d48 2021-06-25 op save_excursion(&place, buffer);
312 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
313 1c412d48 2021-06-25 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
314 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
315 1c412d48 2021-06-25 op message("No next heading");
318 1c412d48 2021-06-25 op cmd_next_line(buffer);
319 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
323 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
325 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
327 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
328 2b2d2872 2021-06-20 op message("No previous page");
330 2b2d2872 2021-06-20 op start_loading_anim(tab);
334 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
336 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
338 2b2d2872 2021-06-20 op if (!load_next_page(tab))
339 2b2d2872 2021-06-20 op message("No next page");
341 2b2d2872 2021-06-20 op start_loading_anim(tab);
345 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
347 2b2d2872 2021-06-20 op message(NULL);
351 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
355 2b2d2872 2021-06-20 op if (in_minibuffer) {
356 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
360 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
361 2b2d2872 2021-06-20 op &eecmd_history);
363 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
364 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
366 2b2d2872 2021-06-20 op if (thiskey.meta)
367 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
369 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
371 2b2d2872 2021-06-20 op if (thiskey.meta)
372 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
376 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
378 2b2d2872 2021-06-20 op struct tab *tab, *t;
380 2b2d2872 2021-06-20 op tab = current_tab();
381 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
382 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
383 2b2d2872 2021-06-20 op message("Can't close the only tab.");
387 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
388 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
390 2b2d2872 2021-06-20 op stop_tab(tab);
392 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
393 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
394 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
397 2b2d2872 2021-06-20 op switch_to_tab(t);
401 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
403 2b2d2872 2021-06-20 op struct tab *t, *i;
405 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
406 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
410 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
416 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
418 2b2d2872 2021-06-20 op const char *url;
420 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
421 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
423 2b2d2872 2021-06-20 op new_tab(url);
427 2b2d2872 2021-06-20 op cmd_tab_next(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_NEXT(tab, tabs)) == NULL)
435 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&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_previous(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 tab->flags &= ~TAB_CURRENT;
448 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
449 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
450 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
451 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
455 2b2d2872 2021-06-20 op cmd_tab_move(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_NEXT(tab, 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 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
466 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
470 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
472 2b2d2872 2021-06-20 op struct tab *tab, *t;
474 2b2d2872 2021-06-20 op tab = current_tab();
475 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
476 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
478 2b2d2872 2021-06-20 op if (t == NULL) {
479 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
480 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
482 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
484 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
488 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
490 2b2d2872 2021-06-20 op if (in_minibuffer) {
491 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
495 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
496 2b2d2872 2021-06-20 op &lu_history);
497 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
498 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
499 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
503 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
505 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
507 2b2d2872 2021-06-20 op if (in_minibuffer) {
508 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
512 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
513 2b2d2872 2021-06-20 op &lu_history);
514 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
515 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
516 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
520 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
522 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
524 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
525 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
526 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
527 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
531 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
533 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
537 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
539 2b2d2872 2021-06-20 op ui_toggle_side_window();
543 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
545 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
546 2b2d2872 2021-06-20 op if (olivetti_mode)
547 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
549 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
551 2b2d2872 2021-06-20 op ui_schedule_redraw();
555 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
559 2b2d2872 2021-06-20 op if (!in_minibuffer) {
560 2b2d2872 2021-06-20 op message("text is read-only");
564 2b2d2872 2021-06-20 op minibuffer_taint_hist();
566 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
567 2b2d2872 2021-06-20 op if (*c == '\0')
569 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
571 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
575 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
577 2b2d2872 2021-06-20 op char *c, *p, *start;
579 2b2d2872 2021-06-20 op if (!in_minibuffer) {
580 2b2d2872 2021-06-20 op message("text is read-only");
584 2b2d2872 2021-06-20 op minibuffer_taint_hist();
586 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
587 2b2d2872 2021-06-20 op start = buffer->current_line->line;
588 2b2d2872 2021-06-20 op if (c == start)
590 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
592 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
593 2b2d2872 2021-06-20 op buffer->cpoff--;
597 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
601 2b2d2872 2021-06-20 op if (!in_minibuffer) {
602 2b2d2872 2021-06-20 op message("text is read-only");
606 2b2d2872 2021-06-20 op minibuffer_taint_hist();
607 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
612 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
614 2b2d2872 2021-06-20 op if (!in_minibuffer)
617 2b2d2872 2021-06-20 op ministate.abortfn();
621 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
623 2b2d2872 2021-06-20 op if (!in_minibuffer)
626 2b2d2872 2021-06-20 op minibuffer_taint_hist();
627 2b2d2872 2021-06-20 op ministate.donefn();
631 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
633 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
634 2b2d2872 2021-06-20 op message("No history");
638 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
639 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
640 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
641 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
642 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
643 2b2d2872 2021-06-20 op message("No prev item");
645 2b2d2872 2021-06-20 op ministate.hist_off--;
648 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
649 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
653 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
655 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
656 2b2d2872 2021-06-20 op message("No history");
660 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
661 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
662 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
663 2b2d2872 2021-06-20 op ministate.hist_off = 0;
664 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
665 2b2d2872 2021-06-20 op message("No next item");
667 2b2d2872 2021-06-20 op ministate.hist_off++;
670 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
671 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;