mirror of
https://github.com/tomasriveral/NoteWrapper.git
synced 2026-08-12 02:18:38 +02:00
Merge (#6) from tomasriveral/vi. Adds vi support
Vi: added initial support
This commit is contained in:
@@ -47,6 +47,7 @@ You must also have a [supported editor (and their associated plugin if needed)](
|
|||||||
* `micro`
|
* `micro`
|
||||||
* `nano`
|
* `nano`
|
||||||
* `neovim`
|
* `neovim`
|
||||||
|
* `vi`
|
||||||
* `vim`
|
* `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)|
|
| Micro | ❌ | ✅ | ✅ | [micro-vivify](https://codeberg.org/gibbert/micro-vivify) and [modifications to your `init.lua`](./docs/micro.md)|
|
||||||
| Nano | ❌ | ❌ | ✅ | — |
|
| Nano | ❌ | ❌ | ✅ | — |
|
||||||
| Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
| Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||||
|
| Vi | ❌ | ❌ | ✅ | |
|
||||||
| Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
| Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||||
|
|
||||||
[How to add support for another editor](./CONTRIBUTING.md#adding-editor-support)
|
[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
|
* [ ] A converter between journal types
|
||||||
* [ ] Support multiple vault directories
|
* [ ] 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
|
* [ ] Default to $EDITOR
|
||||||
|
|||||||
+40
-2
@@ -1,8 +1,8 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vim"};
|
const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vi", "vim"};
|
||||||
const int numEditors = 6;
|
const int numEditors = 7;
|
||||||
|
|
||||||
int compareString(const void *a, const void *b) {
|
int compareString(const void *a, const void *b) {
|
||||||
const char *str1 = *(const char **)a;
|
const char *str1 = *(const char **)a;
|
||||||
@@ -522,7 +522,45 @@ if (editor_pid == 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
error(1, "program", "execlp() failed.");
|
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 ----
|
// ---- UNKNOWN EDITOR ----
|
||||||
} else {
|
} else {
|
||||||
error(1, "program", "Unknown editor.");
|
error(1, "program", "Unknown editor.");
|
||||||
|
|||||||
Reference in New Issue
Block a user