forked from speedie/spmenu
add ability to delete word, some other small changes to previous commit
This commit is contained in:
parent
ba5af9883b
commit
cca8ca373c
13
keybinds.h
13
keybinds.h
|
@ -39,10 +39,6 @@ static Key keys[] = {
|
|||
*
|
||||
* mode modifier key function argument */
|
||||
{ 1, 0, XK_Escape, switchmode, {0} },
|
||||
{ 1, 0, XK_Up, move, {.i = 1 } },
|
||||
{ 1, 0, XK_Down, move, {.i = 2 } },
|
||||
{ 1, 0, XK_Left, move, {.i = 3 } },
|
||||
{ 1, 0, XK_Right, move, {.i = 4 } },
|
||||
|
||||
/* normal mode
|
||||
*
|
||||
|
@ -84,8 +80,8 @@ static Key keys[] = {
|
|||
{ 0, SHIFT, XK_g, moveend, {0} },
|
||||
{ 0, 0, XK_Next, movenext, {0} },
|
||||
{ 0, 0, XK_Prior, moveprev, {0} },
|
||||
{ 0, SHIFT, XK_Left, moveword, {.i = -1 } },
|
||||
{ 0, SHIFT, XK_Right, moveword, {.i = +1 } },
|
||||
{ 0, CONTROL, XK_Left, moveword, {.i = -1 } },
|
||||
{ 0, CONTROL, XK_Right, moveword, {.i = +1 } },
|
||||
{ 0, 0, XK_Left, movecursor, {.i = -1 } },
|
||||
{ 0, 0, XK_Right, movecursor, {.i = +1 } },
|
||||
{ 0, MODIFIER1, XK_p, navhistory, {.i = -1 } },
|
||||
|
@ -99,4 +95,9 @@ static Key keys[] = {
|
|||
{ -1, CONTROL, XK_v, paste, {.i = 1 } }, /* primary buffer */
|
||||
{ -1, CONTROL|SHIFT, XK_v, paste, {.i = 2 } },
|
||||
{ -1, 0, XK_BackSpace, backspace, {0} },
|
||||
{ -1, CONTROL, XK_BackSpace, deleteword, {0} },
|
||||
{ -1, CONTROL, XK_Left, moveword, {.i = -1 } },
|
||||
{ -1, CONTROL, XK_Right, moveword, {.i = +1 } },
|
||||
{ -1, 0, XK_Left, movecursor, {.i = -1 } },
|
||||
{ -1, 0, XK_Right, movecursor, {.i = +1 } },
|
||||
};
|
||||
|
|
29
libs/arg.c
29
libs/arg.c
|
@ -193,17 +193,42 @@ viewhist(const Arg *arg)
|
|||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
deleteword(const Arg *arg)
|
||||
{
|
||||
if (cursor == 0)
|
||||
return;
|
||||
|
||||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, nextrune(-1) - cursor);
|
||||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, nextrune(-1) - cursor);
|
||||
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
moveword(const Arg *arg)
|
||||
{
|
||||
movewordedge(arg->i);
|
||||
if (arg->i < 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);
|
||||
}
|
||||
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
void
|
||||
movecursor(const Arg *arg)
|
||||
{
|
||||
cursor = arg->i ? nextrune(+1) : nextrune(-1);
|
||||
cursor = nextrune(arg->i);
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ static void restoresel(const Arg *arg);
|
|||
static void clear(const Arg *arg);
|
||||
static void viewhist(const Arg *arg);
|
||||
static void moveword(const Arg *arg);
|
||||
static void deleteword(const Arg *arg);
|
||||
static void movecursor(const Arg *arg);
|
||||
static void navhistory(const Arg *arg);
|
||||
static void backspace(const Arg *arg);
|
||||
|
|
17
spmenu.c
17
spmenu.c
|
@ -190,7 +190,6 @@ static void calcoffsets(void);
|
|||
static void readstdin(void);
|
||||
static void recalculatenumbers(void);
|
||||
static void usage(void);
|
||||
static void movewordedge(int dir);
|
||||
static void insert(const char *str, ssize_t n);
|
||||
static void cleanup(void);
|
||||
static void navigatehistfile(int dir);
|
||||
|
@ -395,22 +394,6 @@ nextrune(int inc)
|
|||
return n;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loadhistory(void)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue