READ ONLY state for buffers
Build project / build (push) Successful in 36s

This commit is contained in:
2026-05-23 15:42:17 +02:00
parent 310498d582
commit c4d772e465
8 changed files with 58 additions and 11 deletions
+1 -1
View File
@@ -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
View File
@@ -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
+1
View File
@@ -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
+2 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
+1
View File
@@ -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);
+4 -2
View File
@@ -77,8 +77,10 @@ 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 (at < 0 || at >= row->size)
return;
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);
row->size -= n;
row->chars[row->size] = '\0';