all repos — dmenu @ e2a280541eab62717d6a9a72d047c832e5cb1edc

my build of dmenu

add key bindings for moving to the word start or end

Mod1+b/^Left and Mod1+f/^Right
Quentin Rameau quinq@fifth.space
Tue, 13 Mar 2018 17:15:09 +0100
commit

e2a280541eab62717d6a9a72d047c832e5cb1edc

parent

889512811d7ae410eb4ab60be3568278b3e23f2e

2 files changed, 46 insertions(+), 0 deletions(-)

jump to
M dmenu.1dmenu.1

@@ -100,6 +100,12 @@ .TP

.B Escape Exit without selecting an item, returning failure. .TP +.B Ctrl-Left +Move cursor to the start of the current word +.TP +.B Ctrl-Right +Move cursor to the end of the current word +.TP C\-a Home .TP

@@ -159,6 +165,12 @@ Paste from primary X selection

.TP C\-Y Paste from X clipboard +.TP +M\-b +Move cursor to the start of the current word +.TP +M\-f +Move cursor to the end of the current word .TP M\-g Home
M dmenu.cdmenu.c

@@ -288,6 +288,22 @@ return n;

} static void +movewordedge(int dir) +{ + if (dir < 0) { /* move cursor to the start of the word*/ + while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) + cursor = nextrune(-1); + while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) + cursor = nextrune(-1); + } else { /* move cursor to the end of the word */ + while (text[cursor] && strchr(worddelimiters, text[cursor])) + cursor = nextrune(+1); + while (text[cursor] && !strchr(worddelimiters, text[cursor])) + cursor = nextrune(+1); + } +} + +static void keypress(XKeyEvent *ev) { char buf[32];

@@ -334,6 +350,14 @@ case XK_Y:

XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, utf8, utf8, win, CurrentTime); return; + case XK_Left: + movewordedge(-1); + ksym = NoSymbol; + break; + case XK_Right: + movewordedge(+1); + ksym = NoSymbol; + break; case XK_Return: case XK_KP_Enter: break;

@@ -345,6 +369,14 @@ return;

} else if (ev->state & Mod1Mask) switch(ksym) { + case XK_b: + movewordedge(-1); + ksym = NoSymbol; + break; + case XK_f: + movewordedge(+1); + ksym = NoSymbol; + break; case XK_g: ksym = XK_Home; break; case XK_G: ksym = XK_End; break; case XK_h: ksym = XK_Up; break;

@@ -358,6 +390,8 @@ switch(ksym) {

default: if (!iscntrl(*buf)) insert(buf, len); + break; + case NoSymbol: break; case XK_Delete: if (text[cursor] == '\0')