commit - e9beee55fac609bf1acc351cda8deeedceabc52a
commit + 65601367fceed001d065f7e8bbd8c87439d8fd60
blob - d8df75d4f04bc1cd10bbcbd2ec0cfbcad6d8044e
blob + c0a8b754824c75529b5d2a17067a287754dde499
--- ChangeLog
+++ ChangeLog
2021-07-14 Omar Polo <op@omarpolo.com>
+ * defaults.c (load_default_keys): bind M-t to tab-select
+
+ * cmd.c (cmd_tab_select): add tab-select
+
* defaults.c (load_default_keys): bind f5 to reload-page
(load_default_keys): bind r to reload-page
blob - dda99c778de636e6699decfab50640386bda21a7
blob + cc749be2e22468a529dd2b9805bb7c52cd9d068f
--- cmd.c
+++ cmd.c
}
void
+cmd_tab_select(struct buffer *buffer)
+{
+ if (in_minibuffer) {
+ message("We don't have enable-recursive-minibuffers");
+ return;
+ }
+
+ enter_minibuffer(minibuffer_self_insert, ts_select, exit_minibuffer,
+ NULL, compl_ts, NULL);
+ strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
+}
+
+void
cmd_load_url(struct buffer *buffer)
{
if (in_minibuffer) {
blob - 5014678193e118a6328f1ee8d1cfb78ef056bdc8
blob + d917ae29efa1d6cb4ec883bc7610be7a008be618
--- cmd.h
+++ cmd.h
CMD(cmd_tab_move);
CMD(cmd_tab_move_to);
+CMD(cmd_tab_select);
CMD(cmd_load_url);
CMD(cmd_load_current_url);
CMD(cmd_reload_page);
blob - 315c8b7babf7d2d7c78216c1e29018ee72ff9a85
blob + fc7484ba7bcc79961838ef5568f1d9e9a6226e43
--- compl.c
+++ compl.c
#include "telescope.h"
const char *
-compl_eecmd(void **data)
+compl_eecmd(void **data, void **ret)
{
struct cmd **state = (struct cmd **)data;
return (*state)++->cmd;
}
+
+const char *
+compl_ts(void **data, void **ret)
+{
+ struct tab **tab = (struct tab **)data;
+
+ /* first time: init the state */
+ if (*tab == NULL)
+ *tab = TAILQ_FIRST(&tabshead);
+ else if ((*tab = TAILQ_NEXT(*tab, tabs)) == NULL)
+ return NULL;
+
+ *ret = *tab;
+
+ if (*(*tab)->buffer.page.title == '\0')
+ return (*tab)->hist_cur->h;
+ return (*tab)->buffer.page.title;
+}
blob - 8bf04bcb4c4660854bfa2ed924c52f23eb9c1c0c
blob + 6c7ce78052bff445bb26ee0c5faaa014df6e8fed
--- compl.h
+++ compl.h
#ifndef COMPL_H
#define COMPL_H
-const char *compl_eecmd(void **);
+const char *compl_eecmd(void **, void **);
+const char *compl_ts(void **, void **);
#endif
blob - 145e8b461d949d4bdac18575810c4c80b0c9a7b2
blob + 51ce6b015727274fc997c0e2c2a30f2a00e71aaf
--- defaults.c
+++ defaults.c
global_set_key("M-tab", cmd_previous_button);
global_set_key("backtab", cmd_previous_button);
global_set_key("tab", cmd_next_button);
+ global_set_key("M-t", cmd_tab_select);
/* === minibuffer map === */
minibuffer_set_key("ret", cmd_mini_complete_and_exit);
blob - b48c7b920e5bc6656de8541757ee2a10396b029a
blob + 1efdef09ad6b3cb21f312d9b57a089af0e6e89e5
--- minibuffer.c
+++ minibuffer.c
#include "utf8.h"
static void minibuffer_hist_save_entry(void);
-static void minibuffer_self_insert(void);
static void yornp_self_insert(void);
static void yornp_abort(void);
static void read_self_insert(void);
ministate.buffer.current_line->line = ministate.buf;
}
-static void
+void
minibuffer_self_insert(void)
{
char *c, tmp[5] = {0};
message("Abort.");
}
+void
+ts_select(void)
+{
+ struct vline *vl;
+ struct tab *tab;
+
+ vl = ministate.compl.buffer.current_line;
+
+ if (vl == NULL || vl->parent->flags & L_HIDDEN) {
+ message("No tab selected");
+ return;
+ }
+
+ tab = vl->parent->meta.data;
+ exit_minibuffer();
+ switch_to_tab(tab);
+}
+
static void
yornp_self_insert(void)
{
struct line *l;
struct buffer *b;
struct parser *p;
+ void *linedata = NULL;
b = &ministate.compl.buffer;
p = &b->page;
- while ((s = fn(&data)) != NULL) {
+ while ((s = fn(&data, &linedata)) != NULL) {
if ((l = calloc(1, sizeof(*l))) == NULL)
abort();
l->type = LINE_COMPL;
+ l->meta.data = linedata;
if ((l->line = strdup(s)) == NULL)
abort();
TAILQ_INSERT_HEAD(&p->head, l, lines);
else
TAILQ_INSERT_TAIL(&p->head, l, lines);
+
+ linedata = NULL;
}
if ((l = TAILQ_FIRST(&p->head)) != NULL)
blob - 73e4f9f746397c6856c0ce65b15083e15bd7380c
blob + 52c1fa531c17aeab0cddfde3e01df89e770fd0d3
--- minibuffer.h
+++ minibuffer.h
* using the given parameter `state' and modify it eventually. To
* signal the end of the completions, complfn should return NULL: the
* value of state will then be discarded and the function never called
- * again.
+ * again. The second parameter is some extra metadata per-line; it'll
+ * be available as line->meta.data on the selected line during the
+ * minibuffer lifecycle.
*/
-typedef const char *(complfn)(void **);
+typedef const char *(complfn)(void **, void **);
struct ministate {
char *curmesg;
blob - e93980071fcbb4244679e7aaf91b2010dd57f27d
blob + 05adbf2643cd4f5857e78503b6962f6a4f9f3572
--- ui.h
+++ ui.h
void restore_excursion(struct excursion *, struct buffer *);
void global_key_unbound(void);
void minibuffer_taint_hist(void);
+void minibuffer_self_insert(void);
void eecmd_self_insert(void);
void eecmd_select(void);
void ir_self_insert(void);
void lu_self_insert(void);
void lu_select(void);
void bp_select(void);
+void ts_select(void);
struct vline *adjust_line(struct vline *, struct buffer *);
void vmessage(const char *, va_list);
void message(const char *, ...) __attribute__((format(printf, 1, 2)));