From 5aee1f540c9ee773f2643a8bff3170006e54c6c4 Mon Sep 17 00:00:00 2001 From: Tomas Rivera Date: Mon, 20 Apr 2026 18:41:32 +0200 Subject: [PATCH] Helix: added initial support --- README.md | 10 ++++++---- src/utils.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2f6ac01..eec4284 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ Before building NoteWrapper, you must install the following dependencies: * `ripgrep` * `fzf` -You must also have a [supported editor](#editor-support) installed: +You must also have a [supported editor (and their associated plugin if needed)](#editor-support) installed: +* `helix` * `nano` * `neovim` * `vim` @@ -139,8 +140,9 @@ The first two features depend on [Vivify's editor integration](https://github.co If your editor does not support these features, you can implement a plugin using [Vivify's API](https://github.com/jannis-baum/Vivify?tab=readme-ov-file#editor-support). -| Editor | Bufferless | Cursor | Jump to end | Plugin required | -| ------ | ---------- | ------ | ----------- | ------------------------------------------------------- | +| Editor | Bufferless | Cursor | Jump to end | Plugin required | +| ------ | ----------- | ------- | ------------ | --------------------------------------------------------| +| Helix | ❌ | ❌ | ✅ | — | | Nano | ❌ | ❌ | ✅ | — | | Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) | | Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) | @@ -200,5 +202,5 @@ It is recommended to use a browser different from your main one for rendering. * [ ] A converter between journal types * [ ] Support multiple vault directories -* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `helix`, `emacs -nw`, `micro`, `jed`, kakoune, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `nvi`, `dit`, `zile`, `moe`, `joe`) +* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `emacs -nw`, `micro`, `jed`, kakoune, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `nvi`, `dit`, `zile`, `moe`, `joe`) * [ ] Default to $EDITOR diff --git a/src/utils.c b/src/utils.c index 73449ae..3194bae 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,9 @@ #include "utils.h" +#include "string.h" #include -const char *supportedEditor[] = {"neovim", "vim", "nano"}; -const int numEditors = 3; +const char *supportedEditor[] = {"helix", "nano", "neovim", "vim"}; +const int numEditors = 4; int compareString(const void *a, const void *b) { const char *str1 = *(const char **)a; @@ -204,8 +205,9 @@ int doesEditorExist (char *editorToCheck, int shouldDebug) { // Some exectua char *editor; if (strcmp(editorToCheck, "neovim") == 0) { editor = strdup("nvim"); // we must use strdup and not just copy as we would have modified editorToOpen in main - } - else { + } else if (strcmp(editorToCheck, "helix") == 0) { + editor = strdup("hx"); + } else { editor = strdup(editorToCheck); } char *path_env = getenv("PATH"); @@ -338,6 +340,8 @@ int openEditor(char *path, char *editor, int render, int shouldJumpToEndOfFile, pid_t editor_pid = fork(); error(editor_pid < 0, "program", "fork() failed."); +// instead of reusing part of the codes, for any new editor copy an example and adapt it. This is in case we need a custom fix for an editor. + if (editor_pid == 0) { // ========================= // CHILD: launch editor @@ -406,6 +410,45 @@ if (editor_pid == 0) { execlp("nano", "nano", path, NULL); } + error(1, "program", "execlp() failed."); + } else if (strcmp(editor, "helix") == 0) { + + // If render enabled → spawn viv in parallel + if (render) { + debug("Running the editor..."); + pid_t viv_pid = fork(); + error(viv_pid < 0, "program", "fork() failed."); + + if (viv_pid == 0) { + // GRANDCHILD → viv + + + char viv_path[PATH_MAX]; + strncpy(viv_path, path, PATH_MAX - 1); + viv_path[PATH_MAX - 1] = '\0'; + + if (shouldJumpToEndOfFile) { + strncat(viv_path, ":99999", + PATH_MAX - strlen(viv_path) - 1); + } + + debug("Running viv %s", viv_path); + execlp("viv", "viv", viv_path, NULL); + error(1, "program", "execlp() failed."); + } + // IMPORTANT: do NOT wait for viv + } + + // Now run helix (this replaces the child process) + if (shouldJumpToEndOfFile) { + strncat(path, ":99999", PATH_MAX); + debug("Running hx %s", path); + execlp("hx", "hx", path, NULL); + } else { + debug("Running hx %s", path); + execlp("hx", "hx", path, NULL); + } + error(1, "program", "execlp() failed."); }