This commit is contained in:
+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);
|
||||
|
||||
+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 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';
|
||||
|
||||
Reference in New Issue
Block a user