minor fixups
This commit is contained in:
8
ke.1
8
ke.1
@@ -26,6 +26,8 @@ k-command mode can be exited with ESC or C-g.
|
|||||||
.Bl -tag -width xxxxxxxxxxxx -offset indent
|
.Bl -tag -width xxxxxxxxxxxx -offset indent
|
||||||
.It C-k BACKSPACE
|
.It C-k BACKSPACE
|
||||||
Delete from the cursor to the beginning of the line.
|
Delete from the cursor to the beginning of the line.
|
||||||
|
.It C-k c
|
||||||
|
Clear (flush) the kill ring.
|
||||||
.It C-k SPACE
|
.It C-k SPACE
|
||||||
Toggle the mark.
|
Toggle the mark.
|
||||||
.It C-k d
|
.It C-k d
|
||||||
@@ -49,7 +51,7 @@ save the file, prompting for a filename if needed. Also C-k C-s.
|
|||||||
.It C-k x
|
.It C-k x
|
||||||
save the file and exit. Also C-k C-x.
|
save the file and exit. Also C-k C-x.
|
||||||
.It C-k y
|
.It C-k y
|
||||||
Yank the killring.
|
Yank the kill ring.
|
||||||
.It C-k \[char92]
|
.It C-k \[char92]
|
||||||
Dump core.
|
Dump core.
|
||||||
.El
|
.El
|
||||||
@@ -64,7 +66,7 @@ Incremental find.
|
|||||||
.It C-w
|
.It C-w
|
||||||
Kill the region if the mark is set.
|
Kill the region if the mark is set.
|
||||||
.It C-y
|
.It C-y
|
||||||
Yank the killring.
|
Yank the kill ring.
|
||||||
.It ESC BACKSPACE
|
.It ESC BACKSPACE
|
||||||
Delete the previous word.
|
Delete the previous word.
|
||||||
.It ESC b
|
.It ESC b
|
||||||
@@ -74,7 +76,7 @@ Delete the next word.
|
|||||||
.It ESC f
|
.It ESC f
|
||||||
Move to the next word.
|
Move to the next word.
|
||||||
.It ESC w
|
.It ESC w
|
||||||
Save the region (if the mark is set) to the killring.
|
Save the region (if the mark is set) to the kill ring.
|
||||||
.It
|
.It
|
||||||
.El
|
.El
|
||||||
.Sh FIND
|
.Sh FIND
|
||||||
|
|||||||
209
main.c
209
main.c
@@ -1566,11 +1566,12 @@ editor_prompt(char *prompt, void (*cb)(char *, int16_t))
|
|||||||
void
|
void
|
||||||
editor_find_callback(char *query, int16_t c)
|
editor_find_callback(char *query, int16_t c)
|
||||||
{
|
{
|
||||||
static int lmatch = -1;
|
static int lmatch = -1;
|
||||||
static int dir = 1;
|
static int dir = -1;
|
||||||
int i, current;
|
int i, current, traversed = 0;
|
||||||
char *match;
|
int qlen = strnlen(query, 128);
|
||||||
struct erow *row;
|
char *match;
|
||||||
|
struct erow *row;
|
||||||
|
|
||||||
if (c == '\r' || c == ESC_KEY || c == CTRL_KEY('g')) {
|
if (c == '\r' || c == ESC_KEY || c == CTRL_KEY('g')) {
|
||||||
/* reset search */
|
/* reset search */
|
||||||
@@ -1592,6 +1593,11 @@ editor_find_callback(char *query, int16_t c)
|
|||||||
current = lmatch;
|
current = lmatch;
|
||||||
|
|
||||||
for (i = 0; i < editor.nrows; i++) {
|
for (i = 0; i < editor.nrows; i++) {
|
||||||
|
traversed++;
|
||||||
|
if (traversed >= editor.nrows) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
current += dir;
|
current += dir;
|
||||||
if (current == -1) {
|
if (current == -1) {
|
||||||
current = editor.nrows - 1;
|
current = editor.nrows - 1;
|
||||||
@@ -1600,7 +1606,11 @@ editor_find_callback(char *query, int16_t c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
row = &editor.row[current];
|
row = &editor.row[current];
|
||||||
match = strstr(row->render, query);
|
if (row == NULL || row->size < qlen) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match = strnstr(row->render, query, row->size);
|
||||||
if (match) {
|
if (match) {
|
||||||
lmatch = current;
|
lmatch = current;
|
||||||
editor.cury = current;
|
editor.cury = current;
|
||||||
@@ -1903,100 +1913,107 @@ void
|
|||||||
process_kcommand(int16_t c)
|
process_kcommand(int16_t c)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ' ':
|
case BACKSPACE:
|
||||||
toggle_markset();
|
while (editor.curx > 0) {
|
||||||
break;
|
process_normal(BACKSPACE);
|
||||||
case 'q':
|
}
|
||||||
case CTRL_KEY('q'):
|
break;
|
||||||
if (editor.dirty && editor.dirtyex) {
|
case CTRL_KEY('\\'):
|
||||||
editor_set_status(
|
/* sometimes it's nice to dump core */
|
||||||
"File not saved - C-k q again to quit.");
|
disable_termraw();
|
||||||
editor.dirtyex = 0;
|
abort();
|
||||||
return;
|
case ' ':
|
||||||
}
|
toggle_markset();
|
||||||
exit(0);
|
break;
|
||||||
case CTRL_KEY('s'):
|
case 'c':
|
||||||
case 's':
|
len = editor.killring->size;
|
||||||
save_file();
|
killring_flush();
|
||||||
break;
|
editor_set_status("Kill ring cleared (%d characters)", len);
|
||||||
case CTRL_KEY('x'):
|
break;
|
||||||
case 'x':
|
case 'd':
|
||||||
exit(save_file());
|
if (editor.curx == 0 && cursor_at_eol()) {
|
||||||
case DEL_KEY:
|
|
||||||
case CTRL_KEY('d'):
|
|
||||||
delete_row(editor.cury);
|
delete_row(editor.cury);
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
if (editor.curx == 0 && cursor_at_eol()) {
|
|
||||||
delete_row(editor.cury);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((editor.row[editor.cury].size - editor.curx) >
|
|
||||||
0) {
|
|
||||||
process_normal(DEL_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'g':
|
|
||||||
goto_line();
|
|
||||||
break;
|
|
||||||
case BACKSPACE:
|
|
||||||
while (editor.curx > 0) {
|
|
||||||
process_normal(BACKSPACE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CTRL_KEY('\\'):
|
|
||||||
/* sometimes it's nice to dump core */
|
|
||||||
disable_termraw();
|
|
||||||
abort();
|
|
||||||
case 'e':
|
|
||||||
case CTRL_KEY('e'):
|
|
||||||
if (editor.dirty && editor.dirtyex) {
|
|
||||||
editor_set_status(
|
|
||||||
"File not saved - C-k e again to open a new file anyways.");
|
|
||||||
editor.dirtyex = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editor_openfile();
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
editor_find();
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
buf = get_cloc_code_lines(editor.filename);
|
|
||||||
|
|
||||||
editor_set_status("Lines of code: %s", buf);
|
|
||||||
free(buf);
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
if (system("make") != 0) {
|
|
||||||
editor_set_status(
|
|
||||||
"process failed: %s",
|
|
||||||
strerror(errno));
|
|
||||||
} else {
|
|
||||||
editor_set_status("make: ok");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
editor_set_status("undo: todo");
|
|
||||||
break;
|
|
||||||
case 'y':
|
|
||||||
killring_yank();
|
|
||||||
break;
|
|
||||||
case ESC_KEY:
|
|
||||||
case CTRL_KEY('g'):
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (isprint(c)) {
|
|
||||||
editor_set_status("unknown kcommand '%c'", c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
editor_set_status("unknown kcommand: %04x", c);
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((editor.row[editor.cury].size - editor.curx) >
|
||||||
|
0) {
|
||||||
|
process_normal(DEL_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DEL_KEY:
|
||||||
|
case CTRL_KEY('d'):
|
||||||
|
delete_row(editor.cury);
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
case CTRL_KEY('e'):
|
||||||
|
if (editor.dirty && editor.dirtyex) {
|
||||||
|
editor_set_status(
|
||||||
|
"File not saved - C-k e again to open a new file anyways.");
|
||||||
|
editor.dirtyex = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
editor_openfile();
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
editor_find();
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
goto_line();
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
buf = get_cloc_code_lines(editor.filename);
|
||||||
|
|
||||||
|
editor_set_status("Lines of code: %s", buf);
|
||||||
|
free(buf);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
if (system("make") != 0) {
|
||||||
|
editor_set_status(
|
||||||
|
"process failed: %s",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
editor_set_status("make: ok");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
case CTRL_KEY('q'):
|
||||||
|
if (editor.dirty && editor.dirtyex) {
|
||||||
|
editor_set_status(
|
||||||
|
"File not saved - C-k q again to quit.");
|
||||||
|
editor.dirtyex = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
case CTRL_KEY('s'):
|
||||||
|
case 's':
|
||||||
|
save_file();
|
||||||
|
break;
|
||||||
|
case CTRL_KEY('x'):
|
||||||
|
case 'x':
|
||||||
|
exit(save_file());
|
||||||
|
case 'u':
|
||||||
|
editor_set_status("undo: todo");
|
||||||
|
break;
|
||||||
|
case 'y':
|
||||||
|
killring_yank();
|
||||||
|
break;
|
||||||
|
case ESC_KEY:
|
||||||
|
case CTRL_KEY('g'):
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (isprint(c)) {
|
||||||
|
editor_set_status("unknown kcommand '%c'", c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor_set_status("unknown kcommand: %04x", c);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.dirtyex = 1;
|
editor.dirtyex = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user