Navigation Menu

Skip to content

Commit

Permalink
Reterm all viml -> vimscript
Browse files Browse the repository at this point in the history
  • Loading branch information
rktjmp committed Nov 4, 2021
1 parent c638077 commit 5846909
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 54 deletions.
40 changes: 20 additions & 20 deletions BUILD.md
Expand Up @@ -5,12 +5,12 @@ Lush Build
-- lush_build.lua
local colorscheme = require("zenbones")
run(colorscheme,
lush_to_viml,
lush_to_vimscript,
{overwrite, "colors/zenbones.vim"})
```

- [What is Lush Build](#what-is-lush-build)
- [Exporting a colorscheme to VimL](#exporting-a-colorscheme-to-viml)
- [Exporting a colorscheme to Vim Script](#exporting-a-colorscheme-to-vim-script)
- [Exporting a colorscheme to configurable Lua](#exporting-a-colorscheme-to-configurable-lua)
- [Converting a Lush colorscheme into an Alacritty colorscheme](#converting-a-lush-colorscheme-into-an-alacritty-colorscheme)
- [Branch transform](#branch-transform)
Expand All @@ -37,9 +37,9 @@ Transforms can take any additional number of arguments after the table.
Lush ships with some default transforms, which are automatically injected into
the build environment:

- `lush_to_viml`, head, convert parsed spec into viml
- `lush_to_vimscript`, head, convert parsed spec into vimscript
- `lush_to_lua`, head, convert parsed spec into lua
- `vim_compatible_viml`, tail, remove vim-incompatible values from highlight rules
- `vim_compatible_vimscript`, tail, remove vim-incompatible values from highlight rules
- `prepend`, tail, prepend one or more items to the given table
- `append`, tail, append one or more items to the given table
- `branch`, tail, pass a value through a pipeline but return the original value
Expand All @@ -62,15 +62,15 @@ We will discuss the simplest example, where you have a colorscheme with no
variations or configuration options and simply want to let non-lush users use
your colorscheme.

## Exporting a colorscheme to VimL
## Exporting a colorscheme to Vim Script

To ship our colorscheme as a viml file, we will need to:
To ship our colorscheme as a vimscript file, we will need to:

- load our colorscheme.
- convert it to viml.
- convert it to vimscript.
- save the output to a file.

We will use the `lush_to_viml` and `overwrite` transforms.
We will use the `lush_to_vimscript` and `overwrite` transforms.

Our build file would look something like this:

Expand All @@ -83,14 +83,14 @@ local colorscheme = require("my.lush.colorscheme")
-- any other arguments form the pipeline.
run(colorscheme,

-- now we will convert that colorscheme to a list of viml highlight commands
lush_to_viml,
-- now we will convert that colorscheme to a list of vimscript highlight commands
lush_to_vimscript,

-- we can pass the viml through a vim compatible transform if we want.
-- we can pass the vimscript through a vim compatible transform if we want.
-- note: this strips blending
-- vim_compatible_viml,
-- vim_compatible_vimscript,

-- the viml commands alone are generally not enough for a colorscheme, we
-- the vimscript commands alone are generally not enough for a colorscheme, we
-- will need to append a few housekeeping lines first.
--
-- note how we are passing arguments to append by wrapping the transform in a table.
Expand Down Expand Up @@ -253,7 +253,7 @@ Before running this build file, we should prepare the destination for `patchwrit
After running `:LushBuild`, we will have a `lush_apply` function.

By default, `lush_apply` will convert your colorscheme (now compiled as a
table) into viml highlight commands and apply them, but you can provide
table) into vimscript highlight commands and apply them, but you can provide
optional function hooks to `lush_apply` to alter data along the way.

The following hooks are provided:
Expand All @@ -265,7 +265,7 @@ The following hooks are provided:
- `generate_group_fn = function(group) .. end`
- Accepts a group and generate *something* that `apply` will understand.
- By default this is a `highlight ...` vim command but you could return other
viml, raw lua, different tables, etc.
vimscript, raw lua, different tables, etc.
- The results of this function is collected into a table of "rules", one per
group.
- `before_apply_fn = function(rules) ... end`
Expand Down Expand Up @@ -371,12 +371,12 @@ The branch transform allows you to split a pipeline into independant streams.

```lua
run(zenbones,
lush_to_viml,
lush_to_vimscript,
{branch,
vim_compatible_viml,
vim_compatible_vimscript,
{prepend, [["vim-compatible, see http://... for more details]]},
{patchwrite, "../dist/...", [[" M_OPEN]], [[" M_CLOSE]]}},
-- though vim_compatible_viml has altered the highlight rules, the original
-- though vim_compatible_vimscript has altered the highlight rules, the original
-- unmodified rules are passed to the rest of the pipeline.
{branch,
{patchwrite, "colors/", [[" M_OPEN]], [[" M_CLOSE]]}})
Expand Down Expand Up @@ -423,7 +423,7 @@ Every transform accepts and returns a table, this is implied in the
documentation, so "returns commands" means "returns a list of strings, where
each string is a command".

**`lusn_to_viml`**
**`lusn_to_vimscript`**

- Converts a parsed lush spec into highlight commands.
- Accepts
Expand All @@ -435,7 +435,7 @@ each string is a command".
- Accepts
- none

**`vim_compatible_viml`**
**`vim_compatible_vimscript`**

- Removes vim-incompatible attributes from highlight commands
- Accepts
Expand Down
4 changes: 2 additions & 2 deletions CREATE.md
Expand Up @@ -140,7 +140,7 @@ use '~/projects/cool_name'

Afterwards we can apply the colorscheme like any other:

```viml
```vimscript
colorscheme cool_name
```

Expand All @@ -150,7 +150,7 @@ Lush provides a highly extensible export system, called
[LushBuild](lush_build.md). It provides some built in tools to export your
colorscheme to:

- VimL (for use with Vim, or Neovim)
- Vim Script (for use with Vim, or Neovim)
- Lua, with extension hooks to provide end-user configuration
- Various terminal emulators

Expand Down
4 changes: 2 additions & 2 deletions EXTEND.md
Expand Up @@ -77,7 +77,7 @@ _G.customise_colorscheme = function()
end
```

```viml
```vimscript
autocmd VimEnter,ColorScheme * lua customise_colorscheme()
```

Expand Down Expand Up @@ -118,7 +118,7 @@ _G.customise_colorscheme = function()
end
```

```viml
```vimscript
autocmd VimEnter,ColorScheme * lua customise_colorscheme()
```

Expand Down
16 changes: 8 additions & 8 deletions FAQ.md
Expand Up @@ -99,24 +99,24 @@ Short answer: no.

Long answer:

There isn't a noticeable performance impact in using Lush over a raw VimL
There isn't a noticeable performance impact in using Lush over a raw Vim Script
colorscheme. The parse and compile stage is generally around 1ms on a quite
aged core i5 and is comparatively dwarfed by the 3ms spent waiting Vim's
interpreter to apply the commands, a penalty which raw VimL schemes would
interpreter to apply the commands, a penalty which raw Vim Script schemes would
share.

If you noticed a poor performance, you can always export your theme to
VimL after using Lush to aid the development process.
Vim Script after using Lush to aid the development process.

*Times measured with libuv's hrtime(), specifically around the parse, compile
and apply calls. There may be a few extra nanoseconds not recorded between
calling in and out of functions, as well as the initial file load time
(which VimL would also incur).*
(which Vim Script would also incur).*

```
Parse: 286300 ns 0.2863 ms -- resolve lush-spec into concrete values
Compile: 671900 ns 0.6719 ms -- convert concrete spec into viml commands
Apply: 3134300 ns 3.1343 ms -- pass to VimL interpreter (iterate array and call "nvim_command", "nvim_exec" performance is identical)
Compile: 671900 ns 0.6719 ms -- convert concrete spec into vimscript commands
Apply: 3134300 ns 3.1343 ms -- pass to Vim Script interpreter (iterate array and call "nvim_command", "nvim_exec" performance is identical)
Total: 4092500 ns 4.0925 ms
Parse: 373500 ns 0.3735 ms
Expand All @@ -136,7 +136,7 @@ Total: 4179300 ns 4.1793 ms
```

See also [issue #19](https://github.com/rktjmp/lush.nvim/issues/19), where
1000, 2000 and 4000 rule specs were tested. VimL is stll consistently the
1000, 2000 and 4000 rule specs were tested. Vim Script is stll consistently the
bottleneck.

Note that a 1000 rule spec is likely pretty unsual. There are only about 150
Expand All @@ -146,7 +146,7 @@ less).
A 4k rule spec would probably mean you're loading an enourmous number of
plugins, at which point your load times are probably also already enormous.

Also as per the issue, since VimL is such a huge bottleneck, you may find
Also as per the issue, since Vim Script is such a huge bottleneck, you may find
similarly sized colorschemes actually load *faster* via Lush because any maths
and manipulation is done via Lua instead.

Expand Down
10 changes: 5 additions & 5 deletions doc/lush.txt
Expand Up @@ -16,8 +16,8 @@ Lush is a color scheme creation aid, written in Lua, for Neovim.
Lush lets you define your scheme as a mini-dsl, provides HSL colour
manipulation aids, and gives you real time feedback of your changes.

Lush colorschemes can be exported to plain VimL for distribution (or escape),
and they can also be imported to other Lua (or VimL) files to access color)
Lush colorschemes can be exported to plain Vim Script for distribution (or escape),
and they can also be imported to other Lua (or Vim Script) files to access color)
data.

================================================================================
Expand Down Expand Up @@ -264,7 +264,7 @@ Here's a very simple lush-spec:
And the corresponding colorscheme loading file for nvim:
>
" cool_name/colors/cool_name.vim
" yes, unfortunately you still have to write some VimL
" yes, unfortunately you still have to write some Vim Script
set background=dark
let g:colors_name="cool_name"
" you could detect background == dark || light here and require
Expand Down Expand Up @@ -608,7 +608,7 @@ lush spec. See `lush/compiler/plugin/` for implementation details.

Lush ships with the following plugins:

- lush_core: always included, base viml generator
- lush_core: always included, base vimscript generator
>
local compiled = lush.compile(parsed, {plugins = {
require("my_compiler_plugin")
Expand Down Expand Up @@ -679,7 +679,7 @@ Live Search-Replace:
Lightline

While Lightline can be styled through Lush, real-time updating has some
caveats and performance may be less than optimal due to VimL performance.
caveats and performance may be less than optimal due to Vim Script performance.

See `examples/lightline-one-file` and `examples/lightline-two-files` for
guidance. Generally, if real time performance with Lightline is problematic,
Expand Down
4 changes: 2 additions & 2 deletions lua/lush/builder.lua
Expand Up @@ -52,9 +52,9 @@ local function make_env()
local env = {
lush = require("lush"),
run = require("lush.builder").run,
lush_to_viml = require("lush.transform.lush_to_viml"),
lush_to_vimscript = require("lush.transform.lush_to_vimscript"),
lush_to_lua = require("lush.transform.lush_to_lua"),
vim_compatible_viml = require("lush.transform.vim_compatible_viml"),
vim_compatible_vimscript = require("lush.transform.vim_compatible_vimscript"),
branch = require("lush.transform.branch"),
overwrite = require("lush.transform.overwrite"),
patchwrite = require("lush.transform.patchwrite"),
Expand Down
4 changes: 2 additions & 2 deletions lua/lush/transform/lush_to_lua.lua
Expand Up @@ -46,7 +46,7 @@ local lush_apply = function(groups, opts)
-- group.data (table of fg, bg, gui, sp and blend)). Should return something
-- which apply() knows how to handle.
--
-- By default we generate a viml highlight rule.
-- By default we generate a vimscript highlight rule.
local generate_group = options.generate_group_fn or
function(group)
if group.type == "link" then
Expand Down Expand Up @@ -80,7 +80,7 @@ local lush_apply = function(groups, opts)
-- Accepts a list of each group's result from generate_group_fn. Should
-- return something apply_fn can understand.
--
-- By default, generate_group_fn returns a viml "highlight ..." command and
-- By default, generate_group_fn returns a vimscript "highlight ..." command and
-- apply_fn assumes it's recieving a list of commands to pass to vim.cmd, but
-- you could for example, return a table of functions here and the apply_fn
-- could call those functions.
Expand Down
Expand Up @@ -19,7 +19,7 @@ end

return function(ast, config)
assert(is_spec(ast),
"first argument to viml transform must be a parsed lush spec")
"first argument to vimscript transform must be a parsed lush spec")

local rules = compiler(ast, config)

Expand Down
@@ -1,4 +1,4 @@
--- Alters a list of viml highlight commands to be vim compatible
--- Alters a list of vim script highlight commands to be vim compatible
return function(rules)
local collect = {}
for _, rule in ipairs(rules) do
Expand Down
4 changes: 2 additions & 2 deletions spec/build/build_file.lua
Expand Up @@ -4,8 +4,8 @@ assert(type(run) == "function")
assert(type(branch) == "function")
assert(type(overwrite) == "function")
assert(type(patchwrite) == "function")
assert(type(lush_to_viml) == "function")
assert(type(vim_compatible_viml) == "function")
assert(type(lush_to_vimscript) == "function")
assert(type(vim_compatible_vimscript) == "function")
assert(type(lush_to_lua) == "function")
assert(type(prepend) == "function")
assert(type(append) == "function")
Expand Down
18 changes: 9 additions & 9 deletions spec/transform/viml_spec.moon
@@ -1,4 +1,4 @@
describe "run.viml", ->
describe "run.vimscript", ->
run = require("lush.builder").run

setup ->
Expand All @@ -17,29 +17,29 @@ describe "run.viml", ->
teardown ->
package.loaded["theme"] = nil

it "returns viml", ->
viml = require("lush.transform.lush_to_viml")
value = run(require("theme"), viml)
it "returns vimscript", ->
vimscript = require("lush.transform.lush_to_vimscript")
value = run(require("theme"), vimscript)
assert.is.table(value)
assert.matches("highlight A guifg=NONE guibg=NONE guisp=NONE gui=italic blend=40", value[1])

it "orders the viml", ->
viml = require("lush.transform.lush_to_viml")
it "orders the vimscript", ->
vimscript = require("lush.transform.lush_to_vimscript")
parse = require('lush.parser')
ast = parse -> {
Apple { gui: "italic", blend: 40 }, -- first
Bananna { gui: "italic", blend: 40 }, -- after apple and links
Cat { Apple } -- link, so after apple, after bandana
Bandana { Apple } -- link, so after apple
}
value = run(ast, viml)
value = run(ast, vimscript)
assert.match("highlight Apple", value[1])
assert.match("link Bandana Apple", value[2])
assert.match("link Cat Apple", value[3])
assert.match("highlight Bananna", value[4])

-- it "accepts options", ->
-- viml = require("lush.transform.viml")
-- value = run(require("theme"), {viml, {plugins: require("lush.compiler.plugin.vim_compatible")}})
-- vimscript = require("lush.transform.vimscript")
-- value = run(require("theme"), {vimscript, {plugins: require("lush.compiler.plugin.vim_compatible")}})
-- assert.is.table(value)
-- assert.matches("highlight A guifg=NONE guibg=NONE guisp=NONE gui=italic blend=40", value[1])

0 comments on commit 5846909

Please sign in to comment.