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