Adding usefull keybinds
Build and Deploy Docs / build (push) Successful in 50s

This commit is contained in:
Arthur Barraux
2025-10-02 14:59:28 +02:00
parent 3b6c60a49e
commit 9157b94398
6 changed files with 78 additions and 20 deletions
-13
View File
@@ -1,13 +0,0 @@
(define TAB-LENGTH 2)
(define QUIT-TIMES 1)
(map-key "CTRL-q" editor-quit)
(map-key "CTRL-s" editor-save)
(map-key "ARROW-UP" '(move-cursor "up"))
(map-key "ARROW-DOWN" '(move-cursor "down"))
(map-key "ARROW-RIGHT" '(move-cursor "right"))
(map-key "ARROW-LEFT" '(move-cursor "left"))
(map-key "ENTER" editor-insert-new-line)
(map-key "CTRL-a" move-cursor-beg-line)
(map-key "CTRL-e" move-cursor-end-line)
+29
View File
@@ -0,0 +1,29 @@
(define TAB-LENGTH 2)
(define QUIT-TIMES 1)
(map-key "CTRL-q" editor-quit)
(map-key "CTRL-s" editor-save)
(define editor-delete-next-char (lambda () (
(move-cursor "right")
(editor-delete-previous-char)
)
)
)
(map-key "ARROW-UP" '(move-cursor "up"))
(map-key "ARROW-DOWN" '(move-cursor "down"))
(map-key "ARROW-RIGHT" '(move-cursor "right"))
(map-key "ARROW-LEFT" '(move-cursor "left"))
(map-key "ENTER" editor-insert-new-line)
(map-key "CTRL-a" move-cursor-beg-line)
(map-key "CTRL-e" move-cursor-end-line)
(map-key "BACKSPACE" editor-delete-previous-char)
(map-key "DEL" editor-delete-next-char)
(map-key "PAGE-UP" move-cursor-page-up)
(map-key "PAGE-DOWN" move-cursor-page-down)
; Key binds
+6
View File
@@ -19,4 +19,10 @@ Lisp moveCursorBeginLine(Lisp args, LispError *e, LispContext ctx);
Lisp moveCursorEndLine(Lisp args, LispError *e, LispContext ctx); Lisp moveCursorEndLine(Lisp args, LispError *e, LispContext ctx);
Lisp deletePreviousChar(Lisp args, LispError *e, LispContext ctx);
Lisp editorMoveCursorPageUp(Lisp args, LispError* e, LispContext ctx);
Lisp editorMoveCursorPageDown(Lisp args, LispError* e, LispContext ctx);
#endif #endif
+33
View File
@@ -5,6 +5,7 @@
#include "../include/editor_op.h" #include "../include/editor_op.h"
#include "../include/data.h" #include "../include/data.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -26,6 +27,7 @@ Lisp mapKey(Lisp args, LispError *e, LispContext ctx) {
} }
Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) { Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) {
fprintf(stderr, "Cursor is moving\n");
const char *direction = lisp_string(lisp_car(args)); const char *direction = lisp_string(lisp_car(args));
switch (direction[0]) { switch (direction[0]) {
case 'u': case 'u':
@@ -93,3 +95,34 @@ Lisp moveCursorEndLine(Lisp args, LispError* e, LispContext ctx) {
} }
return lisp_null(); return lisp_null();
} }
Lisp deletePreviousChar(Lisp args, LispError* e, LispContext ctx) {
editorDelChar();
return lisp_null();
}
Lisp editorMoveCursorPageUp(Lisp args, LispError* e, LispContext ctx) {
E.cursor_y = E.row_offset;
int times = E.screenrows;
while (--times) {
editorMoveCursor(ARROW_UP);
}
return lisp_null();
}
Lisp editorMoveCursorPageDown(Lisp args, LispError* e, LispContext ctx) {
E.cursor_y = E.row_offset + E.screenrows - 1;
if (E.cursor_y > E.numrows) {
E.cursor_y = E.numrows;
}
int times = E.screenrows;
while (--times) {
editorMoveCursor(ARROW_DOWN);
}
return lisp_null();
}
+4 -3
View File
@@ -26,8 +26,9 @@ void initBuiltins() {
registerBuiltin("EDITOR-INSERT-NEW-LINE", l_editorInsertNewLine); registerBuiltin("EDITOR-INSERT-NEW-LINE", l_editorInsertNewLine);
registerBuiltin("MOVE-CURSOR-BEG-LINE", moveCursorBeginLine); registerBuiltin("MOVE-CURSOR-BEG-LINE", moveCursorBeginLine);
registerBuiltin("MOVE-CURSOR-END-LINE", moveCursorEndLine); registerBuiltin("MOVE-CURSOR-END-LINE", moveCursorEndLine);
registerBuiltin("EDITOR-DELETE-PREVIOUS-CHAR", deletePreviousChar);
registerBuiltin("MOVE-CURSOR-PAGE-UP", editorMoveCursorPageUp);
registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown);
} }
void initEditor() { void initEditor() {
@@ -50,7 +51,7 @@ void initEditor() {
E.number_of_keybinds = 0; E.number_of_keybinds = 0;
E.fd_init_file = fopen("config/init.el", "r"); E.fd_init_file = fopen("config/init.lisp", "r");
E.ctx = lisp_init(); E.ctx = lisp_init();
E.env = lisp_env(E.ctx); E.env = lisp_env(E.ctx);
lisp_lib_load(E.ctx); lisp_lib_load(E.ctx);
+3 -1
View File
@@ -2,7 +2,6 @@
#include "../include/editor_op.h" #include "../include/editor_op.h"
#include "../include/output.h" #include "../include/output.h"
#include "../include/define.h" #include "../include/define.h"
#include "data.h"
#include <ctype.h> #include <ctype.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@@ -80,12 +79,15 @@ char *key_to_string(int key) {
break; break;
case PAGE_UP: case PAGE_UP:
strcpy(key_str, "PAGE-UP"); strcpy(key_str, "PAGE-UP");
fprintf(stderr, "pagr up\n");
break; break;
case PAGE_DOWN: case PAGE_DOWN:
strcpy(key_str, "PAGE-DOWN"); strcpy(key_str, "PAGE-DOWN");
break; break;
case DEL_KEY: case DEL_KEY:
fprintf(stderr, "delete key\n");
strcpy(key_str, "DEL"); strcpy(key_str, "DEL");
break; break;
case BACKSPACE: case BACKSPACE:
strcpy(key_str, "BACKSPACE"); strcpy(key_str, "BACKSPACE");