Adding splitting screen and buffer switching
This commit is contained in:
+78
-23
@@ -12,6 +12,8 @@
|
||||
#include "../include/file_io.h"
|
||||
#include "../include/input.h"
|
||||
#include "../include/row_op.h"
|
||||
#include "../include/buffer.h"
|
||||
#include "../include/split_screen.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -115,18 +117,25 @@ Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @note Updates global editor state E
|
||||
*/
|
||||
void free_structs(void) {
|
||||
int i;
|
||||
int i, j;
|
||||
free(E.prefix);
|
||||
for (i = 0; i < E.number_of_keybinds; ++i) {
|
||||
free(E.key_binds[i].key_sequence);
|
||||
}
|
||||
free(E.key_binds);
|
||||
free(E.filename);
|
||||
for (i = 0; i < E.numrows; ++i) {
|
||||
free(E.row[i].render);
|
||||
free(E.row[i].chars);
|
||||
// free layout
|
||||
free(E.layout.panes);
|
||||
|
||||
// Free buffers
|
||||
for (i = 0; i < E.number_of_buffer; ++i) {
|
||||
free(E.buffers[i].filename);
|
||||
for (j = 0; j < E.buffers[i].numrows; ++j) {
|
||||
free(E.buffers[i].row[j].render);
|
||||
free(E.buffers[i].row[j].chars);
|
||||
}
|
||||
free(E.buffers[i].row);
|
||||
}
|
||||
free(E.row);
|
||||
|
||||
free(E.init_file_path);
|
||||
fclose(E.fd_init_file);
|
||||
|
||||
@@ -170,6 +179,16 @@ Lisp editorQuit(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @return lisp_null()
|
||||
* @see editorSave()
|
||||
*/
|
||||
|
||||
Lisp l_editorSplitScreenVertical(Lisp args, LispError *e, LispContext ctx) {
|
||||
if (E.number_of_buffer >= 2) {
|
||||
splitScreenVertical(E.buffers[0].buffer_id, E.buffers[1].buffer_id);
|
||||
} else {
|
||||
editorSetStatusMessage("Need at least 2 buffers open");
|
||||
}
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp l_editorSave(Lisp args, LispError *e, LispContext ctx) {
|
||||
|
||||
editorSave();
|
||||
@@ -188,7 +207,7 @@ Lisp l_editorSave(Lisp args, LispError *e, LispContext ctx) {
|
||||
*/
|
||||
Lisp l_editorInsertNewLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
|
||||
editorInsertNewLine();
|
||||
bufferInsertNewLine();
|
||||
|
||||
return lisp_null();
|
||||
}
|
||||
@@ -205,7 +224,7 @@ Lisp l_editorInsertNewLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
Lisp l_editorInserTab(Lisp args, LispError *e, LispContext ctx) {
|
||||
|
||||
for (int i = 0; i<E.constantes.TAB_LENGTH; ++i) {
|
||||
editorInsertChar(' ');
|
||||
bufferInsertChar(' ');
|
||||
}
|
||||
|
||||
return lisp_null();
|
||||
@@ -221,7 +240,7 @@ Lisp l_editorInserTab(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @note Updates global editor state E
|
||||
*/
|
||||
Lisp moveCursorBeginLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
E.cursor_x = 0;
|
||||
E.layout.panes[E.layout.active_pane].cursor_x = 0;
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
@@ -235,8 +254,10 @@ Lisp moveCursorBeginLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @note Updates global editor state E
|
||||
*/
|
||||
Lisp moveCursorEndLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
if (E.cursor_y < E.numrows) {
|
||||
E.cursor_x = E.row[E.cursor_y].size;
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buf = bufferFindById(active->buffer_id);
|
||||
if (active->cursor_y < buf->numrows) {
|
||||
active->cursor_x = buf->row[active->cursor_y].size;
|
||||
}
|
||||
return lisp_null();
|
||||
}
|
||||
@@ -251,7 +272,7 @@ Lisp moveCursorEndLine(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @see editorDelChar()
|
||||
*/
|
||||
Lisp deletePreviousChar(Lisp args, LispError *e, LispContext ctx) {
|
||||
editorDelChar();
|
||||
bufferDelChar();
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
@@ -266,7 +287,8 @@ Lisp deletePreviousChar(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @see editorMoveCursor()
|
||||
*/
|
||||
Lisp editorMoveCursorPageUp(Lisp args, LispError *e, LispContext ctx) {
|
||||
E.cursor_y = E.row_offset;
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
active->cursor_y = active->row_offset;
|
||||
int times = E.screenrows;
|
||||
while (--times) {
|
||||
editorMoveCursor(ARROW_UP);
|
||||
@@ -285,9 +307,11 @@ Lisp editorMoveCursorPageUp(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @see editorMoveCursor()
|
||||
*/
|
||||
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;
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
active->cursor_y = active->row_offset + E.screenrows - 1;
|
||||
if (active->cursor_y > buffer->numrows) {
|
||||
active->cursor_y = buffer->numrows;
|
||||
}
|
||||
int times = E.screenrows;
|
||||
while (--times) {
|
||||
@@ -311,7 +335,9 @@ Lisp editorMoveCursorPageDown(Lisp args, LispError *e, LispContext ctx) {
|
||||
Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
char *filename = editorPrompt("Open : %s", getenv("PWD"), 1);
|
||||
if (filename){
|
||||
editorOpen(filename);
|
||||
// editorOpen(filename);
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
active->buffer_id = bufferCreate(filename);
|
||||
}
|
||||
free(filename);
|
||||
|
||||
@@ -330,7 +356,7 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
*/
|
||||
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) {
|
||||
char c = lisp_string(lisp_car(args))[0];
|
||||
editorInsertChar(c);
|
||||
bufferInsertChar(c);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
@@ -375,7 +401,32 @@ Lisp addPackage(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @see editorDelRow()
|
||||
*/
|
||||
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
editorDelRow(E.cursor_y);
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
bufferDelRow(buffer, active->cursor_y);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorSwitchNextBuffer(Lisp args, LispError *e, LispContext ctx) {
|
||||
fprintf(stderr, "switch buffer\n");
|
||||
if (E.number_of_buffer > 0) {
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
int next_idx = (active->buffer_id + 1) % E.number_of_buffer;
|
||||
active->buffer_id = next_idx;
|
||||
}
|
||||
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorSwitchNextPane(Lisp args, LispError *e, LispContext ctx) {
|
||||
splitScreenSwitchPane();
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
Lisp editorUnifiedPanes(Lisp args, LispError *e, LispContext ctx) {
|
||||
if (E.layout.num_panes - 1) {
|
||||
splitScreenUnify();
|
||||
}
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
@@ -388,9 +439,11 @@ Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
* @return lisp_null()
|
||||
* @see editorFind()
|
||||
*/
|
||||
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
Lisp bufferFind_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
fprintf(stderr, "LispFind\n");
|
||||
editorFind();
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
bufferFind(buffer);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
@@ -405,11 +458,13 @@ Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
*/
|
||||
Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
Lisp returned_char;
|
||||
if (E.row[E.cursor_y].render[E.cursor_x] == 0) {
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
if (buffer->row[active->cursor_y].render[active->cursor_x] == 0) {
|
||||
returned_char = lisp_make_char('a');
|
||||
} else {
|
||||
|
||||
returned_char = lisp_make_char(E.row[E.cursor_y].render[E.cursor_x]);
|
||||
returned_char = lisp_make_char(buffer->row[active->cursor_y].render[active->cursor_x]);
|
||||
}
|
||||
return returned_char;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user