mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 20:20:05 +08:00
Add lua stdin support (#2544)
This commit is contained in:
parent
c58216441a
commit
dc899187c3
@ -37,9 +37,17 @@ function! SpaceVim#layers#lang#lua#config() abort
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('lua', function('s:language_specified_mappings'))
|
||||
let luaexe = filter(['lua53', 'lua52', 'lua51'], 'executable(v:val)')
|
||||
if !empty(luaexe)
|
||||
call SpaceVim#plugins#runner#reg_runner('lua', luaexe[0] . ' %s')
|
||||
call SpaceVim#plugins#runner#reg_runner('lua', {
|
||||
\ 'exe' : luaexe[0],
|
||||
\ 'opt' : ['-'],
|
||||
\ 'usestdin' : 1,
|
||||
\ })
|
||||
else
|
||||
call SpaceVim#plugins#runner#reg_runner('lua', 'lua %s')
|
||||
call SpaceVim#plugins#runner#reg_runner('lua', {
|
||||
\ 'exe' : 'lua',
|
||||
\ 'opt' : ['-'],
|
||||
\ 'usestdin' : 1,
|
||||
\ })
|
||||
endif
|
||||
let g:neomake_lua_enabled_makers = ['luac']
|
||||
let luacexe = filter(['luac53', 'luac52', 'luac51'], 'executable(v:val)')
|
||||
@ -62,9 +70,9 @@ function! SpaceVim#layers#lang#lua#config() abort
|
||||
if executable('luap')
|
||||
call SpaceVim#plugins#repl#reg('lua', 'luap')
|
||||
elseif !empty(luaexe)
|
||||
call SpaceVim#plugins#repl#reg('lua', luaexe)
|
||||
call SpaceVim#plugins#repl#reg('lua', luaexe + ['-i'])
|
||||
else
|
||||
call SpaceVim#plugins#repl#reg('lua', 'lua')
|
||||
call SpaceVim#plugins#repl#reg('lua', ['lua', '-i'])
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
@ -22,6 +22,7 @@ Each of the following sections will be covered:
|
||||
- [Jump to test file](#jump-to-test-file)
|
||||
- [running code](#running-code)
|
||||
- [Code formatting](#code-formatting)
|
||||
- [REPL support](#repl-support)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -80,3 +81,11 @@ Before using this feature, please install luaformatter.
|
||||
```sh
|
||||
luarocks install formatter
|
||||
```
|
||||
|
||||
### REPL support
|
||||
|
||||
Start a `lua -i` inferior REPL process with `SPC l s i`. After the REPL process has been started. you can
|
||||
send code to inferior process, all key bindings are begin with `SPC l s` prefix, including sending line, sending selection or even
|
||||
send whole buffer.
|
||||
|
||||
![luarepl](https://user-images.githubusercontent.com/13142418/52158892-075f7a80-26d8-11e9-9bf2-2be8ab2363ab.gif)
|
||||
|
@ -24,6 +24,7 @@ SpaceVim 是一个模块化的 Vim IDE,针对 lua 这一语言的支持主要
|
||||
- [工程文件跳转](#工程文件跳转)
|
||||
- [快速运行](#快速运行)
|
||||
- [代码格式化](#代码格式化)
|
||||
- [交互式编程](#交互式编程)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -81,3 +82,9 @@ lua 代码格式化,主要依赖 `format` 模块,同时需要安装相关的
|
||||
```sh
|
||||
luarocks install formatter
|
||||
```
|
||||
|
||||
### 交互式编程
|
||||
|
||||
在编辑 lua 文件时,可通过快捷键 `SPC l s i` 启动 `lua -i` 交互窗口,之后使用快捷键将代码发送至解释器。默认快捷键都以 `SPC l s` 为前缀。
|
||||
|
||||
![luarepl](https://user-images.githubusercontent.com/13142418/52158892-075f7a80-26d8-11e9-9bf2-2be8ab2363ab.gif)
|
||||
|
@ -11,6 +11,7 @@ lang: cn
|
||||
- [模块简介](#模块简介)
|
||||
- [启用模块](#启用模块)
|
||||
- [快捷键](#快捷键)
|
||||
- [常规快捷键](#常规快捷键)
|
||||
- [交互式编程](#交互式编程)
|
||||
- [运行当前脚本](#运行当前脚本)
|
||||
|
||||
@ -31,6 +32,12 @@ lang: cn
|
||||
|
||||
## 快捷键
|
||||
|
||||
### 常规快捷键
|
||||
|
||||
| 快捷键 | 描述 |
|
||||
| --------- | -------------------------- |
|
||||
| `SPC l b` | 使用 `luac` 编译当前文件至 |
|
||||
|
||||
### 交互式编程
|
||||
|
||||
启动 `lua` 或者 `luap` 交互进程,快捷键为: `SPC l s i`。若使用 `luap`,需要在载入模块时设置 `repl_command` 选项:
|
||||
@ -43,11 +50,11 @@ lang: cn
|
||||
|
||||
将代码传输给 REPL 进程执行:
|
||||
|
||||
| 快捷键 | 描述 |
|
||||
| ----------- | --------------------------- |
|
||||
| 快捷键 | 描述 |
|
||||
| ----------- | ----------------------- |
|
||||
| `SPC l s b` | 发送整个文件内容至 REPL |
|
||||
| `SPC l s l` | 发送当前行内容至 REPL |
|
||||
| `SPC l s s` | 发送已选中的内容至 REPL |
|
||||
| `SPC l s l` | 发送当前行内容至 REPL |
|
||||
| `SPC l s s` | 发送已选中的内容至 REPL |
|
||||
|
||||
### 运行当前脚本
|
||||
|
||||
|
@ -9,11 +9,11 @@ description: "This layer is for lua development, provide autocompletion, syntax
|
||||
|
||||
- [Description](#description)
|
||||
- [Install](#install)
|
||||
- [Layer](#layer)
|
||||
- [Syntax checking && Code formatting](#syntax-checking--code-formatting)
|
||||
- [Features](#features)
|
||||
- [Key bindings](#key-bindings)
|
||||
- [Inferior REPL process](#inferior-repl-process)
|
||||
- [General Key bindings](#general-key-bindings)
|
||||
- [Running current script](#running-current-script)
|
||||
- [Inferior REPL process](#inferior-repl-process)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -23,43 +23,47 @@ This layer is for lua development.
|
||||
|
||||
## Install
|
||||
|
||||
### Layer
|
||||
|
||||
To use this configuration layer, update custom configuration file with:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#lua"
|
||||
```
|
||||
## Features
|
||||
|
||||
### Syntax checking && Code formatting
|
||||
|
||||
- syntax checking
|
||||
- code formatting
|
||||
- code completion
|
||||
- repl support
|
||||
- code runner
|
||||
|
||||
## Key bindings
|
||||
|
||||
### General Key bindings
|
||||
|
||||
| Key Binding | Description |
|
||||
| ----------- | ------------------------------------------------ |
|
||||
| `SPC l b` | compile current lua buffer |
|
||||
|
||||
|
||||
### Running current script
|
||||
|
||||
To running a lua script, you can press `SPC l r` to run current file without loss focus, and the result will be shown in a runner buffer.
|
||||
|
||||
### Inferior REPL process
|
||||
|
||||
Start a `lua` or `luap` inferior REPL process with `SPC l s i`. You may change the REPL command by layer option `repl_command`. For example, if you want to use `lua.repl`, load this layer via:
|
||||
Start a `lua -i` or `luap` inferior REPL process with `SPC l s i`. You may change the REPL command by layer option `repl_command`. For example, if you want to use `lua.repl`, load this layer via:
|
||||
|
||||
```vim
|
||||
call SpaceVim#layers#load('lang#lua'
|
||||
\ {
|
||||
\ 'repl_command' : '~/.luarocks/lib/luarocks/rocks-5.3/luarepl/0.8-1/bin/rep.lua',
|
||||
\ }
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#lua"
|
||||
repl_command = "~/.luarocks/lib/luarocks/rocks-5.3/luarepl/0.8-1/bin/rep.lua"
|
||||
```
|
||||
|
||||
Send code to inferior process commands:
|
||||
|
||||
| Key Binding | Description |
|
||||
| ----------- | ------------------------------------------------ |
|
||||
| `SPC l b` | compile current lua buffer |
|
||||
| `SPC l r` | run current lua file |
|
||||
| `SPC l f` | format current lua file |
|
||||
| `SPC l s b` | send buffer and keep code buffer focused |
|
||||
| `SPC l s l` | send line and keep code buffer focused |
|
||||
| `SPC l s s` | send selection text and keep code buffer focused |
|
||||
|
||||
|
||||
### Running current script
|
||||
|
||||
To running a lua script, you can press `SPC l r` to run current file without loss focus, and the result will be shown in a runner buffer.
|
||||
|
Loading…
Reference in New Issue
Block a user