This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -19,4 +19,10 @@ Lisp moveCursorBeginLine(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
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/data.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -26,6 +27,7 @@ Lisp mapKey(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));
|
||||
switch (direction[0]) {
|
||||
case 'u':
|
||||
@@ -93,3 +95,34 @@ Lisp moveCursorEndLine(Lisp args, LispError* e, LispContext ctx) {
|
||||
}
|
||||
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
@@ -26,8 +26,9 @@ void initBuiltins() {
|
||||
registerBuiltin("EDITOR-INSERT-NEW-LINE", l_editorInsertNewLine);
|
||||
registerBuiltin("MOVE-CURSOR-BEG-LINE", moveCursorBeginLine);
|
||||
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() {
|
||||
@@ -50,7 +51,7 @@ void initEditor() {
|
||||
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.env = lisp_env(E.ctx);
|
||||
lisp_lib_load(E.ctx);
|
||||
|
||||
+3
-1
@@ -2,7 +2,6 @@
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/output.h"
|
||||
#include "../include/define.h"
|
||||
#include "data.h"
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -80,12 +79,15 @@ char *key_to_string(int key) {
|
||||
break;
|
||||
case PAGE_UP:
|
||||
strcpy(key_str, "PAGE-UP");
|
||||
fprintf(stderr, "pagr up\n");
|
||||
break;
|
||||
case PAGE_DOWN:
|
||||
strcpy(key_str, "PAGE-DOWN");
|
||||
break;
|
||||
case DEL_KEY:
|
||||
fprintf(stderr, "delete key\n");
|
||||
strcpy(key_str, "DEL");
|
||||
|
||||
break;
|
||||
case BACKSPACE:
|
||||
strcpy(key_str, "BACKSPACE");
|
||||
|
||||
Reference in New Issue
Block a user