add key bindings for moving to the word start or end e2a28054
Mod1+b/^Left and Mod1+f/^Right
Quentin Rameau · 2018-03-13 17:15 2 file(s) · +46 −0
dmenu.1 +12 −0
100 100
.B Escape
101 101
Exit without selecting an item, returning failure.
102 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 109
C\-a
104 110
Home
105 111
.TP
159 165
.TP
160 166
C\-Y
161 167
Paste from X clipboard
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
162 174
.TP
163 175
M\-g
164 176
Home
dmenu.c +34 −0
288 288
}
289 289
290 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 307
keypress(XKeyEvent *ev)
292 308
{
293 309
	char buf[32];
334 350
			XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
335 351
			                  utf8, utf8, win, CurrentTime);
336 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 361
		case XK_Return:
338 362
		case XK_KP_Enter:
339 363
			break;
345 369
		}
346 370
	else if (ev->state & Mod1Mask)
347 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 380
		case XK_g: ksym = XK_Home;  break;
349 381
		case XK_G: ksym = XK_End;   break;
350 382
		case XK_h: ksym = XK_Up;    break;
358 390
	default:
359 391
		if (!iscntrl(*buf))
360 392
			insert(buf, len);
393 +
		break;
394 +
	case NoSymbol:
361 395
		break;
362 396
	case XK_Delete:
363 397
		if (text[cursor] == '\0')