This commit is contained in:
@@ -124,5 +124,18 @@ Lisp editorMoveCursorPageDown(Lisp args, LispError* e, LispContext ctx) {
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
char *filename = editorPrompt("Path : %s");
|
||||
if (filename)
|
||||
editorOpen(filename);
|
||||
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) {
|
||||
char c = lisp_char(lisp_car(args));
|
||||
editorInsertChar(c);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -1,15 +1,16 @@
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/row_op.h"
|
||||
#include <stdio.h>
|
||||
#include "data.h"
|
||||
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
void editorInsertChar(int c) {
|
||||
if (E.cursor_y == E.numrows) {
|
||||
editorInsertRow(E.numrows, "", 0);
|
||||
}
|
||||
editorRowInsertChar(&E.row[E.cursor_y], E.cursor_x, c);
|
||||
E.cursor_x++;
|
||||
if (E.cursor_y == E.numrows) {
|
||||
editorInsertRow(E.numrows, "", 0);
|
||||
}
|
||||
editorRowInsertChar(&E.row[E.cursor_y], E.cursor_x, c);
|
||||
E.cursor_x++;
|
||||
}
|
||||
|
||||
void editorInsertNewLine() {
|
||||
|
||||
+22
-1
@@ -1,6 +1,7 @@
|
||||
#include "../include/file_io.h"
|
||||
#include "../include/input.h"
|
||||
#include "../include/output.h"
|
||||
#include "data.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -36,16 +37,36 @@ char *editorRowsToString(int *buffer_len) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
void editorCloseFile(void) {
|
||||
E.cursor_x = 0;
|
||||
E.cursor_y = 0;
|
||||
E.rx = 0;
|
||||
E.row_offset = 0;
|
||||
E.col_offset = 0;
|
||||
E.numrows = 0;
|
||||
E.row = NULL;
|
||||
E.dirty = 0;
|
||||
E.filename = NULL;
|
||||
E.status_msg[0] = '\0';
|
||||
E.status_msg_time = 0;
|
||||
|
||||
}
|
||||
|
||||
void editorOpen(char *filename) {
|
||||
FILE *fp;
|
||||
|
||||
// Test if a file is already open
|
||||
if (E.filename != NULL) {
|
||||
editorCloseFile();
|
||||
}
|
||||
|
||||
free(E.filename);
|
||||
E.filename = strdup(filename);
|
||||
|
||||
fp = fopen(filename, "a+");
|
||||
if (!fp)
|
||||
die("fopen");
|
||||
|
||||
|
||||
char *line = NULL;
|
||||
size_t line_cap = 0;
|
||||
ssize_t line_len;
|
||||
|
||||
@@ -29,6 +29,8 @@ void initBuiltins() {
|
||||
registerBuiltin("EDITOR-DELETE-PREVIOUS-CHAR", deletePreviousChar);
|
||||
registerBuiltin("MOVE-CURSOR-PAGE-UP", editorMoveCursorPageUp);
|
||||
registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown);
|
||||
registerBuiltin("EDITOR-OPEN-FILE", editorOpenFile);
|
||||
registerBuiltin("EDITOR-INSERT-CHAR", editorPrintC);
|
||||
}
|
||||
|
||||
void initEditor() {
|
||||
@@ -41,6 +43,7 @@ void initEditor() {
|
||||
E.row = NULL;
|
||||
E.dirty = 0;
|
||||
E.filename = NULL;
|
||||
E.state = READ_ONLY;
|
||||
E.status_msg[0] = '\0';
|
||||
E.status_msg_time = 0;
|
||||
if (getWindowSize(&E.screenrows, &E.screencols) == -1) {
|
||||
|
||||
@@ -102,6 +102,8 @@ void editorDelRow(int at) {
|
||||
* \param at Index of where we want to insert the char */
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, int c) {
|
||||
if (E.state == READ_ONLY)
|
||||
return;
|
||||
if (at < 0 || at > row->size) {
|
||||
at = row->size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user