Useful for those times you want to use an unbound function, but even
when the function is bound to something you haven't memorized yet it
can be faster than lookup up the keybinding in the manual.  Bound to
CM-/ by default.

Index: cwm/calmwm.h
===================================================================
--- cwm.orig/calmwm.h   2012-11-05 13:50:58.468179916 -0600
+++ cwm/calmwm.h        2012-11-05 14:17:27.164487245 -0600
@@ -225,6 +225,13 @@
 };
 TAILQ_HEAD(screen_ctx_q, screen_ctx);
 
+struct func {
+       char            *tag;
+       void             (*handler)(struct client_ctx *, union arg *);
+       int              flags;
+       union arg        argument;
+};
+
 struct keybinding {
        TAILQ_ENTRY(keybinding)  entry;
        void                    (*callback)(struct client_ctx *, union arg *);
@@ -392,6 +399,7 @@
                             union arg *);
 void                    kbfunc_cmdexec(struct client_ctx *, union arg *);
 void                    kbfunc_exec(struct client_ctx *, union arg *);
+void                    kbfunc_func_search(struct client_ctx *, union arg *);
 void                    kbfunc_lock(struct client_ctx *, union arg *);
 void                    kbfunc_menu_search(struct client_ctx *, union arg *);
 void                    kbfunc_moveresize(struct client_ctx *, union arg *);
@@ -498,6 +506,7 @@
 extern struct screen_ctx_q              Screenq;
 extern struct client_ctx_q              Clientq;
 extern struct conf                      Conf;
+extern struct func                      name_to_kbfunc[];
 
 extern int                              HasXinerama, HasRandr, Randr_ev;
 
Index: cwm/conf.c
===================================================================
--- cwm.orig/conf.c     2012-11-05 10:25:37.577424801 -0600
+++ cwm/conf.c  2012-11-05 14:17:27.164487245 -0600
@@ -99,6 +99,7 @@
        { "M-Up",       "raise" },
        { "M-slash",    "search" },
        { "C-slash",    "menusearch" },
+       { "CM-slash",   "funcsearch" },
        { "M-Tab",      "cycle" },
        { "MS-Tab",     "rcycle" },
        { "CM-n",       "label" },
@@ -284,15 +285,11 @@
        cc->flags |= ignore ? CLIENT_IGNORE : 0;
 }
 
-static struct {
-       char            *tag;
-       void             (*handler)(struct client_ctx *, union arg *);
-       int              flags;
-       union arg        argument;
-} name_to_kbfunc[] = {
+struct func name_to_kbfunc[] = {
        { "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, {0} },
        { "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, {0} },
        { "search", kbfunc_client_search, 0, {0} },
+       { "funcsearch", kbfunc_func_search, KBFLAG_NEEDCLIENT, {0} },
        { "menusearch", kbfunc_menu_search, 0, {0} },
        { "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, {0} },
        { "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} },
@@ -399,6 +396,7 @@
            {.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
        { "bigptrmoveright", kbfunc_moveresize, 0,
            {.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
+       { NULL, NULL, 0, {0} }
 };
 
 /*
@@ -488,7 +486,8 @@
                return;
 
        for (iter = 0; iter < nitems(name_to_kbfunc); iter++) {
-               if (strcmp(name_to_kbfunc[iter].tag, binding) != 0)
+               if (name_to_kbfunc[iter].tag == NULL ||
+                   strcmp(name_to_kbfunc[iter].tag, binding) != 0)
                        continue;
 
                current_binding->callback = name_to_kbfunc[iter].handler;
Index: cwm/kbfunc.c
===================================================================
--- cwm.orig/kbfunc.c   2012-11-05 10:25:37.577424801 -0600
+++ cwm/kbfunc.c        2012-11-05 14:17:27.164487245 -0600
@@ -174,6 +174,35 @@
 }
 
 void
+kbfunc_func_search(struct client_ctx *cc, union arg *arg)
+{
+       struct screen_ctx       *sc = cc->sc;
+       struct func             *func;
+       struct menu             *mi;
+       struct menu_q            menuq;
+
+       TAILQ_INIT(&menuq);
+
+       for (func = name_to_kbfunc; func->tag != NULL; func++) {
+               mi = xcalloc(1, sizeof(*mi));
+               (void)strlcpy(mi->text, func->tag, sizeof(mi->text));
+               mi->ctx = func;
+               TAILQ_INSERT_TAIL(&menuq, mi, entry);
+       }
+
+       if ((mi = menu_filter(sc, &menuq, "function", NULL, 0,
+           search_match_text, NULL)) != NULL) {
+               func = (struct func *)mi->ctx;
+               (*func->handler)(cc, &func->argument);
+       }
+
+       while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
+               TAILQ_REMOVE(&menuq, mi, entry);
+               xfree(mi);
+       }
+}
+
+void
 kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
 {
        struct screen_ctx       *sc = cc->sc;
Index: cwm/cwm.1
===================================================================
--- cwm.orig/cwm.1      2012-10-31 17:12:11.710580000 -0500
+++ cwm/cwm.1   2012-11-05 14:21:15.746828265 -0600
@@ -70,6 +70,8 @@
 Search for windows.
 .It Ic C-/
 Search for applications.
+.It Ic CM-/
+Search for internal functions.
 .It Ic CM-n
 Label current window.
 .It Ic M-Tab
Index: cwm/cwmrc.5
===================================================================
--- cwm.orig/cwmrc.5    2012-11-05 14:16:34.183944000 -0600
+++ cwm/cwmrc.5 2012-11-05 14:22:32.637617816 -0600
@@ -284,6 +284,8 @@
 Launch window search menu.
 .It menusearch
 Launch application search menu.
+.It funcsearch
+Launch internal function search menu.
 .It exec
 Launch
 .Dq exec program

Reply via email to