commit - a671711020e5e6ebd5585a118a03801c79136a4d
commit + 753c6ac75647edbcc6acc7c98cab4bce07b1636d
blob - c0a8b754824c75529b5d2a17067a287754dde499
blob + 507a8c83952f012c75e524d3f698f5eb640130a5
--- ChangeLog
+++ ChangeLog
2021-07-14 Omar Polo <op@omarpolo.com>
+ * defaults.c (load_default_keys): bind M-L to link-select
+ (load_default_keys): bind M-/ to swiper
+
+ * cmd.c (cmd_link_select): add link-select
+ (cmd_swiper): add swiper
+
* defaults.c (load_default_keys): bind M-t to tab-select
* cmd.c (cmd_tab_select): add tab-select
blob - cc749be2e22468a529dd2b9805bb7c52cd9d068f
blob + 74b0f596b190da9014ca05d7eb6fe63bdd0aa8cb
--- cmd.c
+++ cmd.c
cmd_toggle_help(struct buffer *buffer)
{
ui_toggle_side_window();
+}
+
+void
+cmd_link_select(struct buffer *buffer)
+{
+ if (in_minibuffer) {
+ message("We don't have enable-recursive-minibuffers");
+ return;
+ }
+
+ enter_minibuffer(minibuffer_self_insert, ls_select, exit_minibuffer,
+ NULL, compl_ls, TAILQ_FIRST(&buffer->page.head));
+ strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
+}
+
+void
+cmd_swiper(struct buffer *buffer)
+{
+ if (in_minibuffer) {
+ message("We don't have enable-recursive-minibuffers");
+ return;
+ }
+
+ enter_minibuffer(minibuffer_self_insert, swiper_select, exit_minibuffer,
+ NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head));
+ strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
}
void
blob - d917ae29efa1d6cb4ec883bc7610be7a008be618
blob + 227bf3ff7479cefd2f2b35611bb7c2b86ef2d988
--- cmd.h
+++ cmd.h
CMD(cmd_list_bookmarks);
CMD(cmd_toggle_help);
+CMD(cmd_link_select);
+CMD(cmd_swiper);
+
CMD(cmd_inc_fill_column);
CMD(cmd_dec_fill_column);
CMD(cmd_olivetti_mode);
blob - f82f8aba82053b4344b19225585199aa6957a462
blob + ec2e3f4ea4ca9f6e63cc12bfba957ef7f74008fd
--- compl.c
+++ compl.c
return (*tab)->hist_cur->h;
return (*tab)->buffer.page.title;
}
+
+/*
+ * Provide completions for link-select.
+ */
+const char *
+compl_ls(void **data, void **ret)
+{
+ struct line **line = (struct line **)data;
+ struct line *l;
+ const char *link;
+
+ l = *line;
+ while (l != NULL && l->type != LINE_LINK)
+ l = TAILQ_NEXT(l, lines);
+
+ /* end of buffer */
+ if (l == NULL)
+ return NULL;
+
+ link = l->line;
+ *ret = l;
+ *line = TAILQ_NEXT(l, lines);
+ return link;
+}
+
+/*
+ * Provide completinos for swiper.
+ */
+const char *
+compl_swiper(void **data, void **ret)
+{
+ struct line **line = (struct line **)data;
+ const char *text;
+
+ while (*line != NULL && (*line)->line == NULL)
+ *line = TAILQ_NEXT(*line, lines);
+
+ if (*line == NULL)
+ return NULL;
+
+ text = (*line)->line;
+ *ret = *line;
+ *line = TAILQ_NEXT(*line, lines);
+ return text;
+}
blob - 6c7ce78052bff445bb26ee0c5faaa014df6e8fed
blob + f1f98044e05a618124876db167f4fcaa1d4b9be3
--- compl.h
+++ compl.h
const char *compl_eecmd(void **, void **);
const char *compl_ts(void **, void **);
+const char *compl_ls(void **, void **);
+const char *compl_swiper(void **, void **);
#endif
blob - 51ce6b015727274fc997c0e2c2a30f2a00e71aaf
blob + d7e1a2c2a8db1d3e128d976ab9711158973cad84
--- defaults.c
+++ defaults.c
global_set_key("backtab", cmd_previous_button);
global_set_key("tab", cmd_next_button);
global_set_key("M-t", cmd_tab_select);
+ global_set_key("M-L", cmd_link_select);
+ global_set_key("M-/", cmd_swiper);
/* === minibuffer map === */
minibuffer_set_key("ret", cmd_mini_complete_and_exit);
blob - 1efdef09ad6b3cb21f312d9b57a089af0e6e89e5
blob + 9a37ea02a70008c37bfeb713e675fa1aec01945d
--- minibuffer.c
+++ minibuffer.c
tab = vl->parent->meta.data;
exit_minibuffer();
switch_to_tab(tab);
+}
+
+void
+ls_select(void)
+{
+ struct line *l;
+ struct vline *vl;
+
+ vl = ministate.compl.buffer.current_line;
+
+ if (vl == NULL || vl->parent->flags & L_HIDDEN) {
+ message("No link selected");
+ return;
+ }
+
+ l = vl->parent->meta.data;
+ exit_minibuffer();
+
+ load_url_in_tab(current_tab(), l->meta.alt);
+}
+
+void
+swiper_select(void)
+{
+ struct line *l;
+ struct vline *vl;
+ struct tab *tab;
+
+ vl = ministate.compl.buffer.current_line;
+
+ if (vl == NULL || vl->parent->flags & L_HIDDEN) {
+ message("No line selected");
+ return;
+ }
+
+ l = vl->parent->meta.data;
+ exit_minibuffer();
+
+ tab = current_tab();
+
+ TAILQ_FOREACH(vl, &tab->buffer.head, vlines) {
+ if (vl->parent == l)
+ break;
+ }
+
+ if (vl == NULL)
+ message("Ops, swiper error! Please report to %s",
+ PACKAGE_BUGREPORT);
+ else
+ tab->buffer.current_line = vl;
}
static void
blob - c4a89364a75b28d2f4da474c60c14165ac06b6df
blob + 9981be0e6bae2d5217fb272827c5d7487ab95a38
--- minibuffer.h
+++ minibuffer.h
void lu_select(void);
void bp_select(void);
void ts_select(void);
+void ls_select(void);
+void swiper_select(void);
void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void),
struct histhead *,
blob - b7261c32639b8a946027f1ba110168762a3bb20a
blob + 19491e23511d5c22c06beeff079e586dc81b4682
--- telescope.1
+++ telescope.1
next-button
.It M-t
tab-select
+.It M-L
+link-select
+.It M-/
+swiper
.El
.Ss Minibuffer-specific keys
.Bl -tag -width xxxxxxxxxxxx -offset indent -compact
.Nm .
.It Ic inc-fill-column
Increments fill-column by two.
+.It Ic link-select
+Select and visit a link using the minibuffer.
.It Ic load-current-url
Prompts for an URL, the minibuffer is preloaded with the current
one.
Scroll up by one line.
.It Ic scroll-up
Scroll up by one visual page.
+.It Ic swiper
+Jump to a line using the minibuffer.
.It Ic toggle-help
Toggle side window with help about available keys and their associated
interactive command.