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"
21 2b2d2872 2021-06-20 op #include "cmd.gen.h"
24 2b2d2872 2021-06-20 op cmd_previous_line(struct buffer *buffer)
26 2b2d2872 2021-06-20 op struct vline *vl;
28 2b2d2872 2021-06-20 op if (buffer->current_line == NULL
29 2b2d2872 2021-06-20 op || (vl = TAILQ_PREV(buffer->current_line, vhead, vlines)) == NULL)
32 2b2d2872 2021-06-20 op if (--buffer->curs_y < 0) {
33 2b2d2872 2021-06-20 op buffer->curs_y = 0;
34 2b2d2872 2021-06-20 op cmd_scroll_line_up(buffer);
38 2b2d2872 2021-06-20 op buffer->current_line = vl;
39 2b2d2872 2021-06-20 op restore_cursor(buffer);
43 2b2d2872 2021-06-20 op cmd_next_line(struct buffer *buffer)
45 2b2d2872 2021-06-20 op struct vline *vl;
47 2b2d2872 2021-06-20 op if (buffer->current_line == NULL
48 2b2d2872 2021-06-20 op || (vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL)
51 2b2d2872 2021-06-20 op if (++buffer->curs_y > body_lines-1) {
52 2b2d2872 2021-06-20 op buffer->curs_y = body_lines-1;
53 2b2d2872 2021-06-20 op cmd_scroll_line_down(buffer);
57 2b2d2872 2021-06-20 op buffer->current_line = vl;
58 2b2d2872 2021-06-20 op restore_cursor(buffer);
62 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
64 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
65 2b2d2872 2021-06-20 op buffer->cpoff--;
66 2b2d2872 2021-06-20 op restore_cursor(buffer);
70 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
72 2b2d2872 2021-06-20 op size_t len = 0;
74 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
75 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
76 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
77 2b2d2872 2021-06-20 op buffer->cpoff = len;
78 2b2d2872 2021-06-20 op restore_cursor(buffer);
82 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
85 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
86 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
87 2b2d2872 2021-06-20 op message("No previous paragraph");
90 2b2d2872 2021-06-20 op cmd_previous_line(buffer);
91 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
92 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
96 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
99 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
100 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
101 2b2d2872 2021-06-20 op message("No next paragraph");
104 2b2d2872 2021-06-20 op cmd_next_line(buffer);
105 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
106 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
110 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
112 2b2d2872 2021-06-20 op buffer->cpoff = 0;
113 2b2d2872 2021-06-20 op restore_cursor(buffer);
117 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
119 2b2d2872 2021-06-20 op struct vline *vl;
121 2b2d2872 2021-06-20 op vl = buffer->current_line;
122 2b2d2872 2021-06-20 op if (vl->line == NULL)
124 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
125 2b2d2872 2021-06-20 op restore_cursor(buffer);
129 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
131 2b2d2872 2021-06-20 op ui_schedule_redraw();
135 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
137 2b2d2872 2021-06-20 op if (buffer->current_line == NULL)
140 28eca2fc 2021-06-20 op if (buffer->line_off == 0)
143 2b2d2872 2021-06-20 op buffer->line_off--;
144 28eca2fc 2021-06-20 op buffer->current_line = TAILQ_PREV(buffer->current_line, vhead, vlines);
145 2b2d2872 2021-06-20 op restore_cursor(buffer);
149 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
151 2b2d2872 2021-06-20 op struct vline *vl;
153 2b2d2872 2021-06-20 op if (buffer->current_line == NULL)
156 2b2d2872 2021-06-20 op if ((vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL)
159 2b2d2872 2021-06-20 op buffer->current_line = vl;
160 2b2d2872 2021-06-20 op buffer->line_off++;
161 2b2d2872 2021-06-20 op restore_cursor(buffer);
165 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
169 2b2d2872 2021-06-20 op off = body_lines-1;
171 2b2d2872 2021-06-20 op for (; off > 0; --off)
172 2b2d2872 2021-06-20 op cmd_scroll_line_up(buffer);
176 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
180 2b2d2872 2021-06-20 op off = body_lines-1;
182 2b2d2872 2021-06-20 op for (; off > 0; --off)
183 2b2d2872 2021-06-20 op cmd_scroll_line_down(buffer);
187 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
189 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
190 2b2d2872 2021-06-20 op buffer->line_off = 0;
191 2b2d2872 2021-06-20 op buffer->curs_y = 0;
192 2b2d2872 2021-06-20 op buffer->cpoff = 0;
193 2b2d2872 2021-06-20 op restore_cursor(buffer);
197 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
201 2b2d2872 2021-06-20 op off = buffer->line_max - body_lines;
202 2b2d2872 2021-06-20 op off = MAX(0, off);
204 2b2d2872 2021-06-20 op buffer->line_off = off;
205 4f0158a7 2021-06-20 op buffer->curs_y = MIN((size_t)body_lines-1, buffer->line_max-1);
207 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
208 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
209 2b2d2872 2021-06-20 op restore_cursor(buffer);
213 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
215 2b2d2872 2021-06-20 op save_session();
216 2b2d2872 2021-06-20 op event_loopbreak();
220 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
222 2b2d2872 2021-06-20 op struct vline *vl;
224 2b2d2872 2021-06-20 op vl = buffer->current_line;
225 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
228 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), vl->parent->alt);
232 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
234 2b2d2872 2021-06-20 op struct vline *vl;
236 2b2d2872 2021-06-20 op vl = buffer->current_line;
237 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
240 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
244 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
246 5d0feb4b 2021-06-23 op struct excursion place;
248 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
251 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
252 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
253 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
254 2b2d2872 2021-06-20 op message("No previous link");
257 2b2d2872 2021-06-20 op cmd_previous_line(buffer);
258 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
262 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
264 5d0feb4b 2021-06-23 op struct excursion place;
266 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
269 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
270 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
271 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
272 2b2d2872 2021-06-20 op message("No next link");
275 2b2d2872 2021-06-20 op cmd_next_line(buffer);
276 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
279 1c412d48 2021-06-25 op static inline int
280 1c412d48 2021-06-25 op is_heading(const struct line *l)
282 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
283 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
284 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
288 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
290 1c412d48 2021-06-25 op struct excursion place;
292 1c412d48 2021-06-25 op save_excursion(&place, buffer);
295 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
296 1c412d48 2021-06-25 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
297 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
298 1c412d48 2021-06-25 op message("No previous heading");
301 1c412d48 2021-06-25 op cmd_previous_line(buffer);
302 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
306 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
308 1c412d48 2021-06-25 op struct excursion place;
310 1c412d48 2021-06-25 op save_excursion(&place, buffer);
313 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
314 1c412d48 2021-06-25 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
315 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
316 1c412d48 2021-06-25 op message("No next heading");
319 1c412d48 2021-06-25 op cmd_next_line(buffer);
320 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
324 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
326 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
328 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
329 2b2d2872 2021-06-20 op message("No previous page");
331 2b2d2872 2021-06-20 op start_loading_anim(tab);
335 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
337 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
339 2b2d2872 2021-06-20 op if (!load_next_page(tab))
340 2b2d2872 2021-06-20 op message("No next page");
342 2b2d2872 2021-06-20 op start_loading_anim(tab);
346 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
348 2b2d2872 2021-06-20 op message(NULL);
352 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
356 2b2d2872 2021-06-20 op if (in_minibuffer) {
357 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
361 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
362 2b2d2872 2021-06-20 op &eecmd_history);
364 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
365 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
367 2b2d2872 2021-06-20 op if (thiskey.meta)
368 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
370 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
372 2b2d2872 2021-06-20 op if (thiskey.meta)
373 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
377 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
379 2b2d2872 2021-06-20 op struct tab *tab, *t;
381 2b2d2872 2021-06-20 op tab = current_tab();
382 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
383 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
384 2b2d2872 2021-06-20 op message("Can't close the only tab.");
388 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
389 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
391 2b2d2872 2021-06-20 op stop_tab(tab);
393 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
394 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
395 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
398 2b2d2872 2021-06-20 op switch_to_tab(t);
402 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
404 2b2d2872 2021-06-20 op struct tab *t, *i;
406 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
407 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
411 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
417 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
419 2b2d2872 2021-06-20 op const char *url;
421 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
422 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
424 2b2d2872 2021-06-20 op new_tab(url);
428 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
430 2b2d2872 2021-06-20 op struct tab *tab, *t;
432 2b2d2872 2021-06-20 op tab = current_tab();
433 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
435 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
436 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
437 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
438 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
442 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
444 2b2d2872 2021-06-20 op struct tab *tab, *t;
446 2b2d2872 2021-06-20 op tab = current_tab();
447 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
449 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
450 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
451 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
452 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
456 2b2d2872 2021-06-20 op cmd_tab_move(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_NEXT(tab, 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 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
467 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
471 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
473 2b2d2872 2021-06-20 op struct tab *tab, *t;
475 2b2d2872 2021-06-20 op tab = current_tab();
476 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
477 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
479 2b2d2872 2021-06-20 op if (t == NULL) {
480 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
481 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
483 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
485 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
489 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
491 2b2d2872 2021-06-20 op if (in_minibuffer) {
492 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
496 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
497 2b2d2872 2021-06-20 op &lu_history);
498 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
499 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
500 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
504 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
506 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
508 2b2d2872 2021-06-20 op if (in_minibuffer) {
509 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
513 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
514 2b2d2872 2021-06-20 op &lu_history);
515 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
516 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
517 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
521 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
523 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
525 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
526 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
527 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
528 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
532 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
534 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
538 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
540 2b2d2872 2021-06-20 op ui_toggle_side_window();
544 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
546 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
547 2b2d2872 2021-06-20 op if (olivetti_mode)
548 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
550 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
552 2b2d2872 2021-06-20 op ui_schedule_redraw();
556 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
560 2b2d2872 2021-06-20 op if (!in_minibuffer) {
561 2b2d2872 2021-06-20 op message("text is read-only");
565 2b2d2872 2021-06-20 op minibuffer_taint_hist();
567 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
568 2b2d2872 2021-06-20 op if (*c == '\0')
570 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
572 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
576 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
578 2b2d2872 2021-06-20 op char *c, *p, *start;
580 2b2d2872 2021-06-20 op if (!in_minibuffer) {
581 2b2d2872 2021-06-20 op message("text is read-only");
585 2b2d2872 2021-06-20 op minibuffer_taint_hist();
587 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
588 2b2d2872 2021-06-20 op start = buffer->current_line->line;
589 2b2d2872 2021-06-20 op if (c == start)
591 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
593 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
594 2b2d2872 2021-06-20 op buffer->cpoff--;
598 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
602 2b2d2872 2021-06-20 op if (!in_minibuffer) {
603 2b2d2872 2021-06-20 op message("text is read-only");
607 2b2d2872 2021-06-20 op minibuffer_taint_hist();
608 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
613 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
615 2b2d2872 2021-06-20 op if (!in_minibuffer)
618 2b2d2872 2021-06-20 op ministate.abortfn();
622 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
624 2b2d2872 2021-06-20 op if (!in_minibuffer)
627 2b2d2872 2021-06-20 op minibuffer_taint_hist();
628 2b2d2872 2021-06-20 op ministate.donefn();
632 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
634 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
635 2b2d2872 2021-06-20 op message("No history");
639 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
640 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
641 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
642 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
643 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
644 2b2d2872 2021-06-20 op message("No prev item");
646 2b2d2872 2021-06-20 op ministate.hist_off--;
649 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
650 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
654 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
656 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
657 2b2d2872 2021-06-20 op message("No history");
661 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
662 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
663 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
664 2b2d2872 2021-06-20 op ministate.hist_off = 0;
665 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
666 2b2d2872 2021-06-20 op message("No next item");
668 2b2d2872 2021-06-20 op ministate.hist_off++;
671 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
672 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;