This commit is contained in:
+1
-1
@@ -81,7 +81,7 @@
|
||||
(map-key "f" editor-open-file "user")
|
||||
(map-key "TAB" editor-insert-tab "no-prefix")
|
||||
(map-key "CTRL-s" buffer-find "no-prefix")
|
||||
(map-key "CTRL-r" editor-move-to-end-of-word "no-prefix")
|
||||
(map-key "CTRL-r" buffer-find-reverse "no-prefix")
|
||||
(map-key "ARROW-RIGHT" editor-switch-next-buffer "user")
|
||||
(map-key "\"" editor-split-screen-vertical "user")
|
||||
(map-key "o" editor-switch-next-pane "user")
|
||||
|
||||
+4
-1
@@ -13,7 +13,7 @@
|
||||
* @param filename Path to the file
|
||||
* @return Buffer ID on success, -1 on failure
|
||||
*/
|
||||
int bufferCreate(const char *filename);
|
||||
int bufferCreate(const char *filename, enum bufferStatus_e state);
|
||||
|
||||
/**
|
||||
* @brief Switches to a specific buffer by ID
|
||||
@@ -56,5 +56,8 @@ int bufferSave(void);
|
||||
int bufferSaveAll(void);
|
||||
|
||||
void bufferFind(struct buffer_t *buf);
|
||||
void bufferFindReverse(struct buffer_t* buf);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,7 @@ Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorSwitchNextBuffer(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp bufferFind_L(Lisp args, LispError *e, LispContext ctx);
|
||||
Lisp bufferFindReverse_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
|
||||
// Pane
|
||||
|
||||
@@ -33,14 +33,14 @@ int main(int argc, char *argv[]) {
|
||||
initEditor();
|
||||
if (argc >= 2) {
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
active->buffer_id = bufferCreate(argv[1]);
|
||||
active->buffer_id = bufferCreate(argv[1], READ_AND_WRITE);
|
||||
} else {
|
||||
strcat(splash_screen, getenv("HOME"));
|
||||
strcat(splash_screen, "/.beluga/assets/beluga.txt");
|
||||
|
||||
appDebug("splash : %s\n", splash_screen);
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
active->buffer_id = bufferCreate(splash_screen);
|
||||
active->buffer_id = bufferCreate(splash_screen, READ_ONLY);
|
||||
}
|
||||
free(splash_screen);
|
||||
|
||||
|
||||
+27
-4
@@ -58,7 +58,7 @@ struct buffer_t* bufferFindById(int buffer_id)
|
||||
* @param filename Path to the file
|
||||
* @return Buffer ID on success, -1 on failure
|
||||
*/
|
||||
int bufferCreate(const char* filename)
|
||||
int bufferCreate(const char* filename, enum bufferStatus_e state)
|
||||
{
|
||||
// Check if file is already open
|
||||
const int existing_id = bufferFindByFilename(filename);
|
||||
@@ -288,14 +288,37 @@ void bufferFind(struct buffer_t* buf)
|
||||
if (query == NULL)
|
||||
return;
|
||||
int i;
|
||||
for (i = active->cursor_y + 1; i < buf->numrows; i++)
|
||||
for (i = buf->y+1; i < buf->numrows; i++)
|
||||
{
|
||||
row_t* row = &buf->row[i];
|
||||
char* match = strstr(row->chars, query);
|
||||
if (match)
|
||||
{
|
||||
active->cursor_y = i;
|
||||
buf->y = buf->numrows;
|
||||
buf->y = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(query);
|
||||
}
|
||||
|
||||
void bufferFindReverse(struct buffer_t* buf)
|
||||
{
|
||||
appDebug("searching\n");
|
||||
char* query = editorPrompt("Reverse search: %s (ESC to cancel)", "", 0);
|
||||
EditorPane* active = splitScreenGetActivePane();
|
||||
|
||||
if (query == NULL)
|
||||
return;
|
||||
int i;
|
||||
if (!buf->y)
|
||||
return;
|
||||
for (i = buf->y - 1; i >= 0; i--)
|
||||
{
|
||||
row_t* row = &buf->row[i];
|
||||
char* match = strstr(row->chars, query);
|
||||
if (match)
|
||||
{
|
||||
buf->y = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-1
@@ -341,7 +341,7 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
|
||||
if (filename) {
|
||||
// editorOpen(filename);
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
active->buffer_id = bufferCreate(filename);
|
||||
active->buffer_id = bufferCreate(filename, READ_AND_WRITE);
|
||||
}
|
||||
free(filename);
|
||||
|
||||
@@ -434,6 +434,23 @@ Lisp bufferFind_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lisp function to search for text
|
||||
* @details Wrapper around editorFind() for use in Lisp keybindings.
|
||||
* @param args Lisp arguments (unused)
|
||||
* @param e Error pointer for Lisp error handling
|
||||
* @param ctx Lisp context
|
||||
* @return lisp_null()
|
||||
* @see editorFind()
|
||||
*/
|
||||
Lisp bufferFindReverse_L(Lisp args, LispError *e, LispContext ctx) {
|
||||
appDebug("LispFind\n");
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
bufferFindReverse(buffer);
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lisp function to read character at cursor
|
||||
* @details Returns the character at the current cursor position as a Lisp
|
||||
|
||||
@@ -36,6 +36,7 @@ void initBuiltins() {
|
||||
registerBuiltin("editor-insert-char", editorPrintC);
|
||||
registerBuiltin("add-package", addPackage);
|
||||
registerBuiltin("buffer-find", bufferFind_L);
|
||||
registerBuiltin("buffer-find-reverse", bufferFindReverse_L);
|
||||
registerBuiltin("editor-read-char", editorReadChar_L);
|
||||
registerBuiltin("add-prefix", editorPrefix);
|
||||
registerBuiltin("editor-set-prefix", editorSetPrefix);
|
||||
|
||||
@@ -77,6 +77,8 @@ void bufferRowInsertBytes(struct buffer_t *buffer, row_t *row, int at,
|
||||
* \param at Index of the char to delete
|
||||
* \param row Row on operation is made */
|
||||
void bufferRowDelByte(struct buffer_t *buffer, row_t *row, int at, int n) {
|
||||
if (buffer->state == READ_ONLY)
|
||||
return;
|
||||
if (at < 0 || at >= row->size)
|
||||
return;
|
||||
memmove(row->chars + at, row->chars + at + n, row->size - at - n);
|
||||
|
||||
Reference in New Issue
Block a user