6 Commits

Author SHA1 Message Date
arthur 419e924650 Add search function
Build project / build (push) Has been cancelled
2025-11-03 16:45:23 +01:00
arthur 6a201b3ebc delete line macro
Build project / build (push) Has been cancelled
2025-11-03 16:05:25 +01:00
arthur 1d253e51ef Update README.md
Build project / build (push) Failing after 3m27s
2025-11-01 13:22:10 +01:00
Arthur Barraux 42f82e2e0d add packages
Build project / build (push) Has been cancelled
2025-11-01 13:03:07 +01:00
arthur fa32f4b177 Update src/init.c
Build project / build (push) Has been cancelled
2025-10-31 09:10:57 +01:00
arthur 65f997e964 Update install.sh
Build project / build (push) Has been cancelled
2025-10-31 09:09:20 +01:00
10 changed files with 94 additions and 11 deletions
+6 -2
View File
@@ -8,13 +8,17 @@ It's abviously only working for **Linux**.
You will only need **meson** and a **C compiler** to compile the editor. You will only need **meson** and a **C compiler** to compile the editor.
## Installation ## Installation
### From source
Here is the installation line for development version: Here is the installation line for development version:
```git clone https://homelinuxserver.ddns.net/git/arthur/beluga.git ~/.beluga && cd ~/.beluga && meson setup --reconfigure build && meson compile -C build``` ```git clone https://homelinuxserver.ddns.net/git/arthur/beluga.git ~/.beluga && cd ~/.beluga && meson setup build && meson compile -C build```
The executable file will be `build/beluga`. Feel free to add it to your path. The executable file will be `build/beluga`. Feel free to add it to your path.
### From installation script ( prefered )
Just clone the repo and execute the script `install.sh`. It will automatically add beluga to your path.
## Getting start ## Getting start
To open an existing file just type : To open an existing file just type :
+3 -3
View File
@@ -16,7 +16,7 @@
;; KEY MAPPING ;; KEY MAPPING
(map-key "CTRL-q" editor-quit) (map-key "CTRL-q" editor-quit)
(map-key "CTRL-s" editor-save) (map-key "CTRL-d" editor-save)
(map-key "ARROW-UP" '(move-cursor "up")) (map-key "ARROW-UP" '(move-cursor "up"))
(map-key "ARROW-DOWN" '(move-cursor "down")) (map-key "ARROW-DOWN" '(move-cursor "down"))
(map-key "ARROW-RIGHT" '(move-cursor "right")) (map-key "ARROW-RIGHT" '(move-cursor "right"))
@@ -29,6 +29,6 @@
(map-key "PAGE-UP" move-cursor-page-up) (map-key "PAGE-UP" move-cursor-page-up)
(map-key "PAGE-DOWN" move-cursor-page-down) (map-key "PAGE-DOWN" move-cursor-page-down)
(map-key "CTRL-o" editor-open-file) (map-key "CTRL-o" editor-open-file)
(map-key "CTRL-k" editor-del-row)
(map-key "CTRL-s" editor-find)
+6
View File
@@ -29,4 +29,10 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx);
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx); Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx);
Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx);
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx);
#endif #endif
+2
View File
@@ -17,4 +17,6 @@ void editorOpen(char *filename);
void editorSave(); void editorSave();
void editorFind();
#endif // FILE_IO_H_ #endif // FILE_IO_H_
+2
View File
@@ -10,6 +10,8 @@
int editorRowCxToRx(erow *row, int cursor_x); int editorRowCxToRx(erow *row, int cursor_x);
int editorRowRxToCx(erow *row, int rx);
void editorUpdateRow(erow *row); void editorUpdateRow(erow *row);
void editorInsertRow(int at, char *s, size_t len); void editorInsertRow(int at, char *s, size_t len);
+11 -3
View File
@@ -17,13 +17,21 @@ fi
echo "Create config files ..." echo "Create config files ..."
mkdir -pv ~/.beluga/ mkdir -pv ~/.beluga/
cp -rv ./assets/ ~/.beluga/ cp -rv ./assets/ ~/.beluga/
cp -rv ./config/ ~/.beluga/ mkdir -pv ~/.beluga/packages/
read -p "Do you want to replace your config file or keep it (init.lisp.bak) / (init.lisp.new) ? (Y/n)" confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
mv ~/.beluga/config/init.lisp ~/.beluga/config/init.lisp.bak
cp -rv ./config/init.lisp ~/.beluga/config/
else
cp -rv ./config/init.lisp ~/.beluga/config/init.lisp.new
fi
# Compile the project # Compile the project
echo "Start compilation ..." echo "Start compilation ..."
meson setup --reconfigure build/ meson setup build/
meson compile -C build/ meson compile -C build/
# Add to path # Add to path
+29 -2
View File
@@ -3,6 +3,7 @@
#include "../include/input.h" #include "../include/input.h"
#include "../include/file_io.h" #include "../include/file_io.h"
#include "../include/editor_op.h" #include "../include/editor_op.h"
#include "../include/row_op.h"
#include "../include/data.h" #include "../include/data.h"
#include <stdio.h> #include <stdio.h>
@@ -27,7 +28,6 @@ Lisp mapKey(Lisp args, LispError *e, LispContext ctx) {
} }
Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) { Lisp moveCursor(Lisp args, LispError *e, LispContext ctx) {
fprintf(stderr, "Cursor is moving\n");
const char *direction = lisp_string(lisp_car(args)); const char *direction = lisp_string(lisp_car(args));
switch (direction[0]) { switch (direction[0]) {
case 'u': case 'u':
@@ -134,8 +134,35 @@ Lisp editorOpenFile(Lisp args, LispError *e, LispContext ctx) {
Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) { Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx) {
char c = lisp_char(lisp_car(args)); char c = lisp_string(lisp_car(args))[0];
editorInsertChar(c); editorInsertChar(c);
return lisp_null(); return lisp_null();
} }
Lisp addPackage(Lisp args, LispError *e, LispContext ctx) {
const char *package_name = lisp_string(lisp_car(args));
char *package_dir = (char *) calloc(256, sizeof(char));
FILE *fd_package = NULL;
strcat(package_dir, getenv("HOME"));
strcat(package_dir, "/.beluga/packages/");
strcat(package_dir, package_name);
strcat(package_dir, "/init.lisp");
fd_package = fopen(package_dir, "r");
lisp_eval(lisp_read_file(fd_package, &E.ctx_error, E.ctx), &E.ctx_error,
E.ctx);
fclose(fd_package);
free(package_dir);
return lisp_null();
}
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx) {
editorDelRow(E.cursor_y);
return lisp_null();
}
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx) {
editorFind();
return lisp_null();
}
+18
View File
@@ -110,3 +110,21 @@ void editorSave() {
free(buf); free(buf);
editorSetStatusMessage("Can't save! I/O error: %s", strerror(errno)); editorSetStatusMessage("Can't save! I/O error: %s", strerror(errno));
} }
void editorFind() {
char *query = editorPrompt("Search: %s (ESC to cancel)");
if (query == NULL) return;
int i;
for (i = 0; i < E.numrows; i++) {
erow *row = &E.row[i];
char *match = strstr(row->render, query);
if (match) {
E.cursor_y = i;
E.cursor_x = editorRowRxToCx(row, match - row->render);
E.row_offset = E.numrows;
break;
}
}
free(query);
}
+5 -1
View File
@@ -31,10 +31,13 @@ void initBuiltins() {
registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown); registerBuiltin("MOVE-CURSOR-PAGE-DOWN", editorMoveCursorPageDown);
registerBuiltin("EDITOR-OPEN-FILE", editorOpenFile); registerBuiltin("EDITOR-OPEN-FILE", editorOpenFile);
registerBuiltin("EDITOR-INSERT-CHAR", editorPrintC); registerBuiltin("EDITOR-INSERT-CHAR", editorPrintC);
registerBuiltin("ADD-PACKAGE", addPackage);
registerBuiltin("EDITOR-DEL-ROW", editorDelRow_L);
registerBuiltin("EDITOR-FIND", editorFind_L);
} }
void initEditor() { void initEditor() {
char init_file_path[256]; char * init_file_path = (char *) calloc(256, sizeof(char));
E.cursor_x = 0; E.cursor_x = 0;
E.cursor_y = 0; E.cursor_y = 0;
E.rx = 0; E.rx = 0;
@@ -66,6 +69,7 @@ void initEditor() {
// Read config file // Read config file
E.ctx_data = lisp_read_file(E.fd_init_file, &E.ctx_error, E.ctx); E.ctx_data = lisp_read_file(E.fd_init_file, &E.ctx_error, E.ctx);
free(init_file_path);
if (E.ctx_error != LISP_ERROR_NONE) { if (E.ctx_error != LISP_ERROR_NONE) {
die("init failed"); die("init failed");
} }
+12
View File
@@ -18,6 +18,18 @@ int editorRowCxToRx(erow *row, int cursor_x) {
return render_x; return render_x;
} }
int editorRowRxToCx(erow *row, int rx) {
int cur_rx = 0;
int cx;
for (cx = 0; cx < row->size; cx++) {
if (row->chars[cx] == '\t')
cur_rx += (E.constantes.TAB_LENGTH - 1) - (cur_rx % E.constantes.TAB_LENGTH);
cur_rx++;
if (cur_rx > rx) return cx;
}
return cx;
}
/** /**
* \fn editorUpdateRow(erow *row) * \fn editorUpdateRow(erow *row)
* \brief Copy content of \p row in \p row->render. * \brief Copy content of \p row in \p row->render.