onivim / libvim Goto Github PK
View Code? Open in Web Editor NEWlibvim: The core Vim editing engine as a minimal C library
Home Page: https://v2.onivim.io
License: MIT License
libvim: The core Vim editing engine as a minimal C library
Home Page: https://v2.onivim.io
License: MIT License
Instructions: Replace the template text and remove irrelevant text (including this line)
Describe the bug
I tired to build this library with build/build-posix.sh on arch linux, only to find the generated headers has a bunch of errors in it.
The generated header files & static library can't be build to another program with the following commands because of the errors in it.
gcc -g -I./include test.c -o out -L./lib -lvim
To Reproduce
Expected behavior
No errors
Environment (please complete the following information):
Linux arch 5.13.9-arch1-1 #1 SMP PREEMPT Sun, 08 Aug 2021 11:25:35 +0000 x86_64 GNU/Linux
Can you give some advice how to compile libvim to WebAssembly? its mentioned in the README.md but I could not find any instructions how this is done.
I do not know the esy
tool very well, but I think I was able to build the library under linux using this script in src/build
(running it from src
):
# build in this folder
cur__install=my_build_wasm
# the lib folder is not created by the makefile for some reason -> created it manually
mkdir -p $cur__install/lib
emconfigure ./configure --disable-selinux CFLAGS=-fPIC
emmake make installlibvim DESTDIR=$cur__install
There were some failing checks though (not sure if this is the problem):
checking --with-tlib argument... empty: automatic terminal library selection
checking for tgetent in -ltinfo... no
checking for tgetent in -lncurses... no
checking for tgetent in -ltermlib... no
checking for tgetent in -ltermcap... no
checking for tgetent in -lcurses... no
no terminal library found
checking for tgetent()... configure: error: NOT FOUND!
You need to install a terminal library; for example ncurses.
Or specify the name of the library with --with-tlib.
Anyway I got a libvim.a
file and tried compiling this code:
#include <stdio.h>
#include "libvim.h"
void sayHello() {
printf("hello\n");
}
int main(int argc, char** argv) {
vimInit(argc, argv);
sayHello();
}
using this command:
emcc -Iinclude -Iinclude/proto -DHAVE_CONFIG_H -fPIC main.c lib/libvim.a -o index.html
But then I got this error:
wasm-ld: error: unknown file type: libvim.o
This works fine using gcc:
# after running the same build script but with configure/make instead of emconfigure/emmake
gcc -Iinclude -Iinclude/proto -DHAVE_CONFIG_H main.c lib/libvim.a -lSM -lICE -lXt -lX11 -lXdmcp -lm -ltinfo -lnsl -ldl
Any idea what could be wrong? Did you have success using this library with WebAssembly yet? If so it would be great if you could add some directions how.
Is your feature request related something that is currently hard to do? Please describe.
Conan is a dependency manager for c/c++, seeing as this is a custom library it's not exactly easy to find in most main stream package managers though(to my knowledge) is very good about allowing smaller packages into it's primary "repo", or creating a cmake-hunter build so that it can be consumed like that
Describe the solution you'd like
I'd prefer conan but something closer to resembling a traditional c/c++ build system would make the project easier to ingest into existing projects.
Describe alternatives you've considered
providing a more traditional build system(cmake/makefile/ninja) so that creating a git submodule and just integrating into an existing project is easier.
Additional context
Conan website: https://conan.io/
Hunter Git repo: https://github.com/cpp-pm/hunter
Describe the bug
If input is passed to vimInput
one character at a time a multi-character keybind (for example inoremap jk <esc>
) will fail. The first key will be swallowed up and the second will be inputted, without leaving insert mode.
To Reproduce
This test passes
diff --git a/src/apitest/insert_mode.c b/src/apitest/insert_mode.c
index bb87cfe01..ff8e3f68b 100644
--- a/src/apitest/insert_mode.c
+++ b/src/apitest/insert_mode.c
@@ -168,6 +168,19 @@ MU_TEST(insert_mode_ctrlv_newline)
mu_check(line[0] == 13);
}
+MU_TEST(insert_mode_exits_with_keybind)
+{
+ vimExecute("inoremap jk <esc>");
+ vimInput("i");
+ vimInput("jk");
+
+ mu_check((vimGetMode() & NORMAL) == NORMAL);
+
+ char_u *line = vimBufferGetLine(curbuf, vimCursorGetLine());
+ printf("LINE: %s\n", line);
+ mu_check(strcmp(line, "abc") == 0);
+}
+
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
@@ -182,6 +195,7 @@ MU_TEST_SUITE(test_suite)
MU_RUN_TEST(insert_mode_ctrlv);
MU_RUN_TEST(insert_mode_ctrlv_no_digit);
MU_RUN_TEST(insert_mode_ctrlv_newline);
+ MU_RUN_TEST(insert_mode_exits_with_keybind);
}
whereas this test fails
diff --git a/src/apitest/insert_mode.c b/src/apitest/insert_mode.c
index bb87cfe01..837cae897 100644
--- a/src/apitest/insert_mode.c
+++ b/src/apitest/insert_mode.c
@@ -168,6 +168,20 @@ MU_TEST(insert_mode_ctrlv_newline)
mu_check(line[0] == 13);
}
+MU_TEST(insert_mode_exits_with_keybind)
+{
+ vimExecute("inoremap jk <esc>");
+ vimInput("i");
+ vimInput("j");
+ vimInput("k");
+
+ mu_check((vimGetMode() & NORMAL) == NORMAL);
+
+ char_u *line = vimBufferGetLine(curbuf, vimCursorGetLine());
+ printf("LINE: %s\n", line);
+ mu_check(strcmp(line, "abc") == 0);
+}
+
MU_TEST_SUITE(test_suite)
{
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
@@ -182,6 +196,7 @@ MU_TEST_SUITE(test_suite)
MU_RUN_TEST(insert_mode_ctrlv);
MU_RUN_TEST(insert_mode_ctrlv_no_digit);
MU_RUN_TEST(insert_mode_ctrlv_newline);
+ MU_RUN_TEST(insert_mode_exits_with_keybind);
}
Expected behavior
Oni2 sends keystrokes one at a time to vimInput
. Because of this, the above behavior is blocking implementing Spacemacs-like keybindings. I would like to see this fixed here or for some other solution for spooling keypress before sending to vimInput
implemented on the Oni2 side.
Thank you for creating this library! I have used it to create a small tool that turns macOS input fields into vim
buffers: https://github.com/FelixKratz/SketchyVim and thought I would let you know.
Seems like one of neovim's original goals was to go from sync key handling to async key handling to improve performance. This takes a step back, back to sync handling.
Will this have the issues that Neovim solved (namely vim plugins that slow the user experience down, f.e. long wait times to process key press actions, especially movement actions), once we start adding various Vim plugins?
There's currently no way to inspect the command state, i.e. which keys have been punched in and what command is in the process of being built. Knowing this would be useful for a couple of features:
Displaying the current command state, which characters and what count, if any, has been entered, in case you get distracted in the middle of something and forget.
To provide contextual help. This will both reduce the need to memorize commands AND make it easier to learn them. For example, if g has been entered, the UI could display a list of possible characters to "complete" the command:
g - Go to top
t - Go to next tab
T - Go to previous tab
u - Convert to lowercase
U - Convert to uppercase
~ - Swap case
] - See all definitions
The command state, at least in normal mode, is stored in state_current->context->ca
, a cmdarg_T
. state_current->context
is a void*
and will point to different data structures depending on mode, but normal mode is mostly what I'm interested in here (or "Normal", "Visual" and "Operator" I guess, according to get_real_state()
).
A new function vimGetCommandState
could return either the entire cmdarg_T
struct, or a subset if that's easier to bind to from Reason. Or null if the stars aren't aligned.
Describe the bug
While in visual mode and in the middle of a search and replace, ie :s/foo/bar
, then cancel by pressing esc, then calling vimSearchGetHighlights
, vim can crash
To Reproduce
run this test (I added it to cmdline_search.c)
MU_TEST(test_get_search_highlights_during_visual)
{
int vim_num_search_highlights;
searchHighlight_T *vim_search_highlights;
vimInput("V");
vimKey("<down>");
vimKey("<down>");
vimInput(":s/vvvv");
vimKey("<esc>");
vimSearchGetHighlights(1, 3, &vim_num_search_highlights, &vim_search_highlights);
}
It will crash with this
-- START test_get_search_highlights_during_visual --
=================================================================
==297823==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b0000003b7 at pc 0x7fa720372917 bp 0x7ffd27057950 sp 0x7ffd270570f8
READ of size 1 at 0x60b0000003b7 thread T0
#0 0x7fa720372916 (/lib/x86_64-linux-gnu/libasan.so.5+0xd7916)
#1 0x55d3560c56f1 in vim_regcomp (/home/matt/dev/libvim/src/_esy/test/store/b/libvim-db9de2ae/apitest/cmdline_search.test.exe+0x986f1)
#2 0x55d3560d797f in search_regcomp (/home/matt/dev/libvim/src/_esy/test/store/b/libvim-db9de2ae/apitest/cmdline_search.test.exe+0xaa97f)
#3 0x55d3560d8665 in searchit (/home/matt/dev/libvim/src/_esy/test/store/b/libvim-db9de2ae/apitest/cmdline_search.test.exe+0xab665)
#4 0x55d356059917 in vimSearchGetHighlights (/home/matt/dev/libvim/src/_esy/test/store/b/libvim-db9de2ae/apitest/cmdline_search.test.exe+0x2c917)
#5 0x55d356057293 in test_get_search_highlights_during_visual apitest/cmdline_search.c:28
#6 0x55d356058742 in test_suite apitest/cmdline_search.c:119
#7 0x55d356058cbb in main apitest/cmdline_search.c:134
#8 0x7fa71f5b10b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#9 0x55d3560569ad in _start (/home/matt/dev/libvim/src/_esy/test/store/b/libvim-db9de2ae/apitest/cmdline_search.test.exe+0x299ad)
entire crash output here: https://gist.github.com/city41/ab6d14b3ffd3494e6e4f01e8b3dc5f66
Expected behavior
should not crash
Environment (please complete the following information):
(Really appreciate your work on this - really is a valuable library for anyone building a vim-like editor)
Most vim commands work as expected with vim.Execute(...). Looking through the code it looks like spellsuggest would be supported and that the sequence:
vimExecute("let sug = spellsuggest('hellllo')")
s = vimEval("string(sug)")
should bring back the suggestions in a stringified list. What I get is always an empty list.
I have tried to place the spelling and suggestion files in a variety of places and explicitly set the file locations via "set spell spelllang=...". Nothing has worked.
Is executing the spellsuggest command supported by libvim?
Is your feature request related something that is currently hard to do? Please describe.
vim contains very "generic" defines such as #define OK 1
. When using vim as a library, these defines can leak out to the rest of the app and cause some grief.
Describe the solution you'd like
I am unsure of a truly good solution. But maybe libvim.h
should not include vim.h
, which pulls in all of vim, but rather pull in a more strategic set of files?
Another possible solution is to namespace these defines, like #define VIM_OK 1
but can certainly understand why changing vim's code is not so great.
And of course, another solution is just ignore this problem. I suppose it depends on how far libvim gets used. If it really only ever powers Oni, then this might not matter.
Describe alternatives you've considered
I have used #undef
after #include
ing libvim.h, which patches the problem. But since I don't know what defines vim has made, I am unsure when/if this will bite me again in the future.
https://wiki.ubuntu.com/CosmicCuttlefish/ReleaseNotes
Do you have a preference as to what image to target instead?
Instructions: Replace the template text and remove irrelevant text (including this line)
Describe the bug
A clear and concise description of what the bug is.
(Issues related to the runtime files should be reported to their maintainer, check the file header.)
To Reproduce
Detailed steps to reproduce the behavior:
vim --clean
(or gvim --clean
, etc.)filename
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, copy/paste the text or add screenshots to help explain your problem.
Environment (please complete the following information):
vim --version
.)Additional context
Add any other context about the problem here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.