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

2
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 .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

135
main.c
View File

@@ -1567,8 +1567,9 @@ 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;
int qlen = strnlen(query, 128);
char *match; char *match;
struct erow *row; struct erow *row;
@@ -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,11 +1913,74 @@ 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 BACKSPACE:
while (editor.curx > 0) {
process_normal(BACKSPACE);
}
break;
case CTRL_KEY('\\'):
/* sometimes it's nice to dump core */
disable_termraw();
abort();
case ' ': case ' ':
toggle_markset(); toggle_markset();
break; 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 'q':
case CTRL_KEY('q'): case CTRL_KEY('q'):
if (editor.dirty && editor.dirtyex) { if (editor.dirty && editor.dirtyex) {
@@ -1924,62 +1997,6 @@ process_kcommand(int16_t c)
case CTRL_KEY('x'): case CTRL_KEY('x'):
case 'x': case 'x':
exit(save_file()); 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': case 'u':
editor_set_status("undo: todo"); editor_set_status("undo: todo");
break; break;