Re: [dwm] [dmenu] patch: non-consecutive substring matching

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Mon, 4 Jun 2007 15:04:25 +0200

Hi Dave,

many thx for your patch. The idocontains() algorithm is
implemented in a very simple way, I like it. Though I'm not sure
yet what others think about it, and if it should be applied for
the mainstream dmenu.

Regards,
Anselm

On Fri, Jun 01, 2007 at 07:02:19PM +0200, Robert Manea wrote:
> ----- Forwarded message from David Glasser <glasser_AT_mit.edu> -----
>
> Message-ID: <1ea387f60706010957u31c539eeja11170c392affa14_AT_mail.gmail.com>
> From: David Glasser <glasser_AT_mit.edu>
> Subject: Fwd: dmenu patch: non-consecutive substring matching
> Date: Fri, 1 Jun 2007 12:57:27 -0400
> To: rob.manea_AT_gmail.com
>
>
> I find it useful to be able to type non-consecutive substrings to
> match for dmenu. For example, I use dmenu to send internal commands
> to xmonad, and I like to be able to type "v1" for "view1", or "to2"
> for "screen-to-2". The following patch enables non-consecutive
> substring matching. (I refer to it as "ido" matching because I was
> inspired to do it by emacs' ido mode.) Non-consecutive matches are
> lower priority than exact substring matches. I hope other people find
> this useful!
>
> --dave
>
>
> --
> David Glasser | glasser@mit.edu | http://www.davidglasser.net/
>
> diff -r 55399b039414 main.c
> --- a/main.c Wed May 30 12:22:38 2007 +0200
> +++ b/main.c Thu May 31 16:43:11 2007 -0400
> @@ -168,6 +168,23 @@ initfont(const char *fontstr) {
> dc.font.height = dc.font.ascent + dc.font.descent;
> }
>
> +static int
> +idocontains(char *text, char *pattern) {
> + if (!text || !pattern || !*text || !*pattern) {
> + return 0;
> + }
> +
> + while (*text && *pattern) {
> + if (*text == *pattern) {
> + pattern++;
> + }
> + text++;
> + }
> +
> + // if we matched all the text, *pattern == 0.
> + return !*pattern;
> +}
> +
> static void
> match(char *pattern) {
> unsigned int plen;
> @@ -192,6 +209,19 @@ match(char *pattern) {
> for(i = allitems; i; i=i->next)
> if(plen && strncmp(pattern, i->text, plen)
> && strstr(i->text, pattern)) {
> + if(!j)
> + item = i;
> + else
> + j->right = i;
> + i->left = j;
> + i->right = NULL;
> + j = i;
> + nitem++;
> + }
> + for(i = allitems; i; i=i->next)
> + if(plen && strncmp(pattern, i->text, plen)
> + && !strstr(i->text, pattern)
> + && idocontains(i->text,pattern)) {
> if(!j)
> item = i;
> else
>
>
> ----- End forwarded message -----
>

-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
Received on Mon Jun 04 2007 - 15:04:25 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:43:49 UTC