commit 2402838982a194f72576cf80f825f9b3ffcd8262
Author: Matt Briançon <[email protected]>
Date: Sat Sep 26 15:54:31 2020 -0400
[dmenu][patch] -S: do not sort matches
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
new file mode 100644
index 00000000..c443f760
--- /dev/null
+++ 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 <[email protected]>
+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]
"
++ fputs("usage: dmenu [-bfivS] [-l lines] [-p prompt] [-fn font] [-m
monitor]
"
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w
windowid]
", 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
new file mode 100644
index 00000000..431c8857
--- /dev/null
+++ 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 <[email protected]>