From: Daniel Carl Date: Sun, 23 Dec 2012 22:56:44 +0000 (+0100) Subject: Allow to set the maximum number of completion items to runtime. X-Git-Url: https://git.owens.tech/assets/me.png/assets/me.png/git?a=commitdiff_plain;h=19609ad24a55cc5a23070bf7c4c5409540825272;p=vimb.git Allow to set the maximum number of completion items to runtime. --- diff --git a/src/completion.c b/src/completion.c index 304ae8a..26f4984 100644 --- a/src/completion.c +++ b/src/completion.c @@ -144,11 +144,11 @@ static GList* completion_update(GList* completion, GList* active, gboolean back) GList *old, *new; Completion *c; - int length = g_list_length(completion); - int max = 15; - int items = MAX(length, max); - int r = (max) % 2; - int offset = max / 2 - 1 + r; + gint length = g_list_length(completion); + gint max = vp.config.max_completion_items; + gint items = MAX(length, max); + gint r = (max) % 2; + gint offset = max / 2 - 1 + r; old = active; int position = g_list_position(completion, active) + 1; @@ -216,17 +216,16 @@ static GList* completion_update(GList* completion, GList* active, gboolean back) /* allow to chenge the direction of display */ static void completion_show(gboolean back) { - /* TODO make this configurable */ - const gint max_items = 15; + guint max = vp.config.max_completion_items; gint i = 0; if (back) { vp.comps.active = g_list_last(vp.comps.completions); - for (GList *l = vp.comps.active; l && i < max_items; l = l->prev, i++) { + for (GList *l = vp.comps.active; l && i < max; l = l->prev, i++) { gtk_widget_show_all(((Completion*)l->data)->event); } } else { vp.comps.active = g_list_first(vp.comps.completions); - for (GList *l = vp.comps.active; l && i < max_items; l = l->next, i++) { + for (GList *l = vp.comps.active; l && i < max; l = l->next, i++) { gtk_widget_show_all(((Completion*)l->data)->event); } } @@ -269,7 +268,6 @@ static void completion_set_entry_text(Completion* completion) static Completion* completion_get_new(const gchar* label, const gchar* prefix) { - /* TODO make this configurable */ const gint padding = 2; Completion* c = g_new0(Completion, 1); diff --git a/src/main.h b/src/main.h index 7120caf..2d5236e 100644 --- a/src/main.h +++ b/src/main.h @@ -202,6 +202,7 @@ typedef struct { time_t cookie_timeout; #endif gint scrollstep; + guint max_completion_items; } Config; typedef struct { @@ -214,6 +215,7 @@ typedef struct { VpColor input_fg[VP_MSG_LAST]; VpColor input_bg[VP_MSG_LAST]; PangoFontDescription* input_font[VP_MSG_LAST]; + /* completion */ VpColor comp_fg[VP_COMP_LAST]; VpColor comp_bg[VP_COMP_LAST]; PangoFontDescription* comp_font[VP_COMP_LAST]; @@ -246,11 +248,6 @@ typedef struct { Style style; GHashTable* settings; Hints hints; -#if 0 - Ssl ssl; - Communication comm; - Info info; -#endif } VpCore; /* main object */ diff --git a/src/setting.c b/src/setting.c index 7ef26e7..40b8ca5 100644 --- a/src/setting.c +++ b/src/setting.c @@ -97,6 +97,7 @@ static Setting default_settings[] = { {NULL, "completion-fg-active", TYPE_CHAR, setting_completion_style, {.s = "#fff"}}, {NULL, "completion-bg-normal", TYPE_CHAR, setting_completion_style, {.s = "#656565"}}, {NULL, "completion-bg-active", TYPE_CHAR, setting_completion_style, {.s = "#777777"}}, + {NULL, "max-completion-items", TYPE_INTEGER, setting_completion_style, {.i = 15}}, {NULL, "hint-bg", TYPE_CHAR, setting_hint_style, {.s = "#ff0"}}, {NULL, "hint-bg-focus", TYPE_CHAR, setting_hint_style, {.s = "#8f0"}}, {NULL, "hint-fg", TYPE_CHAR, setting_hint_style, {.s = "#000"}}, @@ -273,6 +274,8 @@ static gboolean setting_completion_style(const Setting* s) pango_font_description_free(style->comp_font[type]); } style->comp_font[type] = pango_font_description_from_string(s->arg.s); + } else if (!g_strcmp0(s->name, "max-completion-items")) { + vp.config.max_completion_items = s->arg.i; } return TRUE;