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 b1e1e41a 2021-07-14 op #include "compl.h"
22 e5a2797f 2021-07-13 op #include "defaults.h"
23 450a89f7 2021-07-12 op #include "minibuffer.h"
24 2b2d2872 2021-06-20 op #include "telescope.h"
25 d1a0f2a3 2021-07-12 op #include "ui.h"
26 5caf7d67 2021-07-12 op #include "utf8.h"
28 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
29 c4c82003 2021-07-01 op static inline int
30 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
32 c4c82003 2021-07-01 op struct vline *vl;
35 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
37 963c680c 2021-07-05 op vl = buffer->current_line;
40 c4c82003 2021-07-01 op while (n != 0) {
42 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
43 c4c82003 2021-07-01 op if (vl == NULL)
45 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
47 c4c82003 2021-07-01 op buffer->current_line = vl;
50 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
51 c4c82003 2021-07-01 op if (vl == NULL)
53 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
55 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
56 6e6c6afb 2021-07-14 op buffer->line_off--;
57 c4c82003 2021-07-01 op buffer->top_line = vl;
59 c4c82003 2021-07-01 op buffer->current_line = vl;
70 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
72 c4c82003 2021-07-01 op forward_line(buffer, -1);
76 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
78 c4c82003 2021-07-01 op forward_line(buffer, +1);
82 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
84 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
85 2b2d2872 2021-06-20 op buffer->cpoff--;
89 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
91 2b2d2872 2021-06-20 op size_t len = 0;
93 2b2d2872 2021-06-20 op if (buffer->current_line->line != NULL)
94 2b2d2872 2021-06-20 op len = utf8_cplen(buffer->current_line->line);
95 2b2d2872 2021-06-20 op if (++buffer->cpoff > len)
96 2b2d2872 2021-06-20 op buffer->cpoff = len;
100 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
103 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
104 2b2d2872 2021-06-20 op message("No previous paragraph");
107 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
108 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
112 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
115 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
116 2b2d2872 2021-06-20 op message("No next paragraph");
119 2b2d2872 2021-06-20 op } while (buffer->current_line->line != NULL ||
120 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
124 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
126 2b2d2872 2021-06-20 op buffer->cpoff = 0;
130 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
132 2b2d2872 2021-06-20 op struct vline *vl;
134 2b2d2872 2021-06-20 op vl = buffer->current_line;
135 2b2d2872 2021-06-20 op if (vl->line == NULL)
137 2b2d2872 2021-06-20 op buffer->cpoff = utf8_cplen(vl->line);
141 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
143 2b2d2872 2021-06-20 op ui_schedule_redraw();
147 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
149 e39920a9 2021-07-07 op struct vline *vl;
151 e39920a9 2021-07-07 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
155 e39920a9 2021-07-07 op forward_line(buffer, -1);
157 e39920a9 2021-07-07 op buffer->top_line = vl;
161 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
163 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
166 94ec38e8 2021-06-29 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
167 2b2d2872 2021-06-20 op buffer->line_off++;
171 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
173 d38e7214 2021-07-05 op forward_line(buffer, -1*body_lines);
177 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
179 d38e7214 2021-07-05 op forward_line(buffer, body_lines);
183 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
185 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
186 c4c82003 2021-07-01 op buffer->cpoff = 0;
187 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
188 2b2d2872 2021-06-20 op buffer->line_off = 0;
192 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
194 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
195 2b2d2872 2021-06-20 op buffer->cpoff = body_cols;
199 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
201 2b2d2872 2021-06-20 op save_session();
202 2b2d2872 2021-06-20 op event_loopbreak();
206 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
208 2b2d2872 2021-06-20 op struct vline *vl;
209 963c680c 2021-07-05 op struct line *l;
211 2b2d2872 2021-06-20 op vl = buffer->current_line;
212 963c680c 2021-07-05 op switch (vl->parent->type) {
213 963c680c 2021-07-05 op case LINE_LINK:
214 e9beee55 2021-07-14 op load_url_in_tab(current_tab(), vl->parent->meta.alt);
216 963c680c 2021-07-05 op case LINE_PRE_START:
217 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
218 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
219 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
221 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
222 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
223 6e6c6afb 2021-07-14 op buffer->line_max--;
225 6e6c6afb 2021-07-14 op buffer->line_max++;
234 2b2d2872 2021-06-20 op cmd_push_button_new_tab(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 e9beee55 2021-07-14 op new_tab(vl->parent->meta.alt);
246 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
248 5d0feb4b 2021-06-23 op struct excursion place;
250 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
253 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
254 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
255 2b2d2872 2021-06-20 op message("No previous link");
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 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
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 } while (buffer->current_line->parent->type != LINE_LINK);
277 1c412d48 2021-06-25 op static inline int
278 1c412d48 2021-06-25 op is_heading(const struct line *l)
280 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
281 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
282 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
286 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
288 1c412d48 2021-06-25 op struct excursion place;
290 1c412d48 2021-06-25 op save_excursion(&place, buffer);
293 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
294 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
295 1c412d48 2021-06-25 op message("No previous heading");
298 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
302 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
304 1c412d48 2021-06-25 op struct excursion place;
306 1c412d48 2021-06-25 op save_excursion(&place, buffer);
309 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
310 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
311 1c412d48 2021-06-25 op message("No next heading");
314 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
318 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
320 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
322 2b2d2872 2021-06-20 op if (!load_previous_page(tab))
323 2b2d2872 2021-06-20 op message("No previous page");
325 2b2d2872 2021-06-20 op start_loading_anim(tab);
329 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
331 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
333 2b2d2872 2021-06-20 op if (!load_next_page(tab))
334 2b2d2872 2021-06-20 op message("No next page");
336 2b2d2872 2021-06-20 op start_loading_anim(tab);
340 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
342 2b2d2872 2021-06-20 op message(NULL);
346 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
350 2b2d2872 2021-06-20 op if (in_minibuffer) {
351 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
355 2b2d2872 2021-06-20 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
356 b1e1e41a 2021-07-14 op &eecmd_history, compl_eecmd, NULL);
358 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
359 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
361 2b2d2872 2021-06-20 op if (thiskey.meta)
362 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
364 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
366 2b2d2872 2021-06-20 op if (thiskey.meta)
367 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
371 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
373 2b2d2872 2021-06-20 op struct tab *tab, *t;
375 2b2d2872 2021-06-20 op tab = current_tab();
376 2b2d2872 2021-06-20 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
377 2b2d2872 2021-06-20 op TAILQ_NEXT(tab, tabs) == NULL) {
378 2b2d2872 2021-06-20 op message("Can't close the only tab.");
382 2b2d2872 2021-06-20 op if (evtimer_pending(&tab->loadingev, NULL))
383 2b2d2872 2021-06-20 op evtimer_del(&tab->loadingev);
385 2b2d2872 2021-06-20 op stop_tab(tab);
387 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
388 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
389 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
392 2b2d2872 2021-06-20 op switch_to_tab(t);
396 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
398 2b2d2872 2021-06-20 op struct tab *t, *i;
400 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
401 2b2d2872 2021-06-20 op if (t->flags & TAB_CURRENT)
405 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, t, tabs);
411 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
413 2b2d2872 2021-06-20 op const char *url;
415 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
416 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
418 2b2d2872 2021-06-20 op new_tab(url);
422 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
424 2b2d2872 2021-06-20 op struct tab *tab, *t;
426 2b2d2872 2021-06-20 op tab = current_tab();
427 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
429 2b2d2872 2021-06-20 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
430 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
431 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
432 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
436 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
438 2b2d2872 2021-06-20 op struct tab *tab, *t;
440 2b2d2872 2021-06-20 op tab = current_tab();
441 2b2d2872 2021-06-20 op tab->flags &= ~TAB_CURRENT;
443 2b2d2872 2021-06-20 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
444 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
445 2b2d2872 2021-06-20 op t->flags |= TAB_CURRENT;
446 2b2d2872 2021-06-20 op t->flags &= ~TAB_URGENT;
450 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
452 2b2d2872 2021-06-20 op struct tab *tab, *t;
454 2b2d2872 2021-06-20 op tab = current_tab();
455 2b2d2872 2021-06-20 op t = TAILQ_NEXT(tab, tabs);
456 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
458 2b2d2872 2021-06-20 op if (t == NULL)
459 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
461 2b2d2872 2021-06-20 op TAILQ_INSERT_AFTER(&tabshead, t, tab, tabs);
465 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
467 2b2d2872 2021-06-20 op struct tab *tab, *t;
469 2b2d2872 2021-06-20 op tab = current_tab();
470 2b2d2872 2021-06-20 op t = TAILQ_PREV(tab, tabshead, tabs);
471 2b2d2872 2021-06-20 op TAILQ_REMOVE(&tabshead, tab, tabs);
473 2b2d2872 2021-06-20 op if (t == NULL) {
474 2b2d2872 2021-06-20 op if (TAILQ_EMPTY(&tabshead))
475 2b2d2872 2021-06-20 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
477 2b2d2872 2021-06-20 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
479 2b2d2872 2021-06-20 op TAILQ_INSERT_BEFORE(t, tab, tabs);
483 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
485 65601367 2021-07-14 op if (in_minibuffer) {
486 65601367 2021-07-14 op message("We don't have enable-recursive-minibuffers");
490 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
491 65601367 2021-07-14 op NULL, compl_ts, NULL);
492 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
496 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
498 2b2d2872 2021-06-20 op if (in_minibuffer) {
499 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
503 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
504 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
505 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
506 2b2d2872 2021-06-20 op strlcpy(ministate.buf, "gemini://", sizeof(ministate.buf));
507 2b2d2872 2021-06-20 op cmd_move_end_of_line(&ministate.buffer);
511 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
513 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
515 2b2d2872 2021-06-20 op if (in_minibuffer) {
516 2b2d2872 2021-06-20 op message("We don't have enable-recursive-minibuffers");
520 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
521 e5a2797f 2021-07-13 op &lu_history, NULL, NULL);
522 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
523 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
524 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
528 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
530 661233ed 2021-07-14 op struct tab *tab;
532 661233ed 2021-07-14 op tab = current_tab();
533 661233ed 2021-07-14 op load_url_in_tab(tab, tab->hist_cur->h);
537 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
539 2b2d2872 2021-06-20 op struct tab *tab = current_tab();
541 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
543 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
544 2b2d2872 2021-06-20 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
545 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
549 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
551 2b2d2872 2021-06-20 op load_url_in_tab(current_tab(), "about:bookmarks");
555 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
557 2b2d2872 2021-06-20 op ui_toggle_side_window();
561 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
563 753c6ac7 2021-07-14 op if (in_minibuffer) {
564 753c6ac7 2021-07-14 op message("We don't have enable-recursive-minibuffers");
568 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
569 753c6ac7 2021-07-14 op NULL, compl_ls, TAILQ_FIRST(&buffer->page.head));
570 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
574 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
576 753c6ac7 2021-07-14 op if (in_minibuffer) {
577 753c6ac7 2021-07-14 op message("We don't have enable-recursive-minibuffers");
581 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
582 753c6ac7 2021-07-14 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
583 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
587 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
589 edd9a650 2021-07-15 op if (in_minibuffer) {
590 edd9a650 2021-07-15 op message("We don't have enable-recursive-minibuffers");
594 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
595 edd9a650 2021-07-15 op NULL, compl_toc, TAILQ_FIRST(&buffer->page.head));
596 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
597 edd9a650 2021-07-15 op sizeof(ministate.prompt));
601 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
603 61251035 2021-06-26 op if (fill_column == INT_MAX)
606 61251035 2021-06-26 op fill_column += 2;
607 61251035 2021-06-26 op message("fill-column: %d", fill_column);
609 61251035 2021-06-26 op ui_schedule_redraw();
613 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
615 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
618 61251035 2021-06-26 op fill_column -= 2;
619 61251035 2021-06-26 op message("fill-column: %d", fill_column);
621 61251035 2021-06-26 op ui_schedule_redraw();
625 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
627 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
628 2b2d2872 2021-06-20 op if (olivetti_mode)
629 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
631 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
633 2b2d2872 2021-06-20 op ui_schedule_redraw();
637 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
641 2b2d2872 2021-06-20 op if (!in_minibuffer) {
642 2b2d2872 2021-06-20 op message("text is read-only");
646 2b2d2872 2021-06-20 op minibuffer_taint_hist();
648 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
649 2b2d2872 2021-06-20 op if (*c == '\0')
651 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
653 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
655 b1e1e41a 2021-07-14 op recompute_completions(0);
659 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
661 2b2d2872 2021-06-20 op char *c, *p, *start;
663 2b2d2872 2021-06-20 op if (!in_minibuffer) {
664 2b2d2872 2021-06-20 op message("text is read-only");
668 2b2d2872 2021-06-20 op minibuffer_taint_hist();
670 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
671 2b2d2872 2021-06-20 op start = buffer->current_line->line;
672 2b2d2872 2021-06-20 op if (c == start)
674 2b2d2872 2021-06-20 op p = utf8_prev_cp(c-1, start);
676 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
677 2b2d2872 2021-06-20 op buffer->cpoff--;
679 b1e1e41a 2021-07-14 op recompute_completions(0);
683 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
687 2b2d2872 2021-06-20 op if (!in_minibuffer) {
688 2b2d2872 2021-06-20 op message("text is read-only");
692 2b2d2872 2021-06-20 op minibuffer_taint_hist();
693 2b2d2872 2021-06-20 op c = utf8_nth(buffer->current_line->line, buffer->cpoff);
696 b1e1e41a 2021-07-14 op recompute_completions(0);
700 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
702 2b2d2872 2021-06-20 op if (!in_minibuffer)
705 2b2d2872 2021-06-20 op ministate.abortfn();
709 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
711 2b2d2872 2021-06-20 op if (!in_minibuffer)
714 2b2d2872 2021-06-20 op minibuffer_taint_hist();
715 2b2d2872 2021-06-20 op ministate.donefn();
719 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
721 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
722 2b2d2872 2021-06-20 op message("No history");
726 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
727 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
728 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
729 2b2d2872 2021-06-20 op ministate.hist_off = ministate.history->len - 1;
730 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
731 fc14510d 2021-07-14 op message("No prev history item");
733 2b2d2872 2021-06-20 op ministate.hist_off--;
736 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
737 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
741 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
743 2b2d2872 2021-06-20 op if (ministate.history == NULL) {
744 2b2d2872 2021-06-20 op message("No history");
748 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL ||
749 2b2d2872 2021-06-20 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
750 2b2d2872 2021-06-20 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
751 2b2d2872 2021-06-20 op ministate.hist_off = 0;
752 2b2d2872 2021-06-20 op if (ministate.hist_cur == NULL)
753 fc14510d 2021-07-14 op message("No next history item");
755 2b2d2872 2021-06-20 op ministate.hist_off++;
758 2b2d2872 2021-06-20 op if (ministate.hist_cur != NULL)
759 2b2d2872 2021-06-20 op buffer->current_line->line = ministate.hist_cur->h;
763 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
765 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
768 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
770 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
771 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
773 e7b982f4 2021-07-14 op forward_line(buffer, -1);
775 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
776 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
780 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
782 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
785 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
787 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
788 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
790 e7b982f4 2021-07-14 op forward_line(buffer, +1);
792 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
793 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
797 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
799 e7b982f4 2021-07-14 op struct vline *vl;
801 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
804 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
805 e7b982f4 2021-07-14 op if ((vl = buffer->current_line) == NULL)
808 e7b982f4 2021-07-14 op minibuffer_taint_hist();
809 e7b982f4 2021-07-14 op strlcpy(ministate.buf, vl->parent->line, sizeof(ministate.buf));
810 e7b982f4 2021-07-14 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);