diff options
author | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-06-12 00:53:30 +0200 |
---|---|---|
committer | Manuel Palenzuela <manuelpalenzuelamerino@gmail.com> | 2019-06-12 00:53:30 +0200 |
commit | c6a3dddb74cd4572390d11eb153833e21a3443eb (patch) | |
tree | bee1188f899c76f79aab500ebebd93756ca3689b | |
parent | Added mouse support patch [Patch] (diff) | |
download | dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.tar.gz dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.tar.bz2 dmenu-c6a3dddb74cd4572390d11eb153833e21a3443eb.zip |
Added tab complete [Patch]
-rw-r--r-- | config.h | 5 | ||||
-rw-r--r-- | dmenu.1 | 5 | ||||
-rw-r--r-- | dmenu.c | 29 |
3 files changed, 29 insertions, 10 deletions
diff --git a/config.h b/config.h index 317fa2f..7d45da2 100644 --- a/config.h +++ b/config.h @@ -22,3 +22,8 @@ static unsigned int lineheight = 0; /* -h option; minimum height of a me * for example: " /?\"&[]" */ static const char worddelimiters[] = " "; + +/* + * Use prefix matching by default; can be inverted with the -x flag. + */ +static int use_prefix = 1; diff --git a/dmenu.1 b/dmenu.1 index 7ef34d2..84ccf21 100644 --- a/dmenu.1 +++ b/dmenu.1 @@ -3,7 +3,7 @@ dmenu \- dynamic menu .SH SYNOPSIS .B dmenu -.RB [ \-bfiv ] +.RB [ \-bfivx ] .RB [ \-l .IR lines ] .RB [ \-m @@ -81,6 +81,9 @@ defines the selected foreground color. .B \-v prints version information to stdout, then exits. .TP +.B \-x +Invert prefix matching setting. +.TP .BI \-w " windowid" embed into windowid. .SH USAGE diff --git a/dmenu.c b/dmenu.c index 0e0f94e..e7ce2fd 100644 --- a/dmenu.c +++ b/dmenu.c @@ -228,8 +228,13 @@ match(void) die("cannot realloc %u bytes:", tokn * sizeof *tokv); len = tokc ? strlen(tokv[0]) : 0; - matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; - textsize = strlen(text) + 1; + if (use_prefix) { + matches = lprefix = matchend = prefixend = NULL; + textsize = strlen(text); + } else { + matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; + textsize = strlen(text) + 1; + } for (item = items; item && item->text; item++) { for (i = 0; i < tokc; i++) if (!fstrstr(item->text, tokv[i])) @@ -241,7 +246,7 @@ match(void) appenditem(item, &matches, &matchend); else if (!fstrncmp(tokv[0], item->text, len)) appenditem(item, &lprefix, &prefixend); - else + else if (!use_prefix) appenditem(item, &lsubstr, &substrend); } if (lprefix) { @@ -252,7 +257,7 @@ match(void) matches = lprefix; matchend = prefixend; } - if (lsubstr) { + if (!use_prefix && lsubstr) { if (matches) { matchend->right = lsubstr; lsubstr->left = matchend; @@ -309,6 +314,7 @@ keypress(XKeyEvent *ev) { char buf[32]; int len; + struct item * item; KeySym ksym; Status status; @@ -487,12 +493,17 @@ insert: } break; case XK_Tab: - if (!sel) - return; - strncpy(text, sel->text, sizeof text - 1); + if (!matches) break; /* cannot complete no matches */ + strncpy(text, matches->text, sizeof text - 1); text[sizeof text - 1] = '\0'; - cursor = strlen(text); - match(); + len = cursor = strlen(text); /* length of longest common prefix */ + for (item = matches; item && item->text; item = item->right) { + cursor = 0; + while (cursor < len && text[cursor] == item->text[cursor]) + cursor++; + len = cursor; + } + memset(text + len, '\0', strlen(text) - len); break; } |