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"
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 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_PREV(buffer->top_line, vhead, vlines);
145 28eca2fc 2021-06-20 op buffer->current_line = TAILQ_PREV(buffer->current_line, vhead, vlines);
146 2b2d2872 2021-06-20 op restore_cursor(buffer);
150 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
152 2b2d2872 2021-06-20 op struct vline *vl;
154 2b2d2872 2021-06-20 op if (buffer->current_line == NULL)
157 2b2d2872 2021-06-20 op if ((vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL)
160 2b2d2872 2021-06-20 op buffer->current_line = vl;
162 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
163 2b2d2872 2021-06-20 op buffer->line_off++;
165 2b2d2872 2021-06-20 op restore_cursor(buffer);
169 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
173 2b2d2872 2021-06-20 op off = body_lines-1;
175 2b2d2872 2021-06-20 op for (; off > 0; --off)
176 2b2d2872 2021-06-20 op cmd_scroll_line_up(buffer);
180 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
184 2b2d2872 2021-06-20 op off = body_lines-1;
186 2b2d2872 2021-06-20 op for (; off > 0; --off)
187 2b2d2872 2021-06-20 op cmd_scroll_line_down(buffer);
191 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
193 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
194 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
195 2b2d2872 2021-06-20 op buffer->line_off = 0;
196 2b2d2872 2021-06-20 op buffer->curs_y = 0;
197 2b2d2872 2021-06-20 op buffer->cpoff = 0;
198 2b2d2872 2021-06-20 op restore_cursor(buffer);
202 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
206 2b2d2872 2021-06-20 op off = buffer->line_max - body_lines;
207 2b2d2872 2021-06-20 op off = MAX(0, off);
209 94ec38e8 2021-06-29 op while (buffer->line_off > (size_t)off) {
210 94ec38e8 2021-06-29 op buffer->line_off--;
211 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_PREV(buffer->top_line, vhead, vlines);
213 94ec38e8 2021-06-29 op while (buffer->line_off < (size_t)off) {
214 94ec38e8 2021-06-29 op buffer->line_off++;
215 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
218 2b2d2872 2021-06-20 op buffer->line_off = off;
219 4f0158a7 2021-06-20 op buffer->curs_y = MIN((size_t)body_lines-1, buffer->line_max-1);
221 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
222 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
223 2b2d2872 2021-06-20 op restore_cursor(buffer);
227 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
229 2b2d2872 2021-06-20 op save_session();
230 2b2d2872 2021-06-20 op event_loopbreak();
234 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
236 2b2d2872 2021-06-20 op struct vline *vl;
238 2b2d2872 2021-06-20 op vl = buffer->current_line;
239 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
242 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), vl->parent->alt);
246 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
248 2b2d2872 2021-06-20 op struct vline *vl;
250 2b2d2872 2021-06-20 op vl = buffer->current_line;
251 2b2d2872 2021-06-20 op if (vl->parent->type != LINE_LINK)
254 2b2d2872 2021-06-20 op new_tab(vl->parent->alt);
258 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
260 5d0feb4b 2021-06-23 op struct excursion place;
262 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
265 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
266 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
267 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
268 2b2d2872 2021-06-20 op message("No previous link");
271 2b2d2872 2021-06-20 op cmd_previous_line(buffer);
272 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
276 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
278 5d0feb4b 2021-06-23 op struct excursion place;
280 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
283 2b2d2872 2021-06-20 op if (buffer->current_line == NULL ||
284 2b2d2872 2021-06-20 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
285 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
286 2b2d2872 2021-06-20 op message("No next link");
289 2b2d2872 2021-06-20 op cmd_next_line(buffer);
290 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
293 1c412d48 2021-06-25 op static inline int
294 1c412d48 2021-06-25 op is_heading(const struct line *l)
296 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
297 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
298 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
302 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
304 1c412d48 2021-06-25 op struct excursion place;
306 1c412d48 2021-06-25 op save_excursion(&place, buffer);
309 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
310 1c412d48 2021-06-25 op buffer->current_line == TAILQ_FIRST(&buffer->head)) {
311 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
312 1c412d48 2021-06-25 op message("No previous heading");
315 1c412d48 2021-06-25 op cmd_previous_line(buffer);
316 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
320 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
322 1c412d48 2021-06-25 op struct excursion place;
324 1c412d48 2021-06-25 op save_excursion(&place, buffer);
327 1c412d48 2021-06-25 op if (buffer->current_line == NULL ||
328 1c412d48 2021-06-25 op buffer->current_line == TAILQ_LAST(&buffer->head, vhead)) {
329 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
330 1c412d48 2021-06-25 op message("No next heading");
333 1c412d48 2021-06-25 op cmd_next_line(buffer);
334 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
338 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
340 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
342 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
343 2b2d2872 2021-06-20 op message("No previous page");
345 2b2d2872 2021-06-20 op start_loading_anim(tab);
349 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
351 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
353 2b2d2872 2021-06-20 op if (!load_next_page(tab))
354 2b2d2872 2021-06-20 op message("No next page");
356 2b2d2872 2021-06-20 op start_loading_anim(tab);
360 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
362 2b2d2872 2021-06-20 op message(NULL);
366 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
370 2b2d2872 2021-06-20 op if (in_minibuffer) {
371 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
375 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
376 2b2d2872 2021-06-20 op &eecmd_history);
378 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
379 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
381 2b2d2872 2021-06-20 op if (thiskey.meta)
382 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
384 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
386 2b2d2872 2021-06-20 op if (thiskey.meta)
387 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
391 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
393 2b2d2872 2021-06-20 op struct tab *tab, *t;
395 2b2d2872 2021-06-20 op tab = current_tab();
396 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
397 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
398 2b2d2872 2021-06-20 op message("Can't close the only tab.");
402 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
403 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
405 2b2d2872 2021-06-20 op stop_tab(tab);
407 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
408 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
409 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
412 2b2d2872 2021-06-20 op switch_to_tab(t);
416 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
418 2b2d2872 2021-06-20 op struct tab *t, *i;
420 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
421 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
425 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
431 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
433 2b2d2872 2021-06-20 op const char *url;
435 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
436 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
438 2b2d2872 2021-06-20 op new_tab(url);
442 2b2d2872 2021-06-20 op cmd_tab_next(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_NEXT(tab, tabs)) == NULL)
450 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&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_previous(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 tab->flags &= ~TAB_CURRENT;
463 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
464 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
465 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
466 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
470 2b2d2872 2021-06-20 op cmd_tab_move(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_NEXT(tab, 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 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
481 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
485 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
487 2b2d2872 2021-06-20 op struct tab *tab, *t;
489 2b2d2872 2021-06-20 op tab = current_tab();
490 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
491 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
493 2b2d2872 2021-06-20 op if (t == NULL) {
494 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
495 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
497 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
499 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
503 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
505 2b2d2872 2021-06-20 op if (in_minibuffer) {
506 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
510 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
511 2b2d2872 2021-06-20 op &lu_history);
512 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
513 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
514 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
518 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
520 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
522 2b2d2872 2021-06-20 op if (in_minibuffer) {
523 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
527 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
528 2b2d2872 2021-06-20 op &lu_history);
529 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
530 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
531 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
535 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
537 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
539 2b2d2872 2021-06-20 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
540 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
541 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
542 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
546 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
548 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
552 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
554 2b2d2872 2021-06-20 op ui_toggle_side_window();
558 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
560 61251035 2021-06-26 op if (fill_column == INT_MAX)
563 61251035 2021-06-26 op fill_column += 2;
564 61251035 2021-06-26 op message("fill-column: %d", fill_column);
566 61251035 2021-06-26 op ui_schedule_redraw();
570 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
572 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
575 61251035 2021-06-26 op fill_column -= 2;
576 61251035 2021-06-26 op message("fill-column: %d", fill_column);
578 61251035 2021-06-26 op ui_schedule_redraw();
582 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
584 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
585 2b2d2872 2021-06-20 op if (olivetti_mode)
586 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
588 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
590 2b2d2872 2021-06-20 op ui_schedule_redraw();
594 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
598 2b2d2872 2021-06-20 op if (!in_minibuffer) {
599 2b2d2872 2021-06-20 op message("text is read-only");
603 2b2d2872 2021-06-20 op minibuffer_taint_hist();
605 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
606 2b2d2872 2021-06-20 op if (*c == '\0')
608 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
610 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
614 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
616 2b2d2872 2021-06-20 op char *c, *p, *start;
618 2b2d2872 2021-06-20 op if (!in_minibuffer) {
619 2b2d2872 2021-06-20 op message("text is read-only");
623 2b2d2872 2021-06-20 op minibuffer_taint_hist();
625 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
626 2b2d2872 2021-06-20 op start = buffer->current_line->line;
627 2b2d2872 2021-06-20 op if (c == start)
629 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
631 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
632 2b2d2872 2021-06-20 op buffer->cpoff--;
636 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
640 2b2d2872 2021-06-20 op if (!in_minibuffer) {
641 2b2d2872 2021-06-20 op message("text is read-only");
645 2b2d2872 2021-06-20 op minibuffer_taint_hist();
646 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
651 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
653 2b2d2872 2021-06-20 op if (!in_minibuffer)
656 2b2d2872 2021-06-20 op ministate.abortfn();
660 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
662 2b2d2872 2021-06-20 op if (!in_minibuffer)
665 2b2d2872 2021-06-20 op minibuffer_taint_hist();
666 2b2d2872 2021-06-20 op ministate.donefn();
670 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
672 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
673 2b2d2872 2021-06-20 op message("No history");
677 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
678 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
679 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
680 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
681 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
682 2b2d2872 2021-06-20 op message("No prev item");
684 2b2d2872 2021-06-20 op ministate.hist_off--;
687 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
688 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
692 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
694 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
695 2b2d2872 2021-06-20 op message("No history");
699 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
700 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
701 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
702 2b2d2872 2021-06-20 op ministate.hist_off = 0;
703 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
704 2b2d2872 2021-06-20 op message("No next item");
706 2b2d2872 2021-06-20 op ministate.hist_off++;
709 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
710 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;