Re: [cwm] tab completion

2012-11-06 Thread Alexander Polakov
* Alexander Polakov  [121107 02:20]:
> I think this one is ready for wider testing.
> 
> How to use: hit tab in exec menu to complete the command (start
> with / if you want something not in $PATH).  When you're ready,
> hit tab again.  This will open "file menu", which can be used to
> complete file argument.
> 
> Completion works for other menus as well.

Oops, sorry, I sent the wrong diff (previous revision).

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.155
diff -u -p -u -r1.155 calmwm.h
--- calmwm.h31 Oct 2012 22:06:24 -  1.155
+++ calmwm.h7 Nov 2012 01:06:13 -
@@ -73,6 +73,10 @@
 #define CWM_RCYCLE 0x0002
 #define CWM_INGROUP0x0004
 
+/* menu */
+#define CWM_MENU_DUMMY 0x0001
+#define CWM_MENU_FILE  0x0002
+
 #define KBTOGROUP(X) ((X) - 1)
 
 union arg {
@@ -260,7 +264,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +358,10 @@ voidgroup_update_names(struct 
screen
 voidsearch_match_client(struct menu_q *, struct menu_q *,
 char *);
 voidsearch_match_exec(struct menu_q *, struct menu_q *,
+char *);
+voidsearch_match_exec_path(struct menu_q *, struct menu_q 
*,
+char *);
+voidsearch_match_path_any(struct menu_q *, struct menu_q *,
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.64
diff -u -p -u -r1.64 kbfunc.c
--- kbfunc.c31 Oct 2012 19:30:19 -  1.64
+++ kbfunc.c7 Nov 2012 01:06:13 -
@@ -298,8 +298,9 @@ kbfunc_exec(struct client_ctx *cc, union
}
xfree(path);
 
-   if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
-   search_match_exec, NULL)) != NULL) {
+   if ((mi = menu_filter(sc, &menuq, label, NULL,
+   CWM_MENU_DUMMY | CWM_MENU_FILE,
+   search_match_exec_path, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
switch (cmd) {
@@ -376,7 +377,7 @@ kbfunc_ssh(struct client_ctx *cc, union 
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
+   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY,
search_match_exec, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
@@ -403,7 +404,7 @@ kbfunc_client_label(struct client_ctx *c
TAILQ_INIT(&menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+   mi = menu_filter(cc->sc, &menuq, "label", cc->label, CWM_MENU_DUMMY,
search_match_text, NULL);
 
if (!mi->abort) {
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.41
diff -u -p -u -r1.41 menu.c
--- menu.c  31 Oct 2012 19:30:19 -  1.41
+++ menu.c  7 Nov 2012 01:06:13 -
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "calmwm.h"
 
@@ -37,10 +38,11 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+   struct screen_ctx   *sc;
char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1];
@@ -54,6 +56,7 @@ struct menu_ctx {
int  height;
int  width;
int  num;
+   int  flags;
int  x;
int  y;
void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -93,7 +96,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
-char *initial, int dummy,
+char *initial, int flags, 
 void (*match)(struct menu_q *, struct menu_q *, char *),
 void (*print)(struct menu *, int))
 {
@@ -114,6 +117,8 @@ menu_filter(struct screen_ctx *sc, struc
xsave = mc.x;
ysave = mc.y;
 
+   mc.sc = sc;
+   

[cwm] tab completion

2012-11-06 Thread Alexander Polakov
I think this one is ready for wider testing.

How to use: hit tab in exec menu to complete the command (start
with / if you want something not in $PATH).  When you're ready,
hit tab again.  This will open "file menu", which can be used to
complete file argument.

Completion works for other menus as well.

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.155
diff -u -p -u -r1.155 calmwm.h
--- calmwm.h31 Oct 2012 22:06:24 -  1.155
+++ calmwm.h5 Nov 2012 22:20:42 -
@@ -73,6 +73,10 @@
 #define CWM_RCYCLE 0x0002
 #define CWM_INGROUP0x0004
 
+/* menu */
+#define CWM_MENU_DUMMY 0x0001
+#define CWM_MENU_FILE  0x0002
+
 #define KBTOGROUP(X) ((X) - 1)
 
 union arg {
@@ -260,7 +264,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -355,7 +359,11 @@ voidsearch_match_client(struct 
menu_
 char *);
 voidsearch_match_exec(struct menu_q *, struct menu_q *,
 char *);
+voidsearch_match_exec_path(struct menu_q *, struct menu_q 
*,
+char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
+char *);
+voidsearch_match_path(struct menu_q *, struct menu_q *,
 char *);
 voidsearch_print_client(struct menu *, int);
 
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.64
diff -u -p -u -r1.64 kbfunc.c
--- kbfunc.c31 Oct 2012 19:30:19 -  1.64
+++ kbfunc.c5 Nov 2012 22:20:42 -
@@ -298,8 +298,9 @@ kbfunc_exec(struct client_ctx *cc, union
}
xfree(path);
 
-   if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
-   search_match_exec, NULL)) != NULL) {
+   if ((mi = menu_filter(sc, &menuq, label, NULL,
+   CWM_MENU_DUMMY | CWM_MENU_FILE,
+   search_match_exec_path, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
switch (cmd) {
@@ -376,7 +377,7 @@ kbfunc_ssh(struct client_ctx *cc, union 
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
+   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY,
search_match_exec, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
@@ -403,7 +404,7 @@ kbfunc_client_label(struct client_ctx *c
TAILQ_INIT(&menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+   mi = menu_filter(cc->sc, &menuq, "label", cc->label, CWM_MENU_DUMMY,
search_match_text, NULL);
 
if (!mi->abort) {
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.41
diff -u -p -u -r1.41 menu.c
--- menu.c  31 Oct 2012 19:30:19 -  1.41
+++ menu.c  5 Nov 2012 22:20:42 -
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "calmwm.h"
 
@@ -37,10 +38,11 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
+   struct screen_ctx   *sc;
char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1];
@@ -54,6 +56,7 @@ struct menu_ctx {
int  height;
int  width;
int  num;
+   int  flags;
int  x;
int  y;
void (*match)(struct menu_q *, struct menu_q *, char *);
@@ -93,7 +96,7 @@ menu_init(struct screen_ctx *sc)
 
 struct menu *
 menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
-char *initial, int dummy,
+char *initial, int flags, 
 void (*match)(struct menu_q *, struct menu_q *, char *),
 void (*print)(struct menu *, int))
 {
@@ -114,6 +117,8 @@ menu_filter(struct screen_ctx *sc, struc
xsave = mc.x;
ysave = mc.y;
 
+   mc.sc = sc;
+   mc.flags = flags;
if (prompt == NULL) {
evmask = MENUMASK;
mc.promptstr[0] = '\0'

Re: cwm: tab-completion

2012-01-22 Thread Alexander Polakov
* Alexander Polakov  [120120 01:11]:
> Sometimes I want to type something like "xterm -e top" in "exec" menu,
> and feel the need for tab completion.

And now a bigger thing on top of that. One can tab-complete command with
the first menu entry, once ready, just hit tab again and start typing
file path. It uses glob(3), so asterisks are allowed.

I think diff needs more work, posting now to get comments and check if
there's any interest in this.

Index: calmwm.h
===
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.142
diff -u -p -r1.142 calmwm.h
--- calmwm.h13 Sep 2011 08:41:57 -  1.142
+++ calmwm.h22 Jan 2012 10:26:55 -
@@ -257,7 +257,7 @@ TAILQ_HEAD(cmd_q, cmd);
 struct menu {
TAILQ_ENTRY(menu)entry;
TAILQ_ENTRY(menu)resultentry;
-#define MENU_MAXENTRY   50
+#define MENU_MAXENTRY   200
char text[MENU_MAXENTRY + 1];
char print[MENU_MAXENTRY + 1];
void*ctx;
@@ -354,6 +354,8 @@ void search_match_exec(struct 
menu_q 
 char *);
 voidsearch_match_text(struct menu_q *, struct menu_q *,
 char *);
+voidsearch_match_path(struct menu_q *, struct menu_q *,
+char *);
 voidsearch_print_client(struct menu *, int);
 
 XineramaScreenInfo *screen_find_xinerama(struct screen_ctx *, int, int);
@@ -410,7 +412,7 @@ void mousefunc_window_raise(struct 
cl
 voidmousefunc_window_resize(struct client_ctx *, void *);
 
 struct menu*menu_filter(struct screen_ctx *, struct menu_q *,
-char *, char *, int,
+char *, char *, int, int,
 void (*)(struct menu_q *, struct menu_q *, char *),
 void (*)(struct menu *, int));
 voidmenu_init(struct screen_ctx *);
Index: group.c
===
RCS file: /cvs/xenocara/app/cwm/group.c,v
retrieving revision 1.55
diff -u -p -r1.55 group.c
--- group.c 29 Dec 2011 20:48:38 -  1.55
+++ group.c 22 Jan 2012 10:26:55 -
@@ -395,7 +395,7 @@ group_menu(XButtonEvent *e)
if (TAILQ_EMPTY(&menuq))
return;
 
-   mi = menu_filter(sc, &menuq, NULL, NULL, 0, NULL, NULL);
+   mi = menu_filter(sc, &menuq, NULL, NULL, 0, 0, NULL, NULL);
 
if (mi == NULL || mi->ctx == NULL)
goto cleanup;
Index: kbfunc.c
===
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.58
diff -u -p -r1.58 kbfunc.c
--- kbfunc.c29 Aug 2011 09:09:45 -  1.58
+++ kbfunc.c22 Jan 2012 10:26:55 -
@@ -157,7 +157,7 @@ kbfunc_client_search(struct client_ctx *
TAILQ_INSERT_TAIL(&menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
+   if ((mi = menu_filter(sc, &menuq, "window", NULL, 0, 0,
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi->ctx;
if (cc->flags & CLIENT_HIDDEN)
@@ -192,7 +192,7 @@ kbfunc_menu_search(struct client_ctx *cc
TAILQ_INSERT_TAIL(&menuq, mi, entry);
}
 
-   if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
+   if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, 0,
search_match_text, NULL)) != NULL)
u_spawn(((struct cmd *)mi->ctx)->image);
 
@@ -303,7 +303,7 @@ kbfunc_exec(struct client_ctx *cc, union
}
xfree(path);
 
-   if ((mi = menu_filter(sc, &menuq, label, NULL, 1,
+   if ((mi = menu_filter(sc, &menuq, label, NULL, 1, 1,
search_match_exec, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
@@ -383,7 +383,7 @@ kbfunc_ssh(struct client_ctx *cc, union 
xfree(lbuf);
(void)fclose(fp);
 
-   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1,
+   if ((mi = menu_filter(sc, &menuq, "ssh", NULL, 1, 0,
search_match_exec, NULL)) != NULL) {
if (mi->text[0] == '\0')
goto out;
@@ -410,7 +410,7 @@ kbfunc_client_label(struct client_ctx *c
TAILQ_INIT(&menuq);
 
/* dummy is set, so this will always return */
-   mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+   mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1, 0,
search_match_text, NULL);
 
if (!mi->abort) {
Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.33
diff -u -p -r1.33 menu.c
--- me

cwm: tab-completion

2012-01-19 Thread Alexander Polakov
Sometimes I want to type something like "xterm -e top" in "exec" menu,
and feel the need for tab completion.

Not sure about the FALLTHROUGH thing, though.

Index: menu.c
===
RCS file: /cvs/xenocara/app/cwm/menu.c,v
retrieving revision 1.33
diff -u -p -u -r1.33 menu.c
--- menu.c  8 Sep 2011 12:00:50 -   1.33
+++ menu.c  19 Jan 2012 20:58:45 -
@@ -37,7 +37,7 @@
 enum ctltype {
CTL_NONE = -1,
CTL_ERASEONE = 0, CTL_WIPE, CTL_UP, CTL_DOWN, CTL_RETURN,
-   CTL_ABORT, CTL_ALL
+   CTL_TAB, CTL_ABORT, CTL_ALL
 };
 
 struct menu_ctx {
@@ -254,6 +254,14 @@ menu_handle_key(XEvent *e, struct menu_c
mc->searchstr[0] = '\0';
mc->changed = 1;
break;
+   case CTL_TAB:
+   if ((mi = TAILQ_FIRST(resultq)) != NULL) {
+   (void)strlcpy(mc->searchstr,
+   mi->text, sizeof(mc->searchstr));
+   mc->changed = 1;
+   break;
+   }
+   /* FALLTHROUGH */
case CTL_ALL:
mc->list = !mc->list;
break;
@@ -475,6 +483,9 @@ menu_keycode(KeyCode kc, u_int state, en
break;
case XK_Return:
*ctl = CTL_RETURN;
+   break;
+   case XK_Tab:
+   *ctl = CTL_TAB;
break;
case XK_Up:
*ctl = CTL_UP;

-- 
Alexander Polakov | plhk.ru