The default, legacy style is named BASIC. A new completion style named SUBSTRING is added.
Use SUBSTRING for window name completion in select command. Use BASIC everywhere else. --- TODO | 3 --- src/actions.c | 8 ++++---- src/completions.c | 32 ++++++++++++++++++++++++++++---- src/completions.h | 2 +- src/data.h | 16 ++++++++++++++++ src/editor.c | 5 +++-- src/editor.h | 2 +- src/input.c | 6 +++--- src/input.h | 2 +- 9 files changed, 57 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 36c33a3..a84ba56 100644 --- a/TODO +++ b/TODO @@ -25,9 +25,6 @@ stuff ??? * Pasting into input buffer Fix it. -* window name substring matching. -Do it. - * allow letters and numbers to be used for frames (in fselect) * dump all all def* settings diff --git a/src/actions.c b/src/actions.c index c0fc569..c53acc0 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1378,8 +1378,8 @@ cmd_select (int interactive, struct cmdarg **args) /* FIXME: This is manually done because of the kinds of things select accepts. */ if (args[0] == NULL) - str = get_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW, hist_SELECT, - window_completions); + str = get_more_input (MESSAGE_PROMPT_SWITCH_TO_WINDOW, "", hist_SELECT, + SUBSTRING, window_completions); else str = xstrdup (ARG_STRING(0)); @@ -2641,7 +2641,7 @@ cmd_colon (int interactive UNUSED, struct cmdarg **args) input = get_input (MESSAGE_PROMPT_COMMAND, hist_COMMAND, colon_completions); else input = get_more_input (MESSAGE_PROMPT_COMMAND, ARG_STRING(0), hist_COMMAND, - colon_completions); + BASIC, colon_completions); /* User aborted. */ if (input == NULL) @@ -5930,7 +5930,7 @@ cmd_prompt (int interactive UNUSED, struct cmdarg **args) query = sbuf_new (prefix - arg_str); sbuf_nconcat (query, arg_str, prefix - arg_str); output = get_more_input (sbuf_get (query), prefix, hist_PROMPT, - trivial_completions); + BASIC, trivial_completions); sbuf_free (query); } else diff --git a/src/completions.c b/src/completions.c index 483a4d3..9bd35af 100644 --- a/src/completions.c +++ b/src/completions.c @@ -18,13 +18,14 @@ * Boston, MA 02111-1307 USA */ +#define _GNU_SOURCE #include <string.h> #include "ratpoison.h" #include "completions.h" rp_completions * -completions_new (completion_fn list_fn) +completions_new (completion_fn list_fn, enum completion_styles style) { rp_completions *c; @@ -35,6 +36,7 @@ completions_new (completion_fn list_fn) c->last_match = NULL; c->partial = NULL; c->virgin = 1; + c->style = style; return c; } @@ -96,6 +98,27 @@ completions_update (rp_completions *c, char *partial) free (new_list); } + +/* Return true if completion is an alternative for partial string, + given the style used. */ +static int +completions_match(rp_completions *c, char *completion, char *partial) +{ + int match = 0; + + switch (c->style) + { + case BASIC: + match = str_comp (completion, partial, strlen(partial)); + break; + case SUBSTRING: + match = (strcasestr (completion, partial) != NULL); + break; + } + + return match; +} + static char * completions_prev_match (rp_completions *c) { @@ -107,7 +130,7 @@ completions_prev_match (rp_completions *c) cur != c->last_match; cur = list_prev_entry (cur, &c->completion_list, node)) { - if (str_comp (sbuf_get (cur), c->partial, strlen (c->partial))) + if (completions_match (c, sbuf_get (cur), c->partial)) { /* We found a match so update our last_match pointer and return the string. */ @@ -130,7 +153,7 @@ completions_next_match (rp_completions *c) cur != c->last_match; cur = list_next_entry (cur, &c->completion_list, node)) { - if (str_comp (sbuf_get (cur), c->partial, strlen (c->partial))) + if (completions_match (c, sbuf_get (cur), c->partial)) { /* We found a match so update our last_match pointer and return the string. */ @@ -162,8 +185,9 @@ completions_complete (rp_completions *c, char *partial, int direction) if (direction == COMPLETION_PREVIOUS) c->last_match = list_prev_entry (c->last_match, &c->completion_list, node); + PRINT_DEBUG(("%s -> %s\n", sbuf_get (c->last_match), c->partial)); /* Now check if last_match is a match for partial. */ - if (str_comp (sbuf_get (c->last_match), c->partial, strlen (c->partial))) + if (completions_match (c, sbuf_get (c->last_match), c->partial)) return sbuf_get (c->last_match); } diff --git a/src/completions.h b/src/completions.h index d3c44af..01586ee 100644 --- a/src/completions.h +++ b/src/completions.h @@ -22,7 +22,7 @@ #define _RATPOISON_COMPLETIONS_H 1 char *completions_complete (rp_completions *c, char *partial, int direction); -rp_completions *completions_new (completion_fn list_fn); +rp_completions *completions_new (completion_fn list_fn, enum completion_styles style); void completions_free (rp_completions *c); #endif /* ! _RATPOISON_COMPLETIONS_H */ diff --git a/src/data.h b/src/data.h index f4bd185..85a0324 100644 --- a/src/data.h +++ b/src/data.h @@ -332,6 +332,19 @@ struct modifier_info typedef struct list_head *(*completion_fn)(char *string); +/* + BASIC: The completion shall begin with the same characters as the partial + string. Case is ignored. + + SUBSTRING: The partial string shall be a subpart of the completion. Case + is ignored. +*/ +enum completion_styles +{ + BASIC, + SUBSTRING +}; + struct rp_completions { /* A pointer to the partial string that is being completed. We need @@ -352,6 +365,9 @@ struct rp_completions /* virgin = 1 means no completions have been attempted on the input string. */ unsigned short int virgin; + + /* The completion style used to perform string comparisons */ + enum completion_styles style; }; struct rp_input_line diff --git a/src/editor.c b/src/editor.c index 1360241..96cdc6e 100644 --- a/src/editor.c +++ b/src/editor.c @@ -100,14 +100,15 @@ static edit_binding edit_bindings[] = { {0, 0}, 0} }; rp_input_line * -input_line_new (char *prompt, char *preinput, int history_id, completion_fn fn) +input_line_new (char *prompt, char *preinput, int history_id, + enum completion_styles style, completion_fn fn) { rp_input_line *line; size_t length; line = xmalloc (sizeof (rp_input_line)); line->prompt = prompt; - line->compl = completions_new (fn); + line->compl = completions_new (fn, style); line->history_id = history_id; /* Allocate some memory to start with (100 extra bytes) */ diff --git a/src/editor.h b/src/editor.h index 131a5ad..445cd82 100644 --- a/src/editor.h +++ b/src/editor.h @@ -39,7 +39,7 @@ typedef enum edit_status #define RP_IS_UTF8_CONT(c) (defaults.utf8_locale && ((c) & 0xC0) == 0x80) /* Input line functions */ -rp_input_line *input_line_new (char *prompt, char *preinput, int history_id, completion_fn fn); +rp_input_line *input_line_new (char *prompt, char *preinput, int history_id, enum completion_styles style, completion_fn fn); void input_line_free (rp_input_line *line); edit_status execute_edit_action (rp_input_line *line, KeySym ch, unsigned int modifier, char *keysym_buf); diff --git a/src/input.c b/src/input.c index 9bc0347..51443e8 100644 --- a/src/input.c +++ b/src/input.c @@ -561,12 +561,12 @@ ring_bell (void) char * get_input (char *prompt, int history_id, completion_fn fn) { - return get_more_input (prompt, "", history_id, fn); + return get_more_input (prompt, "", history_id, BASIC, fn); } char * get_more_input (char *prompt, char *preinput, int history_id, - completion_fn compl_fn) + enum completion_styles style, completion_fn compl_fn) { /* Emacs 21 uses a 513 byte string to store the keysym name. */ char keysym_buf[513]; @@ -582,7 +582,7 @@ get_more_input (char *prompt, char *preinput, int history_id, history_reset(); /* Create our line structure */ - line = input_line_new (prompt, preinput, history_id, compl_fn); + line = input_line_new (prompt, preinput, history_id, style, compl_fn); /* We don't want to draw overtop of the program bar. */ hide_bar (s); diff --git a/src/input.h b/src/input.h index 7abb652..9515605 100644 --- a/src/input.h +++ b/src/input.h @@ -25,7 +25,7 @@ char *keysym_to_string (KeySym keysym, unsigned int modifier); int cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_name, int len, int ignore_bad_mods); char *get_input (char *prompt, int history_id, completion_fn fn); -char *get_more_input (char *prompt, char *preinput, int history_id, completion_fn fn); +char *get_more_input (char *prompt, char *preinput, int history_id, enum completion_styles style, completion_fn fn); void read_any_key (void); int read_single_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len); int read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len); -- 2.9.2 _______________________________________________ Ratpoison-devel mailing list Ratpoison-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/ratpoison-devel