commit d7ee7b5e9bf19ebdfdef9ec0d887871ee6aedeae from: Omar Polo date: Thu Jul 15 09:06:39 2021 UTC minibuffer: add jump_to_line and minibuffer_metadata commit - c7453a38f43cf40a80834cb129c6b64bd7b2bc2c commit + d7ee7b5e9bf19ebdfdef9ec0d887871ee6aedeae blob - 646346235203e6d091672273a2a1e41746ec7314 blob + bda216af5d2d4091efe0a0de4e7e40fb95b40cab --- minibuffer.c +++ minibuffer.c @@ -21,6 +21,7 @@ #include "ui.h" #include "utf8.h" +static void *minibuffer_metadata(void); static void minibuffer_hist_save_entry(void); static void yornp_self_insert(void); static void yornp_abort(void); @@ -76,6 +77,19 @@ recompute_completions(int add) vl->parent->type = LINE_COMPL_CURRENT; } +static void * +minibuffer_metadata(void) +{ + struct vline *vl; + + vl = ministate.compl.buffer.current_line; + + if (vl == NULL || vl->parent->flags & L_HIDDEN) + return NULL; + + return vl->parent->meta.data; +} + static void minibuffer_hist_save_entry(void) { @@ -222,17 +236,13 @@ bp_select(void) void ts_select(void) { - struct vline *vl; struct tab *tab; - vl = ministate.compl.buffer.current_line; - - if (vl == NULL || vl->parent->flags & L_HIDDEN) { + if ((tab = minibuffer_metadata()) == NULL) { message("No tab selected"); return; } - tab = vl->parent->meta.data; exit_minibuffer(); switch_to_tab(tab); } @@ -241,38 +251,22 @@ void ls_select(void) { struct line *l; - struct vline *vl; - vl = ministate.compl.buffer.current_line; - - if (vl == NULL || vl->parent->flags & L_HIDDEN) { + if ((l = minibuffer_metadata()) == NULL) { 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) +static inline void +jump_to_line(struct line *l) { - 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) { @@ -281,12 +275,26 @@ swiper_select(void) } if (vl == NULL) - message("Ops, swiper error! Please report to %s", - PACKAGE_BUGREPORT); + message("Ops, %s error! Please report to %s", + __func__, PACKAGE_BUGREPORT); else tab->buffer.current_line = vl; } +void +swiper_select(void) +{ + struct line *l; + + if ((l = minibuffer_metadata()) == NULL) { + message("No line selected"); + return; + } + + exit_minibuffer(); + jump_to_line(l); +} + static void yornp_self_insert(void) {