diff options
| author | Quentin Carbonneaux | 2015-01-20 15:46:58 -0500 |
|---|---|---|
| committer | Quentin Carbonneaux | 2015-01-20 15:46:58 -0500 |
| commit | ecc068b38745dc55ef327fb4a1938297ed0e5f43 (patch) | |
| tree | 3b689064f2cae55d03140fdd646ac34ce5beb5a7 | |
| parent | ad7d23c907ab60797d9c2cffe3f30f76624c1de8 (diff) | |
add keyboard command ^L to switch windows
| -rw-r--r-- | vicmd.w | 26 | ||||
| -rw-r--r-- | win.c | 30 | ||||
| -rw-r--r-- | win.h | 1 |
3 files changed, 54 insertions, 3 deletions
@@ -1118,8 +1118,27 @@ keyboard driven editor with minimal visual footprint. static int a_tag(char buf, Cmd c, Cmd mc) { (void)buf; @+(void)c; @+(void)mc; - chwin(win_tag_toggle(curwin)); - return 0; + return chwin(win_tag_toggle(curwin)), 0; +} + +@ Switching between windows is done by clicks. One can also use +the keyboard command \.{\^L} followed by any of the basic line +motions \.h, \.j, \.k, and \.l to jump directly to a neighbor +window. + +@<Subr...@>= +static int a_swtch(char buf, Cmd c, Cmd mc) +{ + (void)buf; @+(void)mc; + switch (c.arg) { + default: + return 1; + case 'h': + case 'j': + case 'k': + case 'l': + return chwin(win_edge(curwin, c.arg)), 0; + } } @ Still from Acme, the editor allows the user to run arbitrary @@ -1281,7 +1300,7 @@ typedef int @[@] cmd_t(char, Cmd, Cmd); array below. @<Predecl...@>= -static cmd_t a_d, a_c, a_y, a_pP, a_m, a_ins, a_run, a_scroll, a_tag, a_write, a_exit; +static cmd_t a_d, a_c, a_y, a_pP, a_m, a_ins, a_run, a_scroll, a_swtch, a_tag, a_write, a_exit; @ @<Other key fields@>= union { @@ -1320,6 +1339,7 @@ union { [CTRL('U')] = Act(CZeroCount, a_scroll),@/ [CTRL('E')] = Act(0, a_scroll), [CTRL('Y')] = Act(0, a_scroll),@/ [CTRL('T')] = Act(0, a_tag), [CTRL('I')] = Act(0, a_run),@/ +[CTRL('L')] = Act(CHasArg, a_swtch),@/ [CTRL('W')] = Act(0, a_write), [CTRL('Q')] = Act(0, a_exit), @** Index. @@ -166,6 +166,36 @@ win_which(int x1, int y1) return w; } +/* win_edge - Find the edge window in the specified direction. + */ +W * +win_edge(W *w, int dir) +{ + W *w1; + int i; + + w1 = win_text(w); + if (dir == 'j' || dir == 'k') { + if (tag.visible && w == tag.owner) + return &tag.win; + return w1; + } + for (i=0; w1 != screen[i]; i++) + ; + switch (dir) { + case 'h': + if (--i < 0) + while (screen[i+1]) + i++; + break; + case 'l': + if (!screen[++i]) + i = 0; + break; + } + return screen[i]; +} + /* win_move - Resize or move a window to approximately set its * upper-left corner to the specified location. */ @@ -36,6 +36,7 @@ W *win_new(void); W *win_kill(W *); unsigned win_at(W *w, int x, int y); W *win_which(int x, int y); +W *win_edge(W *, int dir); void win_move(W *, int x, int y); void win_resize_frame(int w, int h); void win_redraw_frame(W *focus, int insert); |
