4 Commits

Author SHA1 Message Date
d1978a3b98 Code cleanups and editor fixups.
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
2025-11-24 10:54:48 -08:00
5ee8234ab7 Update the manpage.
Print the core dump k-command correctly.
2025-11-24 10:23:39 -08:00
f82d1f8831 move nix to nixos config 2025-11-24 10:22:48 -08:00
2019ec10ce local testing updates 2025-11-23 19:15:19 -08:00
6 changed files with 41 additions and 20 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
*.log *.log
build build
ke
*.txt

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
project(ke C) # Specify C language explicitly project(ke C) # Specify C language explicitly
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
set(KE_VERSION "1.1.0") set(KE_VERSION "1.0.12")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g") set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")

View File

@@ -8,10 +8,14 @@ CFLAGS += -fsanitize=address -fno-omit-frame-pointer
LDFLAGS := -fsanitize=address LDFLAGS := -fsanitize=address
all: $(TARGET) all: $(TARGET) test.txt
$(TARGET): main.c $(TARGET): main.c
$(CC) $(CFLAGS) -o $(TARGET) $(LDFLAGS) main.c $(CC) $(CFLAGS) -o $(TARGET) $(LDFLAGS) main.c
clean: clean:
rm -f $(TARGET) rm -f $(TARGET)
.PHONY: test.txt
test.txt:
cp test.txt.bak $@

2
ke.1
View File

@@ -42,7 +42,7 @@ exit the editor. Also C-k C-q.
save the file, prompting for a filename if needed. Also C-k C-s. 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 \ .It C-k \[char92]
Dump core. Dump core.
.El .El
.Sh FIND .Sh FIND

32
main.c
View File

@@ -120,7 +120,6 @@ void editor_set_status(const char *fmt, ...);
/* miscellaneous */ /* miscellaneous */
void die(const char *s); void die(const char *s);
int iswspace(const char c);
int get_winsz(int *rows, int *cols); int get_winsz(int *rows, int *cols);
void goto_line(void); void goto_line(void);
int cursor_at_eol(void); int cursor_at_eol(void);
@@ -469,11 +468,6 @@ die(const char *s)
} }
int
iswspace(const char c)
{
return isspace(c) || c == '\t';
}
/* /*
* get_winsz uses the TIOCGWINSZ to get the window size. * get_winsz uses the TIOCGWINSZ to get the window size.
@@ -540,15 +534,15 @@ find_next_word(void)
} }
if (isalnum(editor.row[editor.cury].line[editor.curx])) { if (isalnum(editor.row[editor.cury].line[editor.curx])) {
while (!iswspace(editor.row[editor.cury].line[editor.curx]) && !cursor_at_eol()) { while (!isspace(editor.row[editor.cury].line[editor.curx]) && !cursor_at_eol()) {
move_cursor(ARROW_RIGHT); move_cursor(ARROW_RIGHT);
} }
return; return;
} }
if (iswspace(editor.row[editor.cury].line[editor.curx])) { if (isspace(editor.row[editor.cury].line[editor.curx])) {
while (iswspace(editor.row[editor.cury].line[editor.curx])) { while (isspace(editor.row[editor.cury].line[editor.curx])) {
move_cursor(ARROW_RIGHT); move_cursor(ARROW_RIGHT);
} }
@@ -566,7 +560,7 @@ delete_next_word(void)
} }
if (isalnum(editor.row[editor.cury].line[editor.curx])) { if (isalnum(editor.row[editor.cury].line[editor.curx])) {
while (!iswspace(editor.row[editor.cury].line[editor.curx]) && !cursor_at_eol()) { while (!isspace(editor.row[editor.cury].line[editor.curx]) && !cursor_at_eol()) {
move_cursor(ARROW_RIGHT); move_cursor(ARROW_RIGHT);
deletech(); deletech();
} }
@@ -574,8 +568,8 @@ delete_next_word(void)
return; return;
} }
if (iswspace(editor.row[editor.cury].line[editor.curx])) { if (isspace(editor.row[editor.cury].line[editor.curx])) {
while (iswspace(editor.row[editor.cury].line[editor.curx])) { while (isspace(editor.row[editor.cury].line[editor.curx])) {
move_cursor(ARROW_RIGHT); move_cursor(ARROW_RIGHT);
deletech(); deletech();
} }
@@ -594,7 +588,7 @@ find_prev_word(void)
move_cursor(ARROW_LEFT); move_cursor(ARROW_LEFT);
while (cursor_at_eol() || iswspace(editor.row[editor.cury].line[editor.curx])) { while (cursor_at_eol() || isspace(editor.row[editor.cury].line[editor.curx])) {
if (editor.cury == 0 && editor.curx == 0) { if (editor.cury == 0 && editor.curx == 0) {
return; return;
} }
@@ -602,7 +596,7 @@ find_prev_word(void)
move_cursor(ARROW_LEFT); move_cursor(ARROW_LEFT);
} }
while (editor.curx > 0 && !iswspace(editor.row[editor.cury].line[editor.curx - 1])) { while (editor.curx > 0 && !isspace(editor.row[editor.cury].line[editor.curx - 1])) {
move_cursor(ARROW_LEFT); move_cursor(ARROW_LEFT);
} }
} }
@@ -620,7 +614,7 @@ delete_prev_word(void)
if (editor.curx == 0) { if (editor.curx == 0) {
deletech(); deletech();
} else { } else {
if (!iswspace(editor.row[editor.cury].line[editor.curx - 1])) { if (!isspace(editor.row[editor.cury].line[editor.curx - 1])) {
break; break;
} }
deletech(); deletech();
@@ -628,7 +622,7 @@ delete_prev_word(void)
} }
while (editor.curx > 0) { while (editor.curx > 0) {
if (iswspace(editor.row[editor.cury].line[editor.curx - 1])) { if (isspace(editor.row[editor.cury].line[editor.curx - 1])) {
break; break;
} }
deletech(); deletech();
@@ -1239,9 +1233,15 @@ process_kcommand(int16_t c)
delete_row(editor.cury); delete_row(editor.cury);
break; break;
case 'd': case 'd':
if (editor.curx == 0 && cursor_at_eol()) {
delete_row(editor.cury);
return;
}
while ((editor.row[editor.cury].size - editor.curx) > 0) { while ((editor.row[editor.cury].size - editor.curx) > 0) {
process_normal(DEL_KEY); process_normal(DEL_KEY);
} }
break; break;
case 'g': case 'g':
case CTRL_KEY('g'): case CTRL_KEY('g'):

15
test.txt.bak Normal file
View File

@@ -0,0 +1,15 @@
hello
world it is me
but I am not me