Re: [PATCH v2] Introduce multiple completion styles.
[email protected] (Jérémie Courrèges-Anglas) Tue, 16 Aug 2016 19:39:15 +0200
| Newsgroups | gmane.comp.window-managers.ratpoison.devel |
|---|---|
| Message-ID | <[email protected]> |
Mathieu OTHACEHE <[email protected]> writes: > 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. > --- > > Hi, Hi, > Here is the v2 of the patch, I removed a debug > message I forget. Your patch hasn't been forgotten, I just need to schedule some time. Cheers, > Mathieu > > Changelog: > > v2: Remove a forgotten debug message. > > TODO | 3 --- > src/actions.c | 8 ++++---- > src/completions.c | 31 +++++++++++++++++++++++++++---- > 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, 56 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..7320ae5 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. */ > @@ -163,7 +186,7 @@ completions_complete (rp_completions *c, char *partial, int direction) > c->last_match = list_prev_entry (c->last_match, &c->completion_list, node); > > /* 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); -- jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE _______________________________________________ Ratpoison-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/ratpoison-devel
signature.asc
(application/pgp-signature, 818 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJXs0/DAAoJEA36dK4VJOfutnEQAKNBlOfTO8HIfm4zydWD0IR6 QhrIS/c90bjjAlhwnjdKS6PuKssBtnRIu4yt6WE+hMy1+l74/c53jbPCjKXRITDo tcH1cn1My1g21qxkmW+DqMxPvNNCJqZZn2Wi19+aGvC5PM8QfNIzTi9x5CSrvVPg MvaOvoHyzS8TqcbZusYpOrnUtYNumsFOOXzj06H81upaZfaXn/RYY6C98bqnN8iF 0+4JhQWn/96MUDMDdRspCYb92ziyG6auKeVNuqGXCvfHWx9Y1WdtD9JdxsWmKQCx zushCfpP6u2umWq3ZbbdHOInNU6rtnZOOFdTWDWkBqAttCCn1l9+ptvuCC7yDD0r 1gHnou/yJ601pWrP/MKYtDuFmvjNZ2e/fZlnUK+TJEW+gsQ4zdDu9pJERtkvC6i3 brh8W9yGavYi3EVvr2eOUDoR0OCwFKQm0JHkP3SdLaMuZFMzZiDDRMTCvHjBhwy/ gniC9oDpNlFZPlf+V7/wRuVW+5ZAzY/FsBOFU2Qt+UihQnFF55onMWNOQaxzoFyx UhJ9dH+1cUM0nMKj/7m6/hj/swM9ACQNVvIAVaN0wfQKHnkRLzdpvW4V5Bqnf5cM vCJg2MKXy/5aLExrsAUvGXX7auR5ZbDsHKyrvYyxLTdjrLSK8S7Xlcaa6pbiKQ3l DYhG+5Iiz+Q+YbAtLg5G =Hj5I -----END PGP SIGNATURE-----