sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 2402838982a194f72576cf80f825f9b3ffcd8262
parent e2415b9e6891dfc4868f42e547d6ba7362aa63aa
Author: Matt Briançon <matt.briancon@gmail.com>
Date:   Sat, 26 Sep 2020 15:54:31 -0400

[dmenu][patch] -S: do not sort matches

Diffstat:
Atools.suckless.org/dmenu/patches/no-sort/dmenu-nosort-5.0.diff | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/no-sort/index.md | 18++++++++++++++++++
2 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/no-sort/dmenu-nosort-5.0.diff b/tools.suckless.org/dmenu/patches/no-sort/dmenu-nosort-5.0.diff @@ -0,0 +1,90 @@ +From 7fbf9575aff62301e17b7f0601080633ae2a8a34 Mon Sep 17 00:00:00 2001 +From: Matt Briancon <matt.briancon@gmail.com> +Date: Fri, 25 Sep 2020 22:13:38 -0400 +Subject: [PATCH] -S: do not sort matches + +--- + dmenu.1 | 3 +++ + dmenu.c | 23 ++++++++++++++++------- + 2 files changed, 19 insertions(+), 7 deletions(-) + +diff --git a/dmenu.1 b/dmenu.1 +index 323f93c..b6af611 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file. + .B \-i + dmenu matches menu items case insensitively. + .TP ++.B \-S ++dmenu does not sort menu items after matching. ++.TP + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..efe968c 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -1,6 +1,7 @@ + /* See LICENSE file for copyright and license details. */ + #include <ctype.h> + #include <locale.h> ++#include <stdbool.h> + #include <stdio.h> + #include <stdlib.h> + #include <string.h> +@@ -44,6 +45,7 @@ static struct item *items = NULL; + static struct item *matches, *matchend; + static struct item *prev, *curr, *next, *sel; + static int mon = -1, screen; ++static bool sortmatches = true; + + static Atom clip, utf8; + static Display *dpy; +@@ -236,13 +238,18 @@ match(void) + break; + if (i != tokc) /* not all tokens match */ + continue; +- /* exact matches go first, then prefixes, then substrings */ +- if (!tokc || !fstrncmp(text, item->text, textsize)) ++ ++ if (!sortmatches) + appenditem(item, &matches, &matchend); +- else if (!fstrncmp(tokv[0], item->text, len)) +- appenditem(item, &lprefix, &prefixend); +- else +- appenditem(item, &lsubstr, &substrend); ++ else { ++ /* exact matches go first, then prefixes, then substrings */ ++ if (!tokc || !fstrncmp(text, item->text, textsize)) ++ appenditem(item, &matches, &matchend); ++ else if (!fstrncmp(tokv[0], item->text, len)) ++ appenditem(item, &lprefix, &prefixend); ++ else ++ appenditem(item, &lsubstr, &substrend); ++ } + } + if (lprefix) { + if (matches) { +@@ -689,7 +696,7 @@ setup(void) + static void + usage(void) + { +- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" ++ fputs("usage: dmenu [-bfivS] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); + exit(1); + } +@@ -709,6 +716,8 @@ main(int argc, char *argv[]) + topbar = 0; + else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */ + fast = 1; ++ else if (!strcmp(argv[i], "-S")) /* do not sort matches */ ++ sortmatches = false; + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +-- +2.25.1 + diff --git a/tools.suckless.org/dmenu/patches/no-sort/index.md b/tools.suckless.org/dmenu/patches/no-sort/index.md @@ -0,0 +1,18 @@ +no sort +======= + +Description +----------- + +Adds the `-S` option to disable sorting menu items after matching. Useful, for example, when menu items are sorted by their frequency of use (using an external cache) and the most frequently selected items should always appear first regardless of how they were exact, prefix, or substring matches. + +Download +-------- + +* For 5.0: [dmenu-nosort-5.0.diff](dmenu-nosort-5.0.diff) + + +Author +------ + +* Matt Briançon <matt.briancon@gmail.com>