From c06c820dfb1bd42f057c47bbf762a199e8d647d3 Mon Sep 17 00:00:00 2001 From: arthur Date: Fri, 7 Nov 2025 16:23:56 +0100 Subject: [PATCH] Patch path complete and read char lisp function --- include/builtins.h | 2 ++ src/builtins.c | 6 ++++++ src/init.c | 1 + src/input.c | 9 +++++++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/builtins.h b/include/builtins.h index 2f1670f..4c5b3ff 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -35,4 +35,6 @@ Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx); Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx); +Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx); + #endif diff --git a/src/builtins.c b/src/builtins.c index 7d930ed..0a1c7a5 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -166,3 +166,9 @@ Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx) { editorFind(); return lisp_null(); } + +Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx) { + fprintf(stderr, "char read : %c\n", E.row[E.cursor_y].render[E.cursor_x]); + return lisp_make_char(E.row[E.cursor_y].render[E.cursor_x]); +} + diff --git a/src/init.c b/src/init.c index f9860ba..00df766 100644 --- a/src/init.c +++ b/src/init.c @@ -34,6 +34,7 @@ void initBuiltins() { registerBuiltin("ADD-PACKAGE", addPackage); registerBuiltin("EDITOR-DEL-ROW", editorDelRow_L); registerBuiltin("EDITOR-FIND", editorFind_L); + registerBuiltin("EDITOR-READ-CHAR", editorReadChar_L); } void initEditor() { diff --git a/src/input.c b/src/input.c index 808c72c..b1bdbca 100644 --- a/src/input.c +++ b/src/input.c @@ -18,7 +18,11 @@ char * file_completion(const char *path) { struct dirent *entry; char directory[128]; char predict[128]; - size_t predict_len; + int predict_len = 0; + + if (path[strlen(path) - 1] == '/') { + return path; + } // Find dir name char * last_slash = strrchr(path, '/'); @@ -28,12 +32,13 @@ char * file_completion(const char *path) { predict_len = strlen(path) - dir_len - 1; strncpy(predict, last_slash + 1, predict_len); directory[dir_len] = '\0'; - fprintf(stderr, "%s %s\n", directory, predict); predict[predict_len] = '\0'; + fprintf(stderr, "%s %s\n", directory, predict); } else { return NULL; } + dir = opendir(directory); if (!dir) return NULL;