diff options
author | Quentin Rameau <quinq@fifth.space> | 2018-03-13 17:15:09 +0100 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2018-03-13 20:10:46 +0100 |
commit | e2a280541eab62717d6a9a72d047c832e5cb1edc (patch) | |
tree | 5cdfb7c03fc76d7024e009dc3d9617cb5db48520 | |
parent | 889512811d7ae410eb4ab60be3568278b3e23f2e (diff) |
add key bindings for moving to the word start or end
Mod1+b/^Left and Mod1+f/^Right
-rw-r--r-- | dmenu.1 | 12 | ||||
-rw-r--r-- | dmenu.c | 34 |
2 files changed, 46 insertions, 0 deletions
@@ -100,6 +100,12 @@ Confirm input. Prints the input text to stdout and exits, returning success. | |||
100 | .B Escape | 100 | .B Escape |
101 | Exit without selecting an item, returning failure. | 101 | Exit without selecting an item, returning failure. |
102 | .TP | 102 | .TP |
103 | .B Ctrl-Left | ||
104 | Move cursor to the start of the current word | ||
105 | .TP | ||
106 | .B Ctrl-Right | ||
107 | Move cursor to the end of the current word | ||
108 | .TP | ||
103 | C\-a | 109 | C\-a |
104 | Home | 110 | Home |
105 | .TP | 111 | .TP |
@@ -160,6 +166,12 @@ Paste from primary X selection | |||
160 | C\-Y | 166 | C\-Y |
161 | Paste from X clipboard | 167 | Paste from X clipboard |
162 | .TP | 168 | .TP |
169 | M\-b | ||
170 | Move cursor to the start of the current word | ||
171 | .TP | ||
172 | M\-f | ||
173 | Move cursor to the end of the current word | ||
174 | .TP | ||
163 | M\-g | 175 | M\-g |
164 | Home | 176 | Home |
165 | .TP | 177 | .TP |
@@ -288,6 +288,22 @@ nextrune(int inc) | |||
288 | } | 288 | } |
289 | 289 | ||
290 | static void | 290 | static void |
291 | movewordedge(int dir) | ||
292 | { | ||
293 | if (dir < 0) { /* move cursor to the start of the word*/ | ||
294 | while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)])) | ||
295 | cursor = nextrune(-1); | ||
296 | while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)])) | ||
297 | cursor = nextrune(-1); | ||
298 | } else { /* move cursor to the end of the word */ | ||
299 | while (text[cursor] && strchr(worddelimiters, text[cursor])) | ||
300 | cursor = nextrune(+1); | ||
301 | while (text[cursor] && !strchr(worddelimiters, text[cursor])) | ||
302 | cursor = nextrune(+1); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | static void | ||
291 | keypress(XKeyEvent *ev) | 307 | keypress(XKeyEvent *ev) |
292 | { | 308 | { |
293 | char buf[32]; | 309 | char buf[32]; |
@@ -334,6 +350,14 @@ keypress(XKeyEvent *ev) | |||
334 | XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, | 350 | XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, |
335 | utf8, utf8, win, CurrentTime); | 351 | utf8, utf8, win, CurrentTime); |
336 | return; | 352 | return; |
353 | case XK_Left: | ||
354 | movewordedge(-1); | ||
355 | ksym = NoSymbol; | ||
356 | break; | ||
357 | case XK_Right: | ||
358 | movewordedge(+1); | ||
359 | ksym = NoSymbol; | ||
360 | break; | ||
337 | case XK_Return: | 361 | case XK_Return: |
338 | case XK_KP_Enter: | 362 | case XK_KP_Enter: |
339 | break; | 363 | break; |
@@ -345,6 +369,14 @@ keypress(XKeyEvent *ev) | |||
345 | } | 369 | } |
346 | else if (ev->state & Mod1Mask) | 370 | else if (ev->state & Mod1Mask) |
347 | switch(ksym) { | 371 | switch(ksym) { |
372 | case XK_b: | ||
373 | movewordedge(-1); | ||
374 | ksym = NoSymbol; | ||
375 | break; | ||
376 | case XK_f: | ||
377 | movewordedge(+1); | ||
378 | ksym = NoSymbol; | ||
379 | break; | ||
348 | case XK_g: ksym = XK_Home; break; | 380 | case XK_g: ksym = XK_Home; break; |
349 | case XK_G: ksym = XK_End; break; | 381 | case XK_G: ksym = XK_End; break; |
350 | case XK_h: ksym = XK_Up; break; | 382 | case XK_h: ksym = XK_Up; break; |
@@ -359,6 +391,8 @@ keypress(XKeyEvent *ev) | |||
359 | if (!iscntrl(*buf)) | 391 | if (!iscntrl(*buf)) |
360 | insert(buf, len); | 392 | insert(buf, len); |
361 | break; | 393 | break; |
394 | case NoSymbol: | ||
395 | break; | ||
362 | case XK_Delete: | 396 | case XK_Delete: |
363 | if (text[cursor] == '\0') | 397 | if (text[cursor] == '\0') |
364 | return; | 398 | return; |