diff --git a/README.md b/README.md index 413a09a..efb0079 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ You must also have a [supported editor (and their associated plugin if needed)]( * `micro` * `nano` * `neovim` +* `vi` * `vim` --- @@ -149,6 +150,7 @@ If your editor does not support these features, you can implement a plugin using | Micro | ❌ | ✅ | ✅ | [micro-vivify](https://codeberg.org/gibbert/micro-vivify) and [modifications to your `init.lua`](./docs/micro.md)| | Nano | ❌ | ❌ | ✅ | — | | Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) | +| Vi | ❌ | ❌ | ✅ | | | Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) | [How to add support for another editor](./CONTRIBUTING.md#adding-editor-support) @@ -206,5 +208,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: `emacs -nw`, `jed`, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `nvi`, `dit`, `zile`, `moe`, `joe`, `pico`, `vis`) +* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `emacs -nw`, `jed`, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `dit`, `zile`, `moe`, `joe`, `pico`, `vis`) * [ ] Default to $EDITOR diff --git a/src/utils.c b/src/utils.c index 9d82a0c..fd7836c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,8 +1,8 @@ #include "utils.h" #include "string.h" -const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vim"}; -const int numEditors = 6; +const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vi", "vim"}; +const int numEditors = 7; int compareString(const void *a, const void *b) { const char *str1 = *(const char **)a; @@ -522,7 +522,45 @@ if (editor_pid == 0) { } error(1, "program", "execlp() failed."); + // ---- VI ---- + } else if (strcmp(editor, "vi") == 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 vi (this replaces the child process) + if (shouldJumpToEndOfFile) { + debug("Running vi +:$ %s", path); + execlp("vi", "vi", "+:$", path, NULL); + } else { + debug("Running vi %s", path); + execlp("vi", "vi", path, NULL); + } + + error(1, "program", "execlp() failed."); // ---- UNKNOWN EDITOR ---- } else { error(1, "program", "Unknown editor.");