Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You must also have a [supported editor (and their associated plugin if needed)](
* `micro`
* `nano`
* `neovim`
* `vi`
* `vim`

---
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
42 changes: 40 additions & 2 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.");
Expand Down