diff --git a/docs/docs.md b/docs/docs.md index 16c9198..45c47a5 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -563,6 +563,23 @@ dmenu compatibility can be achieved using these arguments: There are more options, that can be set in the configuration file but not using arguments passed to spmenu. +## Matching + +`printf "Apple\nPear\nBanana\n" | spmenu` + +With the default configuration, typing in `Apple`, `apple`, `aPpLe` and `pple` +will match `Apple` in this example. Matching is case insensitive, and fuzzy +matching is enabled by default. You can disable fuzzy matching and enable +case sensitivity using arguments, or by enabling it in the configuration. + +`printf "1 Apple\nOne Apple\n" | spmenu` + +spmenu also supports regex matching, but it is not enabled by default. Therefore, +typing in `[0-9]` will return no matches. In the default configuration, you can +press Ctrl+r to enable regex matching. Now typing in `[0-9]` will return the +`1 Apple` entry, but not the `One Apple` entry. Of course, more advanced +regex can be used as well. + ## Keybinds You can set keybinds through the config file. A default config file is available @@ -791,6 +808,7 @@ These are the default keybinds. You can generate these yourself from a | 0 | Ctrl | p | navhistory | -1 | | 0 | Ctrl | n | navhistory | +1 | | 1 | 0 | Escape | switchmode | 0 | +| 1 | Ctrl | r | toggleregex | 0 | ## .Xresources diff --git a/docs/example.Xresources b/docs/example.Xresources index 2920469..48af00f 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -137,7 +137,7 @@ spmenu.caretpadding: 0 spmenu.type: 1 spmenu.passwd: 0 spmenu.fuzzy: 1 -spmenu.regex: 1 +spmenu.regex: 0 spmenu.sortmatches: 1 spmenu.mark: 1 spmenu.casesensitive: 0 diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 3c23b84..9c12480 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -42,6 +42,7 @@ spmenu = { input = ""; // Input text (text) normal = "Normal"; // Normal mode text (text) insert = "Insert"; // Insert mode text (text) + regex = "Regex"; // Insert mode text when regex is enabled (text) capslockon = "Caps Lock"; // Caps Lock On text (text) capslockoff = ""; // Caps Lock Off text (text) } ); @@ -170,8 +171,8 @@ spmenu = { /* Match options */ match = ( { sort = 1; // Sort items (0/1) casesensitive = 0; // Enable case sensitivity when matching (0/1) - fuzzy = 1; // Enable fuzzy finding (0/1) - regex = 1; // Enable regex matching (0/1) + fuzzy = 1; // Enable fuzzy finding by default (0/1) + regex = 0; // Enable regex matching by default (0/1) preselected = 0; // Preselect an item, 0 is the first item (number) mark = 1; // Allow marking/selecting multiple items (0/1) delimiters = " /?\"&[]"; // Word delimiter, used to delete words (text) @@ -301,6 +302,7 @@ spmenu = { { mode = -1; modifier = "Ctrl+Shift"; key = "p"; function = "setprofile"; argument = "0"; }, // Ctrl+Shift+p: Open profile menu { mode = -1; modifier = "None"; key = "PrintScr"; function = "screenshot"; argument = "0"; }, // Print Screen: Screenshot spmenu { mode = 1; modifier = "None"; key = "Esc"; function = "switchmode"; argument = "0"; }, // Escape: Switch mode + { mode = 1; modifier = "Ctrl"; key = "r"; function = "toggleregex"; argument = "0"; }, // Ctrl+r: Toggle regex matching { mode = 0; modifier = "None"; key = "i"; function = "switchmode"; argument = "0"; }, // i: Switch mode { mode = 0; modifier = "Ctrl"; key = "="; function = "setimgsize"; argument = "+1"; }, // Ctrl+=: Increase image size by 1 { mode = 0; modifier = "Ctrl"; key = "-"; function = "setimgsize"; argument = "-1"; }, // Ctrl+-: Decrease image size by 1 diff --git a/libs/arg.c b/libs/arg.c index 732a905..082c03a 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -510,6 +510,13 @@ void setprofile(Arg *arg) { } } +void toggleregex(Arg *arg) { + regex = !regex; + + match(); + drawmenu(); +} + void switchmode(Arg *arg) { if (sp.forceinsertmode) { return; diff --git a/libs/arg.h b/libs/arg.h index f2260af..58acada 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -33,6 +33,7 @@ static void quit(Arg *arg); static void complete(Arg *arg); static void setimgsize(Arg *arg); static void toggleimg(Arg *arg); +static void toggleregex(Arg *arg); static void defaultimg(Arg *arg); static void flipimg(Arg *arg); static void setimgpos(Arg *arg); diff --git a/libs/conf/config.c b/libs/conf/config.c index 99afe8f..e19243e 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -376,6 +376,9 @@ void conf_init(void) { if (config_setting_lookup_string(conf, "insert", &dest)) instext = strdup(dest); + if (config_setting_lookup_string(conf, "regex", &dest)) + regextext = strdup(dest); + if (config_setting_lookup_string(conf, "input", &dest)) input = strdup(dest); } diff --git a/libs/conf/config.h b/libs/conf/config.h index 86f9db8..f001955 100644 --- a/libs/conf/config.h +++ b/libs/conf/config.h @@ -380,6 +380,7 @@ static FuncList fl[] = { { "screenshot", screenshot }, { "setcolumns", setcolumns }, { "togglehighlight",togglehighlight }, + { "toggleregex", toggleregex }, { "setprofile", setprofile }, { "switchmode", switchmode }, { "spawn", spawn }, diff --git a/libs/draw.c b/libs/draw.c index 79309b8..ed74ddf 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -567,6 +567,13 @@ void drawmenu_layer(void) { int x = 0, y = 0, w = 0; sp.plw = hidepowerline ? 0 : draw->font->h / 2 + 1; // powerline size + sp_strncpy(tx.modetext, sp.mode ? instext : normtext, sizeof(tx.modetext)); + +#if USEREGEX + if (regex && regextext && sp.mode) { + sp_strncpy(tx.modetext, regextext, sizeof(tx.modetext)); + } +#endif // draw menu first using menu scheme draw_rect(draw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu); diff --git a/libs/keybinds.h b/libs/keybinds.h index 744fb97..ed4687a 100644 --- a/libs/keybinds.h +++ b/libs/keybinds.h @@ -60,6 +60,7 @@ static Key keys[] = { /* insert mode */ { 1, 0, XK_Escape, switchmode, {0} }, + { 1, Ctrl, XK_r, toggleregex, {0} }, }; #endif @@ -123,5 +124,6 @@ static WlKey wl_keys[] = { /* insert mode */ { 1, WL_None, XKB_KEY_Escape, switchmode, {0} }, + { 1, WL_Ctrl, XKB_KEY_r, toggleregex, {0} }, }; #endif diff --git a/libs/options.h b/libs/options.h index eecd3aa..38c7cea 100644 --- a/libs/options.h +++ b/libs/options.h @@ -66,6 +66,7 @@ static char *screenshotdir = NULL; /* Screenshot file directory. If static int mode = 0; /* Mode to start speedwm in (0: Normal mode, 1: Insert mode) */ static char *normtext = "Normal"; /* Text to display for normal mode */ static char *instext = "Insert"; /* Text to display for insert mode */ +static char *regextext = "Regex"; /* Text to display for insert mode when regex is enabled */ static char *capslockontext = "Caps Lock"; /* Text to display for the caps lock indicator when caps lock is on */ static char *capslockofftext = ""; /* Text to display for the caps lock indicator when caps lock is off */ @@ -94,7 +95,7 @@ static int casesensitive = 0; /* Case-sensitive by default? (0/1) static int mark = 1; /* Enable marking items (multi selection) (0/1) */ static int preselected = 0; /* Which line should spmenu preselect? */ static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */ -static int regex = 1; /* Whether or not to enable regex matching by default */ +static int regex = 0; /* Whether or not to enable regex matching by default */ static char *listfile = NULL; /* File to read entries from instead of stdin. NULL means read from stdin instead. */ /* Line options */ diff --git a/libs/theme/theme.c b/libs/theme/theme.c index 2cb64ae..2e922cc 100644 --- a/libs/theme/theme.c +++ b/libs/theme/theme.c @@ -150,6 +150,9 @@ void theme_load(void) { if (config_setting_lookup_string(conf, "capslockoff", &dest)) capslockofftext = strdup(dest); + if (config_setting_lookup_string(conf, "regex", &dest)) + regextext = strdup(dest); + if (config_setting_lookup_string(conf, "input", &dest)) input = strdup(dest); } diff --git a/spmenu.1 b/spmenu.1 index b84663e..b9ed9b9 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -593,6 +593,26 @@ Set the selected foreground color .PP There are more options, that can be set in the configuration file but not using arguments passed to spmenu. +.SS Matching +.PP +\f[V]printf \[dq]Apple\[rs]nPear\[rs]nBanana\[rs]n\[dq] | spmenu\f[R] +.PP +With the default configuration, typing in \f[V]Apple\f[R], +\f[V]apple\f[R], \f[V]aPpLe\f[R] and \f[V]pple\f[R] will match +\f[V]Apple\f[R] in this example. +Matching is case insensitive, and fuzzy matching is enabled by default. +You can disable fuzzy matching and enable case sensitivity using +arguments, or by enabling it in the configuration. +.PP +\f[V]printf \[dq]1 Apple\[rs]nOne Apple\[rs]n\[dq] | spmenu\f[R] +.PP +spmenu also supports regex matching, but it is not enabled by default. +Therefore, typing in \f[V][0-9]\f[R] will return no matches. +In the default configuration, you can press Ctrl+r to enable regex +matching. +Now typing in \f[V][0-9]\f[R] will return the \f[V]1 Apple\f[R] entry, +but not the \f[V]One Apple\f[R] entry. +Of course, more advanced regex can be used as well. .SS Keybinds .PP You can set keybinds through the config file. @@ -1326,6 +1346,17 @@ switchmode T}@T{ 0 T} +T{ +1 +T}@T{ +Ctrl +T}@T{ +r +T}@T{ +toggleregex +T}@T{ +0 +T} .TE .SS .Xresources .PP