minor fixups

This commit is contained in:
2025-11-25 16:18:34 -08:00
parent acde895fb7
commit 1a184b1a08
2 changed files with 118 additions and 99 deletions

8
ke.1
View File

@@ -26,6 +26,8 @@ k-command mode can be exited with ESC or C-g.
.Bl -tag -width xxxxxxxxxxxx -offset indent
.It C-k BACKSPACE
Delete from the cursor to the beginning of the line.
.It C-k c
Clear (flush) the kill ring.
.It C-k SPACE
Toggle the mark.
.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
save the file and exit. Also C-k C-x.
.It C-k y
Yank the killring.
Yank the kill ring.
.It C-k \[char92]
Dump core.
.El
@@ -64,7 +66,7 @@ Incremental find.
.It C-w
Kill the region if the mark is set.
.It C-y
Yank the killring.
Yank the kill ring.
.It ESC BACKSPACE
Delete the previous word.
.It ESC b
@@ -74,7 +76,7 @@ Delete the next word.
.It ESC f
Move to the next word.
.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
.El
.Sh FIND

135
main.c
View File

@@ -1567,8 +1567,9 @@ void
editor_find_callback(char *query, int16_t c)
{
static int lmatch = -1;
static int dir = 1;
int i, current;
static int dir = -1;
int i, current, traversed = 0;
int qlen = strnlen(query, 128);
char *match;
struct erow *row;
@@ -1592,6 +1593,11 @@ editor_find_callback(char *query, int16_t c)
current = lmatch;
for (i = 0; i < editor.nrows; i++) {
traversed++;
if (traversed >= editor.nrows) {
break;
}
current += dir;
if (current == -1) {
current = editor.nrows - 1;
@@ -1600,7 +1606,11 @@ editor_find_callback(char *query, int16_t c)
}
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) {
lmatch = current;
editor.cury = current;
@@ -1903,11 +1913,74 @@ void
process_kcommand(int16_t c)
{
char *buf = NULL;
int len = 0;
switch (c) {
case BACKSPACE:
while (editor.curx > 0) {
process_normal(BACKSPACE);
}
break;
case CTRL_KEY('\\'):
/* sometimes it's nice to dump core */
disable_termraw();
abort();
case ' ':
toggle_markset();
break;
case 'c':
len = editor.killring->size;
killring_flush();
editor_set_status("Kill ring cleared (%d characters)", len);
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 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) {
@@ -1924,62 +1997,6 @@ process_kcommand(int16_t c)
case CTRL_KEY('x'):
case 'x':
exit(save_file());
case DEL_KEY:
case CTRL_KEY('d'):
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;