0002
2021-06-20
op
* Copyright (c) 2021 Omar Polo <op@omarpolo.com>
0004
2021-06-20
op
* Permission to use, copy, modify, and distribute this software for any
0005
2021-06-20
op
* purpose with or without fee is hereby granted, provided that the above
0006
2021-06-20
op
* copyright notice and this permission notice appear in all copies.
0008
2021-06-20
op
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0009
2021-06-20
op
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0010
2021-06-20
op
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0011
2021-06-20
op
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0012
2021-06-20
op
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0013
2021-06-20
op
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0014
2021-06-20
op
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0017
2021-07-21
op
#include "compat.h"
0019
2021-06-26
op
#include <limits.h>
0020
2021-06-20
op
#include <stdlib.h>
0021
2021-06-26
op
#include <string.h>
0023
2021-07-14
op
#include "compl.h"
0024
2021-07-13
op
#include "defaults.h"
0025
2022-01-11
op
#include "mcache.h"
0026
2021-07-12
op
#include "minibuffer.h"
0027
2021-08-14
op
#include "session.h"
0028
2021-06-20
op
#include "telescope.h"
0029
2021-07-12
op
#include "ui.h"
0030
2021-07-12
op
#include "utf8.h"
0031
2022-02-08
op
#include "utils.h"
0033
2021-07-15
op
#define GUARD_RECURSIVE_MINIBUFFER() \
0035
2021-07-15
op
if (in_minibuffer) { \
0036
2021-07-15
op
message("enable-recursive-minibuffers " \
0037
2021-07-15
op
"is not yet available."); \
0038
2021-07-15
op
return; \
0040
2021-07-15
op
} while(0)
0042
2021-07-19
op
#define GUARD_READ_ONLY() \
0044
2021-07-19
op
if (!in_minibuffer) { \
0045
2021-07-19
op
message("text is read-only"); \
0046
2021-07-19
op
return; \
0048
2021-07-19
op
} while(0)
0050
2021-07-01
op
/* return 1 if moved, 0 otherwise */
0051
2021-07-01
op
static inline int
0052
2021-07-01
op
forward_line(struct buffer *buffer, int n)
0054
2021-07-01
op
struct vline *vl;
0055
2021-07-01
op
int did;
0057
2021-07-01
op
if (buffer->current_line == NULL)
0058
2021-07-01
op
return 0;
0059
2021-07-05
op
vl = buffer->current_line;
0061
2021-07-01
op
did = 0;
0062
2021-07-01
op
while (n != 0) {
0063
2021-07-01
op
if (n > 0) {
0064
2021-07-05
op
vl = TAILQ_NEXT(vl, vlines);
0065
2021-07-01
op
if (vl == NULL)
0066
2021-07-01
op
return did;
0067
2021-07-05
op
if (vl->parent->flags & L_HIDDEN)
0068
2021-07-05
op
continue;
0069
2021-07-01
op
buffer->current_line = vl;
0071
2021-07-01
op
} else {
0072
2021-07-05
op
vl = TAILQ_PREV(vl, vhead, vlines);
0073
2021-07-01
op
if (vl == NULL)
0074
2021-07-01
op
return did;
0075
2021-07-05
op
if (vl->parent->flags & L_HIDDEN)
0076
2021-07-05
op
continue;
0077
2021-07-14
op
if (buffer->current_line == buffer->top_line) {
0078
2021-07-14
op
buffer->line_off--;
0079
2021-07-01
op
buffer->top_line = vl;
0081
2021-07-01
op
buffer->current_line = vl;
0085
2021-07-01
op
did = 1;
0088
2021-07-01
op
return did;
0092
2021-07-01
op
cmd_previous_line(struct buffer *buffer)
0094
2021-07-01
op
forward_line(buffer, -1);
0098
2021-07-01
op
cmd_next_line(struct buffer *buffer)
0100
2021-07-01
op
forward_line(buffer, +1);
0104
2021-06-20
op
cmd_backward_char(struct buffer *buffer)
0106
2021-06-20
op
if (buffer->cpoff != 0)
0107
2021-06-20
op
buffer->cpoff--;
0111
2021-06-20
op
cmd_forward_char(struct buffer *buffer)
0113
2021-06-20
op
size_t len = 0;
0115
2021-07-19
op
if (buffer->current_line == NULL)
0118
2021-06-20
op
if (buffer->current_line->line != NULL)
0119
2021-06-20
op
len = utf8_cplen(buffer->current_line->line);
0120
2021-06-20
op
if (++buffer->cpoff > len)
0121
2021-06-20
op
buffer->cpoff = len;
0125
2021-06-20
op
cmd_backward_paragraph(struct buffer *buffer)
0128
2021-07-01
op
if (!forward_line(buffer, -1)) {
0129
2021-06-20
op
message("No previous paragraph");
0132
2021-06-20
op
} while (buffer->current_line->line != NULL ||
0133
2021-06-20
op
buffer->current_line->parent->type != LINE_TEXT);
0137
2021-06-20
op
cmd_forward_paragraph(struct buffer *buffer)
0140
2021-07-01
op
if (!forward_line(buffer, +1)) {
0141
2021-06-20
op
message("No next paragraph");
0144
2021-06-20
op
} while (buffer->current_line->line != NULL ||
0145
2021-06-20
op
buffer->current_line->parent->type != LINE_TEXT);
0149
2021-06-20
op
cmd_move_beginning_of_line(struct buffer *buffer)
0151
2021-06-20
op
buffer->cpoff = 0;
0155
2021-06-20
op
cmd_move_end_of_line(struct buffer *buffer)
0157
2021-06-20
op
struct vline *vl;
0159
2021-06-20
op
vl = buffer->current_line;
0160
2021-07-19
op
if (vl == NULL || vl->line == NULL)
0162
2021-06-20
op
buffer->cpoff = utf8_cplen(vl->line);
0166
2021-06-20
op
cmd_redraw(struct buffer *buffer)
0168
2021-08-26
op
ui_schedule_redraw();
0172
2021-06-20
op
cmd_scroll_line_up(struct buffer *buffer)
0174
2021-07-07
op
struct vline *vl;
0176
2021-07-30
op
for (;;) {
0177
2021-07-30
op
if (buffer->top_line == NULL)
0180
2021-07-30
op
if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
0181
2021-07-30
op
== NULL)
0184
2021-07-30
op
buffer->top_line = vl;
0186
2021-07-30
op
if (vl->parent->flags & L_HIDDEN)
0187
2021-07-30
op
continue;
0192
2021-07-21
op
buffer->line_off--;
0194
2021-07-30
op
forward_line(buffer, -1);
0198
2021-06-20
op
cmd_scroll_line_down(struct buffer *buffer)
0200
2021-07-01
op
if (!forward_line(buffer, +1))
0203
2021-07-30
op
for (;;) {
0204
2021-07-30
op
if (buffer->top_line == NULL)
0207
2021-07-30
op
buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
0208
2021-07-30
op
if (buffer->top_line->parent->flags & L_HIDDEN)
0209
2021-07-30
op
continue;
0213
2021-06-20
op
buffer->line_off++;
0217
2021-06-20
op
cmd_scroll_up(struct buffer *buffer)
0219
2021-07-15
op
struct vline *vl;
0222
2021-07-24
op
if (buffer->top_line == NULL)
0225
2021-07-15
op
for (i = 0; i < body_lines; ++i) {
0226
2021-07-15
op
vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
0227
2021-07-15
op
if (vl == NULL)
0229
2021-07-19
op
buffer->line_off--;
0230
2021-07-15
op
buffer->top_line = vl;
0231
2021-07-15
op
forward_line(buffer, -1);
0236
2021-06-20
op
cmd_scroll_down(struct buffer *buffer)
0240
2021-07-24
op
if (buffer->top_line == NULL)
0243
2021-07-15
op
for (i = 0; i < body_lines; ++i) {
0244
2021-07-15
op
if (!forward_line(buffer, +1))
0247
2021-07-15
op
buffer->top_line = TAILQ_NEXT(buffer->top_line,
0248
2021-07-15
op
vlines);
0249
2021-07-19
op
buffer->line_off++;
0254
2021-06-20
op
cmd_beginning_of_buffer(struct buffer *buffer)
0256
2021-06-20
op
buffer->current_line = TAILQ_FIRST(&buffer->head);
0257
2021-07-01
op
buffer->cpoff = 0;
0258
2021-06-29
op
buffer->top_line = buffer->current_line;
0259
2021-06-20
op
buffer->line_off = 0;
0263
2021-06-20
op
cmd_end_of_buffer(struct buffer *buffer)
0265
2021-06-20
op
buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
0267
2021-07-19
op
if (buffer->current_line == NULL)
0270
2021-07-18
op
/* deal with invisible lines */
0271
2021-07-18
op
if (buffer->current_line->parent->flags & L_HIDDEN)
0272
2021-07-18
op
forward_line(buffer, -1);
0274
2021-07-18
op
cmd_move_end_of_line(buffer);
0277
2021-01-02
op
static void
0278
2021-01-02
op
kill_telescope_cb(int r, struct tab *tab)
0280
2021-01-02
op
if (r) {
0281
2021-01-02
op
save_session();
0282
2021-01-02
op
event_loopbreak();
0287
2021-06-20
op
cmd_kill_telescope(struct buffer *buffer)
0289
2021-01-02
op
yornp("really quit?", kill_telescope_cb, NULL);
0293
2021-06-20
op
cmd_push_button(struct buffer *buffer)
0295
2021-06-20
op
struct vline *vl;
0296
2021-07-05
op
struct line *l;
0298
2021-06-20
op
vl = buffer->current_line;
0300
2021-07-19
op
if (vl == NULL)
0303
2021-07-05
op
switch (vl->parent->type) {
0304
2021-07-05
op
case LINE_LINK:
0305
2022-01-11
op
load_url_in_tab(current_tab, vl->parent->alt, NULL,
0306
2022-01-11
op
LU_MODE_NOCACHE);
0308
2021-07-05
op
case LINE_PRE_START:
0309
2021-07-05
op
l = TAILQ_NEXT(vl->parent, lines);
0310
2021-07-05
op
for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
0311
2021-07-05
op
if (l->type == LINE_PRE_END)
0313
2021-07-05
op
l->flags ^= L_HIDDEN;
0314
2021-07-14
op
if (l->flags & L_HIDDEN)
0315
2021-07-14
op
buffer->line_max--;
0317
2021-07-14
op
buffer->line_max++;
0320
2021-07-05
op
default:
0326
2021-06-20
op
cmd_push_button_new_tab(struct buffer *buffer)
0328
2021-06-20
op
struct vline *vl;
0330
2021-06-20
op
vl = buffer->current_line;
0331
2021-07-19
op
if (vl == NULL || vl->parent->type != LINE_LINK)
0334
2021-08-12
op
new_tab(vl->parent->alt, current_tab->hist_cur->h, current_tab);
0338
2021-06-20
op
cmd_previous_button(struct buffer *buffer)
0340
2021-06-23
op
struct excursion place;
0342
2021-06-23
op
save_excursion(&place, buffer);
0345
2021-07-01
op
if (!forward_line(buffer, -1)) {
0346
2021-06-23
op
restore_excursion(&place, buffer);
0347
2021-06-20
op
message("No previous link");
0350
2021-06-20
op
} while (buffer->current_line->parent->type != LINE_LINK);
0354
2021-06-20
op
cmd_next_button(struct buffer *buffer)
0356
2021-06-23
op
struct excursion place;
0358
2021-06-23
op
save_excursion(&place, buffer);
0361
2021-07-01
op
if (!forward_line(buffer, +1)){
0362
2021-06-23
op
restore_excursion(&place, buffer);
0363
2021-06-20
op
message("No next link");
0366
2021-06-20
op
} while (buffer->current_line->parent->type != LINE_LINK);
0369
2021-06-25
op
static inline int
0370
2021-06-25
op
is_heading(const struct line *l)
0372
2021-06-25
op
return l->type == LINE_TITLE_1 ||
0373
2021-06-25
op
l->type == LINE_TITLE_2 ||
0374
2021-06-25
op
l->type == LINE_TITLE_3;
0378
2021-06-25
op
cmd_previous_heading(struct buffer *buffer)
0380
2021-06-25
op
struct excursion place;
0382
2021-06-25
op
save_excursion(&place, buffer);
0385
2021-07-01
op
if (!forward_line(buffer, -1)) {
0386
2021-06-25
op
restore_excursion(&place, buffer);
0387
2021-06-25
op
message("No previous heading");
0390
2021-06-25
op
} while (!is_heading(buffer->current_line->parent));
0394
2021-06-25
op
cmd_next_heading(struct buffer *buffer)
0396
2021-06-25
op
struct excursion place;
0398
2021-06-25
op
save_excursion(&place, buffer);
0401
2021-07-01
op
if (!forward_line(buffer, +1)) {
0402
2021-06-25
op
restore_excursion(&place, buffer);
0403
2021-06-25
op
message("No next heading");
0406
2021-06-25
op
} while (!is_heading(buffer->current_line->parent));
0410
2021-06-20
op
cmd_previous_page(struct buffer *buffer)
0412
2021-07-17
op
if (!load_previous_page(current_tab))
0413
2021-06-20
op
message("No previous page");
0417
2021-06-20
op
cmd_next_page(struct buffer *buffer)
0419
2021-07-17
op
if (!load_next_page(current_tab))
0420
2021-06-20
op
message("No next page");
0424
2021-06-20
op
cmd_clear_minibuf(struct buffer *buffer)
0426
2021-08-26
op
message(NULL);
0430
2021-06-20
op
cmd_execute_extended_command(struct buffer *buffer)
0432
2021-06-20
op
size_t len;
0434
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0436
2021-07-24
op
enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
0437
2022-04-13
op
&eecmd_history, compl_eecmd, NULL, 1);
0439
2021-06-20
op
len = sizeof(ministate.prompt);
0440
2021-06-20
op
strlcpy(ministate.prompt, "", len);
0442
2021-06-20
op
if (thiskey.meta)
0443
2021-06-20
op
strlcat(ministate.prompt, "M-", len);
0445
2021-06-20
op
strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
0447
2021-06-20
op
if (thiskey.meta)
0448
2021-06-20
op
strlcat(ministate.prompt, " ", len);
0452
2021-06-20
op
cmd_tab_close(struct buffer *buffer)
0454
2021-06-20
op
struct tab *tab, *t;
0456
2021-07-17
op
tab = current_tab;
0458
2021-07-21
op
if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
0459
2021-07-21
op
(t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
0460
2021-07-21
op
switch_to_tab(t);
0461
2022-01-06
op
kill_tab(tab, 0);
0463
2021-07-21
op
message("Can't close the only tab.");
0468
2021-06-20
op
cmd_tab_close_other(struct buffer *buffer)
0470
2021-06-20
op
struct tab *t, *i;
0472
2021-06-20
op
TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
0473
2021-07-17
op
if (t == current_tab)
0474
2021-06-20
op
continue;
0476
2022-01-06
op
kill_tab(t, 0);
0481
2022-01-05
op
cmd_tab_undo_close(struct buffer *buffer)
0483
2022-01-05
op
struct tab *t;
0485
2022-01-05
op
if ((t = unkill_tab()) == NULL) {
0486
2022-01-05
op
message("No recently-closed tabs");
0490
2022-01-05
op
switch_to_tab(t);
0494
2021-06-20
op
cmd_tab_new(struct buffer *buffer)
0496
2021-06-20
op
const char *url;
0498
2021-06-20
op
if ((url = new_tab_url) == NULL)
0499
2021-06-20
op
url = NEW_TAB_URL;
0501
2021-08-12
op
new_tab(url, NULL, NULL);
0505
2021-06-20
op
cmd_tab_next(struct buffer *buffer)
0507
2021-07-17
op
struct tab *t;
0509
2021-07-17
op
if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
0510
2021-06-20
op
t = TAILQ_FIRST(&tabshead);
0511
2021-07-17
op
switch_to_tab(t);
0515
2021-06-20
op
cmd_tab_previous(struct buffer *buffer)
0517
2021-07-17
op
struct tab *t;
0519
2021-07-17
op
if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
0520
2021-06-20
op
t = TAILQ_LAST(&tabshead, tabshead);
0521
2021-07-17
op
switch_to_tab(t);
0525
2021-06-20
op
cmd_tab_move(struct buffer *buffer)
0527
2021-07-17
op
struct tab *t;
0529
2021-07-17
op
t = TAILQ_NEXT(current_tab, tabs);
0530
2021-07-17
op
TAILQ_REMOVE(&tabshead, current_tab, tabs);
0532
2021-06-20
op
if (t == NULL)
0533
2021-07-17
op
TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
0535
2021-07-17
op
TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
0539
2021-06-20
op
cmd_tab_move_to(struct buffer *buffer)
0541
2021-07-17
op
struct tab *t;
0543
2021-07-17
op
t = TAILQ_PREV(current_tab, tabshead, tabs);
0544
2021-07-17
op
TAILQ_REMOVE(&tabshead, current_tab, tabs);
0546
2021-08-12
op
if (t == NULL)
0547
2021-08-12
op
TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
0549
2021-07-17
op
TAILQ_INSERT_BEFORE(t, current_tab, tabs);
0553
2021-07-14
op
cmd_tab_select(struct buffer *buffer)
0555
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0557
2021-07-14
op
enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
0558
2022-04-13
op
NULL, compl_ts, NULL, 1);
0559
2021-07-14
op
strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
0563
2021-06-20
op
cmd_load_url(struct buffer *buffer)
0565
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0567
2021-07-14
op
enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
0568
2022-04-13
op
&lu_history, compl_lu, NULL, 0);
0569
2021-06-20
op
strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
0573
2021-06-20
op
cmd_load_current_url(struct buffer *buffer)
0575
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0577
2021-07-14
op
enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
0578
2022-04-13
op
&lu_history, compl_lu, NULL, 0);
0579
2021-06-20
op
strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
0580
2021-07-17
op
strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
0581
2021-06-20
op
ministate.buffer.cpoff = utf8_cplen(ministate.buf);
0585
2021-07-14
op
cmd_reload_page(struct buffer *buffer)
0587
2022-01-11
op
load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL,
0588
2022-01-11
op
LU_MODE_NOHIST|LU_MODE_NOCACHE);
0592
2021-06-20
op
cmd_bookmark_page(struct buffer *buffer)
0594
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0596
2021-07-14
op
enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
0597
2022-04-13
op
NULL, NULL, 0);
0598
2021-06-20
op
strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
0599
2021-07-17
op
strlcpy(ministate.buf, current_tab->hist_cur->h, sizeof(ministate.buf));
0600
2021-06-20
op
ministate.buffer.cpoff = utf8_cplen(ministate.buf);
0604
2021-06-20
op
cmd_list_bookmarks(struct buffer *buffer)
0606
2022-01-11
op
load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
0610
2021-06-20
op
cmd_toggle_help(struct buffer *buffer)
0612
2021-11-05
op
ui_toggle_side_window(SIDE_WINDOW_LEFT);
0616
2021-07-14
op
cmd_link_select(struct buffer *buffer)
0618
2021-07-15
op
struct line *l;
0620
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0622
2021-07-15
op
l = TAILQ_FIRST(&buffer->page.head);
0623
2021-07-15
op
while (l != NULL && l->type != LINE_LINK)
0624
2021-07-15
op
l = TAILQ_NEXT(l, lines);
0626
2021-07-15
op
if (l == NULL) {
0627
2021-07-15
op
message("No links found");
0631
2021-07-14
op
enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
0632
2022-04-13
op
NULL, compl_ls, l, 1);
0633
2021-07-14
op
strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
0637
2021-07-14
op
cmd_swiper(struct buffer *buffer)
0639
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0641
2021-07-14
op
enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
0642
2022-04-13
op
NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head), 1);
0643
2021-07-14
op
strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
0647
2021-07-15
op
cmd_toc(struct buffer *buffer)
0649
2021-07-15
op
struct line *l;
0651
2021-07-15
op
GUARD_RECURSIVE_MINIBUFFER();
0653
2021-07-15
op
l = TAILQ_FIRST(&buffer->page.head);
0654
2021-07-15
op
while (l != NULL &&
0655
2021-07-15
op
l->type != LINE_TITLE_1 &&
0656
2021-07-15
op
l->type != LINE_TITLE_2 &&
0657
2021-07-15
op
l->type != LINE_TITLE_3)
0658
2021-07-15
op
l = TAILQ_NEXT(l, lines);
0660
2021-07-15
op
if (l == NULL) {
0661
2021-07-15
op
message("No headings found");
0665
2021-07-15
op
enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
0666
2022-04-13
op
NULL, compl_toc, l, 1);
0667
2021-07-15
op
strlcpy(ministate.prompt, "Select heading: ",
0668
2021-07-15
op
sizeof(ministate.prompt));
0672
2021-06-26
op
cmd_inc_fill_column(struct buffer *buffer)
0674
2021-06-26
op
if (fill_column == INT_MAX)
0677
2021-06-26
op
fill_column += 2;
0678
2021-06-26
op
message("fill-column: %d", fill_column);
0680
2021-06-26
op
ui_schedule_redraw();
0684
2021-06-26
op
cmd_dec_fill_column(struct buffer *buffer)
0686
2021-06-26
op
if (fill_column == INT_MAX || fill_column < 8)
0689
2021-06-26
op
fill_column -= 2;
0690
2021-06-26
op
message("fill-column: %d", fill_column);
0692
2021-06-26
op
ui_schedule_redraw();
0696
2021-06-20
op
cmd_olivetti_mode(struct buffer *buffer)
0698
2021-06-20
op
olivetti_mode = !olivetti_mode;
0699
2021-06-20
op
if (olivetti_mode)
0700
2021-06-20
op
message("olivetti-mode enabled");
0702
2021-06-20
op
message("olivetti-mode disabled");
0704
2021-06-20
op
ui_schedule_redraw();
0708
2021-06-20
op
cmd_mini_delete_char(struct buffer *buffer)
0710
2021-06-20
op
char *c, *n;
0712
2021-07-19
op
GUARD_READ_ONLY();
0714
2021-06-20
op
minibuffer_taint_hist();
0716
2021-06-20
op
c = utf8_nth(buffer->current_line->line, buffer->cpoff);
0717
2021-06-20
op
if (*c == '\0')
0719
2021-06-20
op
n = utf8_next_cp(c);
0721
2021-06-20
op
memmove(c, n, strlen(n)+1);
0723
2021-07-14
op
recompute_completions(0);
0727
2021-06-20
op
cmd_mini_delete_backward_char(struct buffer *buffer)
0729
2021-06-20
op
char *c, *p, *start;
0731
2021-07-19
op
GUARD_READ_ONLY();
0733
2021-06-20
op
minibuffer_taint_hist();
0735
2021-06-20
op
c = utf8_nth(buffer->current_line->line, buffer->cpoff);
0736
2021-06-20
op
start = buffer->current_line->line;
0737
2021-06-20
op
if (c == start)
0739
2021-06-20
op
p = utf8_prev_cp(c-1, start);
0741
2021-06-20
op
memmove(p, c, strlen(c)+1);
0742
2021-06-20
op
buffer->cpoff--;
0744
2021-07-14
op
recompute_completions(0);
0748
2021-06-20
op
cmd_mini_kill_line(struct buffer *buffer)
0750
2021-06-20
op
char *c;
0752
2021-07-19
op
GUARD_READ_ONLY();
0754
2021-06-20
op
minibuffer_taint_hist();
0755
2021-06-20
op
c = utf8_nth(buffer->current_line->line, buffer->cpoff);
0756
2021-06-20
op
*c = '\0';
0758
2021-07-14
op
recompute_completions(0);
0762
2022-04-15
op
cmd_mini_kill_whole_line(struct buffer *buffer)
0764
2022-04-15
op
GUARD_READ_ONLY();
0766
2022-04-15
op
minibuffer_taint_hist();
0767
2022-04-15
op
*buffer->current_line->line = '\0';
0768
2022-04-15
op
buffer->cpoff = 0;
0772
2021-06-20
op
cmd_mini_abort(struct buffer *buffer)
0774
2021-06-20
op
if (!in_minibuffer)
0777
2021-06-20
op
ministate.abortfn();
0781
2021-06-20
op
cmd_mini_complete_and_exit(struct buffer *buffer)
0783
2022-04-13
op
struct vline *vl;
0785
2021-06-20
op
if (!in_minibuffer)
0788
2022-04-15
op
if (ministate.compl.must_select && ministate.hist_cur == NULL) {
0789
2022-04-13
op
vl = ministate.compl.buffer.current_line;
0790
2022-04-13
op
if (vl == NULL || vl->parent->flags & L_HIDDEN ||
0791
2022-04-13
op
vl->parent->type == LINE_COMPL) {
0792
2022-04-13
op
message("no match");
0797
2021-06-20
op
minibuffer_taint_hist();
0798
2021-06-20
op
ministate.donefn();
0802
2021-06-20
op
cmd_mini_previous_history_element(struct buffer *buffer)
0804
2021-06-20
op
if (ministate.history == NULL) {
0805
2021-06-20
op
message("No history");
0809
2021-06-20
op
if (ministate.hist_cur == NULL ||
0810
2021-06-20
op
(ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
0811
2021-06-20
op
ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
0812
2021-06-20
op
ministate.hist_off = ministate.history->len - 1;
0813
2021-06-20
op
if (ministate.hist_cur == NULL)
0814
2021-07-14
op
message("No prev history item");
0815
2021-06-20
op
} else {
0816
2021-06-20
op
ministate.hist_off--;
0819
2022-04-15
op
if (ministate.hist_cur != NULL) {
0820
2021-06-20
op
buffer->current_line->line = ministate.hist_cur->h;
0821
2022-04-15
op
recompute_completions(0);
0826
2021-06-20
op
cmd_mini_next_history_element(struct buffer *buffer)
0828
2021-06-20
op
if (ministate.history == NULL) {
0829
2021-06-20
op
message("No history");
0833
2021-06-20
op
if (ministate.hist_cur == NULL ||
0834
2021-06-20
op
(ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
0835
2021-06-20
op
ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
0836
2021-06-20
op
ministate.hist_off = 0;
0837
2021-06-20
op
if (ministate.hist_cur == NULL)
0838
2021-07-14
op
message("No next history item");
0839
2021-06-20
op
} else {
0840
2021-06-20
op
ministate.hist_off++;
0843
2022-04-15
op
if (ministate.hist_cur != NULL) {
0844
2021-06-20
op
buffer->current_line->line = ministate.hist_cur->h;
0845
2022-04-15
op
recompute_completions(0);
0850
2021-07-14
op
cmd_previous_completion(struct buffer *buffer)
0852
2021-07-14
op
if (in_minibuffer != MB_COMPREAD)
0855
2021-07-14
op
buffer = &ministate.compl.buffer;
0856
2022-04-13
op
if (buffer->current_line == NULL)
0859
2022-04-13
op
buffer->current_line->parent->type = LINE_COMPL;
0860
2022-04-13
op
if (!forward_line(buffer, -1))
0861
2021-07-14
op
buffer->current_line->parent->type = LINE_COMPL;
0863
2021-07-14
op
buffer->current_line->parent->type = LINE_COMPL_CURRENT;
0867
2021-07-14
op
cmd_next_completion(struct buffer *buffer)
0869
2021-07-14
op
if (in_minibuffer != MB_COMPREAD)
0872
2021-07-14
op
buffer = &ministate.compl.buffer;
0873
2022-04-13
op
if (buffer->current_line == NULL)
0876
2022-04-13
op
if (buffer->current_line->parent->type == LINE_COMPL_CURRENT) {
0877
2021-07-14
op
buffer->current_line->parent->type = LINE_COMPL;
0878
2022-04-13
op
forward_line(buffer, +1);
0881
2021-07-14
op
if (buffer->current_line != NULL)
0882
2021-07-14
op
buffer->current_line->parent->type = LINE_COMPL_CURRENT;
0886
2021-07-14
op
cmd_insert_current_candidate(struct buffer *buffer)
0888
2021-07-14
op
if (in_minibuffer != MB_COMPREAD)
0891
2021-01-02
op
minibuffer_insert_current_candidate();
0895
2021-07-15
op
cmd_suspend_telescope(struct buffer *buffer)
0897
2021-07-15
op
message("Zzz...");
0898
2021-07-15
op
ui_suspend();
0902
2021-07-15
op
cmd_toggle_pre_wrap(struct buffer *buffer)
0904
2021-07-15
op
dont_wrap_pre = !dont_wrap_pre;
0906
2021-07-15
op
if (dont_wrap_pre)
0907
2021-07-15
op
message("Don't wrap preformatted blocks");
0909
2021-07-15
op
message("Wrap preformatted blocks");
0911
2021-07-15
op
ui_schedule_redraw();
0915
2021-07-17
op
cmd_mini_goto_beginning(struct buffer *buffer)
0917
2021-07-17
op
struct vline *vl;
0919
2021-07-17
op
if (!in_minibuffer)
0922
2021-07-17
op
buffer = &ministate.compl.buffer;
0924
2021-07-17
op
if ((vl = buffer->current_line) != NULL)
0925
2021-07-17
op
vl->parent->type = LINE_COMPL;
0927
2021-07-17
op
vl = TAILQ_FIRST(&buffer->head);
0928
2021-07-17
op
while (vl != NULL && vl->parent->flags & L_HIDDEN)
0929
2021-07-17
op
vl = TAILQ_NEXT(vl, vlines);
0931
2021-07-17
op
if (vl == NULL)
0934
2021-07-17
op
vl->parent->type = LINE_COMPL_CURRENT;
0935
2021-07-17
op
buffer->top_line = vl;
0936
2021-07-17
op
buffer->current_line = vl;
0940
2021-07-17
op
cmd_mini_goto_end(struct buffer *buffer)
0942
2021-07-17
op
struct vline *vl;
0944
2021-07-17
op
if (!in_minibuffer)
0947
2021-07-17
op
buffer = &ministate.compl.buffer;
0949
2021-07-17
op
if ((vl = buffer->current_line) != NULL)
0950
2021-07-17
op
vl->parent->type = LINE_COMPL;
0952
2021-07-17
op
vl = TAILQ_LAST(&buffer->head, vhead);
0953
2021-07-17
op
while (vl != NULL && vl->parent->flags & L_HIDDEN)
0954
2021-07-17
op
vl = TAILQ_PREV(vl, vhead, vlines);
0956
2021-07-17
op
if (vl == NULL)
0959
2021-07-17
op
vl->parent->type = LINE_COMPL_CURRENT;
0960
2021-07-17
op
buffer->current_line = vl;
0964
2021-07-21
op
cmd_other_window(struct buffer *buffer)
0966
2021-07-21
op
ui_other_window();
0970
2021-07-24
op
cmd_mini_scroll_up(struct buffer *buffer)
0972
2021-07-24
op
if (!in_minibuffer)
0975
2021-08-26
op
buffer = &ministate.compl.buffer;
0976
2021-07-24
op
if (buffer->current_line == NULL)
0979
2021-07-24
op
buffer->current_line->parent->type = LINE_COMPL;
0980
2021-07-24
op
cmd_scroll_up(buffer);
0981
2021-07-24
op
buffer->current_line->parent->type = LINE_COMPL_CURRENT;
0985
2021-07-24
op
cmd_mini_scroll_down(struct buffer *buffer)
0987
2021-07-24
op
if (!in_minibuffer)
0990
2021-08-26
op
buffer = &ministate.compl.buffer;
0991
2021-07-24
op
if (buffer->current_line == NULL)
0994
2021-07-24
op
buffer->current_line->parent->type = LINE_COMPL;
0995
2021-07-24
op
cmd_scroll_down(buffer);
0996
2021-07-24
op
buffer->current_line->parent->type = LINE_COMPL_CURRENT;
1000
2021-11-05
op
cmd_toggle_downloads(struct buffer *buffer)
1002
2021-11-05
op
ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1006
2022-01-11
op
cmd_cache_info(struct buffer *buffer)
1008
2022-01-11
op
size_t npages, tot;
1009
2022-01-11
op
char fmt[FMT_SCALED_STRSIZE];
1011
2022-01-11
op
mcache_info(&npages, &tot);
1013
2022-01-11
op
if (fmt_scaled(tot, fmt) == 0)
1014
2022-01-13
op
message("pages: %zu, total: %s", npages, fmt);
1016
2022-01-13
op
message("pages: %zu, total: %zu", npages, tot);
1020
2022-02-07
op
cmd_reply_last_input(struct buffer *buffer)
1022
2022-02-07
op
GUARD_RECURSIVE_MINIBUFFER();
1024
2022-02-07
op
if (current_tab->last_input_url == NULL) {
1025
2022-02-07
op
message("there was no previous input request in this tab");
1029
2022-04-24
op
if (!strncmp(current_tab->last_input_url, "gopher", 6)) {
1030
2022-02-08
op
load_url_in_tab(current_tab, current_tab->last_input_url,
1031
2022-02-08
op
NULL, LU_MODE_NOCACHE);
1035
2022-02-07
op
message("%s", current_tab->last_input_url);
1036
2022-02-07
op
ui_require_input(current_tab, 0, ir_select_reply);
1040
2022-04-13
op
cmd_write_buffer(struct buffer *buffer)
1042
2022-04-13
op
const char *f, *url;
1043
2022-04-13
op
char path[PATH_MAX];
1045
2022-04-13
op
GUARD_RECURSIVE_MINIBUFFER();
1047
2022-04-13
op
if (safe_mode) {
1048
2022-04-13
op
message("Can't write buffer in safe-mode.");
1052
2022-04-13
op
url = current_tab->hist_cur->h;
1054
2022-04-13
op
if ((f = strrchr(url, '/')) != NULL)
1056
2022-04-13
op
if (f == NULL || *f == '\0') {
1057
2022-04-13
op
/* guess a decent file name based on the protocol used */
1058
2022-04-13
op
if (!strncmp(url, "gemini://", 9))
1059
2022-04-13
op
f = "index.gmi";
1061
2022-04-13
op
f = "index.txt";
1064
2022-04-13
op
strlcpy(path, download_path, sizeof(path));
1065
2022-04-13
op
strlcat(path, f, sizeof(path));
1067
2022-04-13
op
ui_read("Write file", write_buffer, current_tab, path);