summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-07-01 09:12:22 +0200
committerDave Davenport <qball@gmpclient.org>2015-07-01 09:12:22 +0200
commit98b8e583cbd670afe8d69066209ce2c432e41053 (patch)
treed5e19a329e30195fd23989be3b67d1088f8d1712
parentc7ed92e40c2ef8e73cb6ca4eb139fe27020fd2c4 (diff)
Make fuzzy matching available everywhere: #133 (-fuzzy)
-rw-r--r--doc/rofi-manpage.markdown7
-rw-r--r--doc/rofi.128
-rw-r--r--include/helper.h4
-rw-r--r--include/rofi.h2
-rw-r--r--source/dialogs/dmenu.c21
-rw-r--r--source/helper.c39
-rw-r--r--source/xrmoptions.c3
7 files changed, 52 insertions, 52 deletions
diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown
index 5c6eda75..58623b2b 100644
--- a/doc/rofi-manpage.markdown
+++ b/doc/rofi-manpage.markdown
@@ -193,6 +193,10 @@ Below is a list of the most important options:
Do not print any message when starting in daemon mode.
+`-fuzzy`
+
+ Enable experimental fuzzy matching.
+
### Theming
@@ -547,9 +551,6 @@ Add a message line below the filter entry box. Supports pango markup.
For more information on supported markup see [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html)
-`-z`
-
- Enable sloppy fuzzy matching.
### Message dialog
diff --git a/doc/rofi.1 b/doc/rofi.1
index 19a4a142..3e52ac09 100644
--- a/doc/rofi.1
+++ b/doc/rofi.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "ROFI\-MANPAGE" "" "June 2015" "" ""
+.TH "ROFI\-MANPAGE" "" "July 2015" "" ""
.
.SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
@@ -293,6 +293,19 @@ Start in case sensitive mode\.
.P
Do not print any message when starting in daemon mode\.
.
+.P
+\fB\-fuzzy\fR
+.
+.IP "" 4
+.
+.nf
+
+Enable experimental fuzzy matching\.
+.
+.fi
+.
+.IP "" 0
+.
.SS "Theming"
\fB\-bg\fR
.
@@ -997,19 +1010,6 @@ Select first line that matches the given string
.P
Add a message line below the filter entry box\. Supports pango markup\. For more information on supported markup see here \fIhttps://developer\.gnome\.org/pango/stable/PangoMarkupFormat\.html\fR
.
-.P
-\fB\-z\fR
-.
-.IP "" 4
-.
-.nf
-
-Enable sloppy fuzzy matching\.
-.
-.fi
-.
-.IP "" 0
-.
.SS "Message dialog"
\fB\-e\fR \fImessage\fR
.
diff --git a/include/helper.h b/include/helper.h
index cff62427..99b1bf7d 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -108,10 +108,6 @@ int token_match ( char **tokens, const char *input, int case_sensitive,
__attribute__( ( unused ) ) unsigned int index,
__attribute__( ( unused ) ) Switcher * data );
-int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
- __attribute__( ( unused ) ) unsigned int index,
- __attribute__( ( unused ) ) Switcher * data );
-
/**
* @param cmd The command to execute.
*
diff --git a/include/rofi.h b/include/rofi.h
index f9b8a6e4..e627d199 100644
--- a/include/rofi.h
+++ b/include/rofi.h
@@ -226,6 +226,8 @@ typedef struct _Settings
unsigned int parse_hosts;
/** Combi Switchers */
char *combi_modi;
+ /** Fuzzy match */
+ unsigned int fuzzy;
} Settings;
/** Global Settings structure. */
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index 1979c069..cbd9769e 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -180,14 +180,13 @@ static void dmenu_output_formatted_line ( const char *format, const char *string
int dmenu_switcher_dialog ( char **input )
{
- char *dmenu_prompt = "dmenu ";
- int selected_line = -1;
- int retv = FALSE;
- int length = 0;
- char **list = get_dmenu ( &length );
- int restart = FALSE;
- char *message = NULL;
- menu_match_cb filter = token_match;
+ char *dmenu_prompt = "dmenu ";
+ int selected_line = -1;
+ int retv = FALSE;
+ int length = 0;
+ char **list = get_dmenu ( &length );
+ int restart = FALSE;
+ char *message = NULL;
find_arg_str ( "-mesg", &message );
@@ -225,10 +224,6 @@ int dmenu_switcher_dialog ( char **input )
}
find_arg_str_alloc ( "-filter", input );
- if ( find_arg ( "-z" ) >= 0 ) {
- filter = fuzzy_token_match;
- }
-
char *select = NULL;
find_arg_str ( "-select", &select );
if ( select != NULL ) {
@@ -246,7 +241,7 @@ int dmenu_switcher_dialog ( char **input )
do {
int next_pos = selected_line;
int mretv = menu ( list, length, input, dmenu_prompt,
- filter, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message );
+ token_match, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message );
// Special behavior.
if ( only_selected ) {
/**
diff --git a/source/helper.c b/source/helper.c
index 9a5125c8..bda83714 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -329,45 +329,50 @@ int find_arg_char ( const char * const key, char *val )
* Shared 'token_match' function.
* Matches tokenized.
*/
-int token_match ( char **tokens, const char *input, int case_sensitive,
- __attribute__( ( unused ) ) unsigned int index,
- __attribute__( ( unused ) ) Switcher *data )
+static int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive )
{
int match = 1;
char *compk = token_collate_key ( input, case_sensitive );
-
// Do a tokenized match.
if ( tokens ) {
for ( int j = 0; match && tokens[j]; j++ ) {
- match = ( strstr ( compk, tokens[j] ) != NULL );
+ char *t = compk;
+ int token_len = strlen ( tokens[j] );
+ for ( int id = 0; match && t != NULL && id < token_len; id++ ) {
+ match = ( ( t = strchr ( t, tokens[j][id] ) ) != NULL );
+ // next should match the next character.
+ if ( t != NULL ) {
+ t++;
+ }
+ }
}
}
g_free ( compk );
return match;
}
-int fuzzy_token_match ( char **tokens, const char *input, int case_sensitive,
- __attribute__( ( unused ) ) unsigned int index,
- __attribute__( ( unused ) ) Switcher * data )
+static int normal_token_match ( char **tokens, const char *input, int case_sensitive )
{
int match = 1;
char *compk = token_collate_key ( input, case_sensitive );
+
// Do a tokenized match.
if ( tokens ) {
for ( int j = 0; match && tokens[j]; j++ ) {
- char *t = compk;
- int token_len = strlen ( tokens[j] );
- for ( int id = 0; match && t != NULL && id < token_len; id++ ) {
- match = ( ( t = strchr ( t, tokens[j][id] ) ) != NULL );
- // next should match the next character.
- if ( t != NULL ) {
- t++;
- }
- }
+ match = ( strstr ( compk, tokens[j] ) != NULL );
}
}
g_free ( compk );
return match;
}
+int token_match ( char **tokens, const char *input, int case_sensitive,
+ __attribute__( ( unused ) ) unsigned int index,
+ __attribute__( ( unused ) ) Switcher *data )
+{
+ if ( config.fuzzy ) {
+ return fuzzy_token_match ( tokens, input, case_sensitive );
+ }
+ return normal_token_match ( tokens, input, case_sensitive );
+}
int execute_generator ( const char * cmd )
{
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 376a6cf9..2cbb3573 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -122,7 +122,8 @@ static XrmOption xrmOptions[] = {
{ xrm_SNumber, "eh", { .snum = &config.element_height }, NULL },
{ xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL },
{ xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL },
- { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL }
+ { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
+ { xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL }
};
// Dynamic options.