Make regex matching a separate mode inside insert mode
This commit is contained in:
parent
7aecc3edf9
commit
890457729c
18
docs/docs.md
18
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
|
There are more options, that can be set in the configuration file but not using
|
||||||
arguments passed to spmenu.
|
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
|
## Keybinds
|
||||||
|
|
||||||
You can set keybinds through the config file. A default config file is available
|
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 | p | navhistory | -1 |
|
||||||
| 0 | Ctrl | n | navhistory | +1 |
|
| 0 | Ctrl | n | navhistory | +1 |
|
||||||
| 1 | 0 | Escape | switchmode | 0 |
|
| 1 | 0 | Escape | switchmode | 0 |
|
||||||
|
| 1 | Ctrl | r | toggleregex | 0 |
|
||||||
|
|
||||||
## .Xresources
|
## .Xresources
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ spmenu.caretpadding: 0
|
||||||
spmenu.type: 1
|
spmenu.type: 1
|
||||||
spmenu.passwd: 0
|
spmenu.passwd: 0
|
||||||
spmenu.fuzzy: 1
|
spmenu.fuzzy: 1
|
||||||
spmenu.regex: 1
|
spmenu.regex: 0
|
||||||
spmenu.sortmatches: 1
|
spmenu.sortmatches: 1
|
||||||
spmenu.mark: 1
|
spmenu.mark: 1
|
||||||
spmenu.casesensitive: 0
|
spmenu.casesensitive: 0
|
||||||
|
|
|
@ -42,6 +42,7 @@ spmenu = {
|
||||||
input = ""; // Input text (text)
|
input = ""; // Input text (text)
|
||||||
normal = "Normal"; // Normal mode text (text)
|
normal = "Normal"; // Normal mode text (text)
|
||||||
insert = "Insert"; // Insert 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)
|
capslockon = "Caps Lock"; // Caps Lock On text (text)
|
||||||
capslockoff = ""; // Caps Lock Off text (text)
|
capslockoff = ""; // Caps Lock Off text (text)
|
||||||
} );
|
} );
|
||||||
|
@ -170,8 +171,8 @@ spmenu = {
|
||||||
/* Match options */
|
/* Match options */
|
||||||
match = ( { sort = 1; // Sort items (0/1)
|
match = ( { sort = 1; // Sort items (0/1)
|
||||||
casesensitive = 0; // Enable case sensitivity when matching (0/1)
|
casesensitive = 0; // Enable case sensitivity when matching (0/1)
|
||||||
fuzzy = 1; // Enable fuzzy finding (0/1)
|
fuzzy = 1; // Enable fuzzy finding by default (0/1)
|
||||||
regex = 1; // Enable regex matching (0/1)
|
regex = 0; // Enable regex matching by default (0/1)
|
||||||
preselected = 0; // Preselect an item, 0 is the first item (number)
|
preselected = 0; // Preselect an item, 0 is the first item (number)
|
||||||
mark = 1; // Allow marking/selecting multiple items (0/1)
|
mark = 1; // Allow marking/selecting multiple items (0/1)
|
||||||
delimiters = " /?\"&[]"; // Word delimiter, used to delete words (text)
|
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 = "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 = "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 = "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 = "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+=: Increase image size by 1
|
||||||
{ mode = 0; modifier = "Ctrl"; key = "-"; function = "setimgsize"; argument = "-1"; }, // Ctrl+-: Decrease image size by 1
|
{ mode = 0; modifier = "Ctrl"; key = "-"; function = "setimgsize"; argument = "-1"; }, // Ctrl+-: Decrease image size by 1
|
||||||
|
|
|
@ -510,6 +510,13 @@ void setprofile(Arg *arg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleregex(Arg *arg) {
|
||||||
|
regex = !regex;
|
||||||
|
|
||||||
|
match();
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
|
||||||
void switchmode(Arg *arg) {
|
void switchmode(Arg *arg) {
|
||||||
if (sp.forceinsertmode) {
|
if (sp.forceinsertmode) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -33,6 +33,7 @@ static void quit(Arg *arg);
|
||||||
static void complete(Arg *arg);
|
static void complete(Arg *arg);
|
||||||
static void setimgsize(Arg *arg);
|
static void setimgsize(Arg *arg);
|
||||||
static void toggleimg(Arg *arg);
|
static void toggleimg(Arg *arg);
|
||||||
|
static void toggleregex(Arg *arg);
|
||||||
static void defaultimg(Arg *arg);
|
static void defaultimg(Arg *arg);
|
||||||
static void flipimg(Arg *arg);
|
static void flipimg(Arg *arg);
|
||||||
static void setimgpos(Arg *arg);
|
static void setimgpos(Arg *arg);
|
||||||
|
|
|
@ -376,6 +376,9 @@ void conf_init(void) {
|
||||||
if (config_setting_lookup_string(conf, "insert", &dest))
|
if (config_setting_lookup_string(conf, "insert", &dest))
|
||||||
instext = strdup(dest);
|
instext = strdup(dest);
|
||||||
|
|
||||||
|
if (config_setting_lookup_string(conf, "regex", &dest))
|
||||||
|
regextext = strdup(dest);
|
||||||
|
|
||||||
if (config_setting_lookup_string(conf, "input", &dest))
|
if (config_setting_lookup_string(conf, "input", &dest))
|
||||||
input = strdup(dest);
|
input = strdup(dest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,6 +380,7 @@ static FuncList fl[] = {
|
||||||
{ "screenshot", screenshot },
|
{ "screenshot", screenshot },
|
||||||
{ "setcolumns", setcolumns },
|
{ "setcolumns", setcolumns },
|
||||||
{ "togglehighlight",togglehighlight },
|
{ "togglehighlight",togglehighlight },
|
||||||
|
{ "toggleregex", toggleregex },
|
||||||
{ "setprofile", setprofile },
|
{ "setprofile", setprofile },
|
||||||
{ "switchmode", switchmode },
|
{ "switchmode", switchmode },
|
||||||
{ "spawn", spawn },
|
{ "spawn", spawn },
|
||||||
|
|
|
@ -567,6 +567,13 @@ void drawmenu_layer(void) {
|
||||||
int x = 0, y = 0, w = 0;
|
int x = 0, y = 0, w = 0;
|
||||||
sp.plw = hidepowerline ? 0 : draw->font->h / 2 + 1; // powerline size
|
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 menu first using menu scheme
|
||||||
draw_rect(draw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu);
|
draw_rect(draw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu);
|
||||||
|
|
|
@ -60,6 +60,7 @@ static Key keys[] = {
|
||||||
|
|
||||||
/* insert mode */
|
/* insert mode */
|
||||||
{ 1, 0, XK_Escape, switchmode, {0} },
|
{ 1, 0, XK_Escape, switchmode, {0} },
|
||||||
|
{ 1, Ctrl, XK_r, toggleregex, {0} },
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -123,5 +124,6 @@ static WlKey wl_keys[] = {
|
||||||
|
|
||||||
/* insert mode */
|
/* insert mode */
|
||||||
{ 1, WL_None, XKB_KEY_Escape, switchmode, {0} },
|
{ 1, WL_None, XKB_KEY_Escape, switchmode, {0} },
|
||||||
|
{ 1, WL_Ctrl, XKB_KEY_r, toggleregex, {0} },
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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 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 *normtext = "Normal"; /* Text to display for normal mode */
|
||||||
static char *instext = "Insert"; /* Text to display for insert 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 *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 */
|
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 mark = 1; /* Enable marking items (multi selection) (0/1) */
|
||||||
static int preselected = 0; /* Which line should spmenu preselect? */
|
static int preselected = 0; /* Which line should spmenu preselect? */
|
||||||
static int fuzzy = 1; /* Whether or not to enable fuzzy matching by default */
|
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. */
|
static char *listfile = NULL; /* File to read entries from instead of stdin. NULL means read from stdin instead. */
|
||||||
|
|
||||||
/* Line options */
|
/* Line options */
|
||||||
|
|
|
@ -150,6 +150,9 @@ void theme_load(void) {
|
||||||
if (config_setting_lookup_string(conf, "capslockoff", &dest))
|
if (config_setting_lookup_string(conf, "capslockoff", &dest))
|
||||||
capslockofftext = strdup(dest);
|
capslockofftext = strdup(dest);
|
||||||
|
|
||||||
|
if (config_setting_lookup_string(conf, "regex", &dest))
|
||||||
|
regextext = strdup(dest);
|
||||||
|
|
||||||
if (config_setting_lookup_string(conf, "input", &dest))
|
if (config_setting_lookup_string(conf, "input", &dest))
|
||||||
input = strdup(dest);
|
input = strdup(dest);
|
||||||
}
|
}
|
||||||
|
|
31
spmenu.1
31
spmenu.1
|
@ -593,6 +593,26 @@ Set the selected foreground color
|
||||||
.PP
|
.PP
|
||||||
There are more options, that can be set in the configuration file but
|
There are more options, that can be set in the configuration file but
|
||||||
not using arguments passed to spmenu.
|
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
|
.SS Keybinds
|
||||||
.PP
|
.PP
|
||||||
You can set keybinds through the config file.
|
You can set keybinds through the config file.
|
||||||
|
@ -1326,6 +1346,17 @@ switchmode
|
||||||
T}@T{
|
T}@T{
|
||||||
0
|
0
|
||||||
T}
|
T}
|
||||||
|
T{
|
||||||
|
1
|
||||||
|
T}@T{
|
||||||
|
Ctrl
|
||||||
|
T}@T{
|
||||||
|
r
|
||||||
|
T}@T{
|
||||||
|
toggleregex
|
||||||
|
T}@T{
|
||||||
|
0
|
||||||
|
T}
|
||||||
.TE
|
.TE
|
||||||
.SS .Xresources
|
.SS .Xresources
|
||||||
.PP
|
.PP
|
||||||
|
|
Loading…
Reference in a new issue