]> git.armaanb.net Git - dmenu.git/commitdiff
add key bindings for moving to the word start or end
authorQuentin Rameau <quinq@fifth.space>
Tue, 13 Mar 2018 16:15:09 +0000 (17:15 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 13 Mar 2018 19:10:46 +0000 (20:10 +0100)
Mod1+b/^Left and Mod1+f/^Right

dmenu.1
dmenu.c

diff --git a/dmenu.1 b/dmenu.1
index 9eab758ca5b51a6b5ca1fc81d5ab095a1e3fde27..fbb3f761b0c5a63bc705b4999174d8a8f543621d 100644 (file)
--- a/dmenu.1
+++ b/dmenu.1
@@ -100,6 +100,12 @@ Confirm input.  Prints the input text to stdout and exits, returning success.
 .B Escape
 Exit without selecting an item, returning failure.
 .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
 C\-a
 Home
 .TP
@@ -160,6 +166,12 @@ Paste from primary X selection
 C\-Y
 Paste from X clipboard
 .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
 .TP
 M\-g
 Home
 .TP
diff --git a/dmenu.c b/dmenu.c
index a2461115ec253a051d2f3438890eb7944ffe2ccf..5e9c36735152d883d00df4cc21eaad5b3172ce40 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -287,6 +287,22 @@ nextrune(int inc)
        return n;
 }
 
        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)
 {
 static void
 keypress(XKeyEvent *ev)
 {
@@ -334,6 +350,14 @@ keypress(XKeyEvent *ev)
                        XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
                                          utf8, utf8, win, CurrentTime);
                        return;
                        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;
                case XK_Return:
                case XK_KP_Enter:
                        break;
@@ -345,6 +369,14 @@ keypress(XKeyEvent *ev)
                }
        else if (ev->state & Mod1Mask)
                switch(ksym) {
                }
        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;
                case XK_g: ksym = XK_Home;  break;
                case XK_G: ksym = XK_End;   break;
                case XK_h: ksym = XK_Up;    break;
@@ -359,6 +391,8 @@ keypress(XKeyEvent *ev)
                if (!iscntrl(*buf))
                        insert(buf, len);
                break;
                if (!iscntrl(*buf))
                        insert(buf, len);
                break;
+       case NoSymbol:
+               break;
        case XK_Delete:
                if (text[cursor] == '\0')
                        return;
        case XK_Delete:
                if (text[cursor] == '\0')
                        return;