Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Extensions Design #11

Open
coolwanglu opened this issue Dec 15, 2013 · 3 comments
Open

Extensions Design #11

coolwanglu opened this issue Dec 15, 2013 · 3 comments

Comments

@coolwanglu
Copy link
Owner

This is only a draft, any ideas are welcome.

Motivation

Seems that lots of people are expecting web integrations in vim.js, indeed it might be a good combination for lots of different services, but they might not be necessary for all the users.

A better solution might be to expose enough interface such that people can write and enable only the extensions they need. somewhat like vundle.

Run JavaScript inside Vim.js

Vim script is powerful and widely used, but may be it's too large/slow on vim.js. But sometimes Vim script does not make sense as we have a native JS engine behind it, and javascript is more powerful.

The easiest way of implementation is to hijack :!, it makes sense, easy to use and implement. It's my preferred way, but maybe it will be conflict with existing plugins (suppose that vim script is supported in the future) due to the semantic meaning. But anyway there's no shell (so far) in emscripten and :! won't work anyway...

Otherwise we need to define a new command other than :!, which requires further modification to the original Vim, and I'm kind of against it.

Common functions can be defined inside the vimjs JS Object.

Load external JavaScript

:!vimjs.load_js(url) looks like a good choice

Interaction with Vim.js through JS

To actually access the buffer and other internal structures.

Need lots of work to do, or maybe to enable Vim script instead ... Not sure right now.

File System Extensions

Seems to be popularly demanded, which are fortunately not hard to implement. As long as js can be executed inside vim.js, people can mount different FS using emscripten FS API

Relative libraries:

  • BrowserFS
  • dropbox-js

Async Function Calls

Sometimes only async functions are available (e.g. setTimeout), such that you cannot block the current execution until some condition is met.

Fortunately Vim.js allows you suspend and resume it, such that you can simulate a blocking operation, which actually blocks Vim.js but does not freeze your browser. An extra callback will be provided to resume Vim.js.

Need to work out a new syntax other than :!, as :! should be reserved as a handy to for sync calls.

@jordwalke
Copy link

This sounds really great. VimScript is terrible and nobody understands it. The ability to write JS plugins is one of the reasons I'm really excited about vim.js. You could even imagine that rewriting some of the more expensive/common plugins in JS, and then the only thing not in JS is the Vim core which has been compiled through emscripten (which might actually result in usable performance for serious work - enough so that Vim.js provides a full editing experience).

I would suggest encouraging web workers for expensive JS tasks. (Or at least a web worker compatible API so that you don't rely on being in the DOM).

@tecfu
Copy link

tecfu commented Mar 31, 2015

+1

@jordwalke
Copy link

Making an async API ensures that plugin authors must write nonblocking plugins which would help responsiveness while typing and allow running them in a web worker. Then, these plugins could even be compiled into python code (https://github.com/PiotrDabkowski/Js2Py) or used directly via pyv8 and ran in the standard (non-js) Vim with python enabled. <mind-blown />

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants