1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

Add lang#elm layer (#2088)

Add lang#elm layer and improve repl highlight
This commit is contained in:
Wang Shidong 2018-08-26 13:14:25 +08:00 committed by GitHub
parent 9ed641aabf
commit afcf9067dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 372 additions and 18 deletions

View File

@ -0,0 +1,61 @@
"=============================================================================
" elixir.vim --- SpaceVim lang#elm layer
" Copyright (c) 2016-2017 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
""
" @section lang#elm, layer-lang-elm
" @parentsection layers
" @subsection Intro
" The lang#elm layer provides code completion, documentation lookup, jump to
" definition, mix integration, and iex integration for elm. SpaceVim
" uses neomake as default syntax checker which is loaded in
" @section(layer-checkers)
function! SpaceVim#layers#lang#elm#plugins() abort
let plugins = []
call add(plugins, ['wsdjeg/vim-elm', {'on_ft' : 'elm'}])
return plugins
endfunction
function! SpaceVim#layers#lang#elm#config() abort
call SpaceVim#plugins#repl#reg('elm', 'elm repl')
call SpaceVim#mapping#space#regesit_lang_mappings('elm', function('s:language_specified_mappings'))
endfunction
function! s:language_specified_mappings() abort
let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'],
\ 'call SpaceVim#plugins#repl#start("elm")',
\ 'start REPL process', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'l'],
\ 'call SpaceVim#plugins#repl#send("line")',
\ 'send line and keep code buffer focused', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'b'],
\ 'call SpaceVim#plugins#repl#send("buffer")',
\ 'send buffer and keep code buffer focused', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 's'],
\ 'call SpaceVim#plugins#repl#send("selection")',
\ 'send selection and keep code buffer focused', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','m'],
\ '<Plug>(elm-make)',
\ 'Compile the current buffer', 0)
call SpaceVim#mapping#space#langSPC('nmap', ['l','t'],
\ '<Plug>(elm-test)',
\ 'Runs the tests', 0)
call SpaceVim#mapping#space#langSPC('nmap', ['l','e'],
\ '<Plug>(elm-error-detail)',
\ 'Show error detail', 0)
call SpaceVim#mapping#space#langSPC('nmap', ['l','d'],
\ '<Plug>(elm-show-docs)',
\ 'Show symbol doc', 0)
call SpaceVim#mapping#space#langSPC('nmap', ['l','w'],
\ '<Plug>(elm-browse-docs)',
\ 'Browse symbol doc', 0)
nmap <buffer> K <Plug>(elm-show-docs)
let g:elm_setup_keybindings = 0
endfunction

View File

@ -56,23 +56,24 @@ CONTENTS *SpaceVim-contents*
12. lang#crystal...........................|SpaceVim-layer-lang-crystal|
13. lang#csharp.............................|SpaceVim-layer-lang-csharp|
14. lang#elixir.............................|SpaceVim-layer-lang-elixir|
15. lang#go.....................................|SpaceVim-layer-lang-go|
16. lang#java.................................|SpaceVim-layer-lang-java|
17. lang#julia...............................|SpaceVim-layer-lang-julia|
18. lang#kotlin.............................|SpaceVim-layer-lang-kotlin|
19. lang#lua...................................|SpaceVim-layer-lang-lua|
20. lang#ocaml...............................|SpaceVim-layer-lang-ocaml|
21. lang#php...................................|SpaceVim-layer-lang-php|
22. lang#pony.................................|SpaceVim-layer-lang-pony|
23. lang#puppet.............................|SpaceVim-layer-lang-puppet|
24. lang#python.............................|SpaceVim-layer-lang-python|
25. lang#rust.................................|SpaceVim-layer-lang-rust|
26. lang#scala...............................|SpaceVim-layer-lang-scala|
27. lang#xml...................................|SpaceVim-layer-lang-xml|
28. operator...................................|SpaceVim-layer-operator|
29. shell.........................................|SpaceVim-layer-shell|
30. tmux...........................................|SpaceVim-layer-tmux|
31. tools#dash...............................|SpaceVim-layer-tools-dash|
15. lang#elm...................................|SpaceVim-layer-lang-elm|
16. lang#go.....................................|SpaceVim-layer-lang-go|
17. lang#java.................................|SpaceVim-layer-lang-java|
18. lang#julia...............................|SpaceVim-layer-lang-julia|
19. lang#kotlin.............................|SpaceVim-layer-lang-kotlin|
20. lang#lua...................................|SpaceVim-layer-lang-lua|
21. lang#ocaml...............................|SpaceVim-layer-lang-ocaml|
22. lang#php...................................|SpaceVim-layer-lang-php|
23. lang#pony.................................|SpaceVim-layer-lang-pony|
24. lang#puppet.............................|SpaceVim-layer-lang-puppet|
25. lang#python.............................|SpaceVim-layer-lang-python|
26. lang#rust.................................|SpaceVim-layer-lang-rust|
27. lang#scala...............................|SpaceVim-layer-lang-scala|
28. lang#xml...................................|SpaceVim-layer-lang-xml|
29. operator...................................|SpaceVim-layer-operator|
30. shell.........................................|SpaceVim-layer-shell|
31. tmux...........................................|SpaceVim-layer-tmux|
32. tools#dash...............................|SpaceVim-layer-tools-dash|
7. API........................................................|SpaceVim-api|
1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu|
2. data#list....................................|SpaceVim-api-data-list|
@ -1012,6 +1013,14 @@ The lang#elixir layer provides code completion, documentation lookup, jump to
definition, mix integration, and iex integration for Elixir. SpaceVim uses
neomake as default syntax checker which is loaded in |SpaceVim-layer-checkers|
==============================================================================
LANG#ELM *SpaceVim-layer-lang-elm*
INTRO
The lang#elm layer provides code completion, documentation lookup, jump to
definition, mix integration, and iex integration for elm. SpaceVim uses
neomake as default syntax checker which is loaded in |SpaceVim-layer-checkers|
==============================================================================
LANG#GO *SpaceVim-layer-lang-go*

View File

@ -76,6 +76,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [lang#c](lang/c/) | 这一模块为 c/c++/object-c 的开发提供了支持,包括代码补全、语法检查等特性。 |
| [lang#dart](lang/dart/) | 这一模块为 dart 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#elixir](lang/elixir/) | 这一模块为 elixir 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#elm](lang/elm/) | 这一模块为 elm 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#erlang](lang/erlang/) | 这一模块为 erlang 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#fsharp](lang/fsharp/) | 这一模块为 fsharp 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#go](lang/go/) | 这一模块为 go 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 |

View File

@ -0,0 +1,98 @@
---
title: "SpaceVim lang#elm 模块"
description: "这一模块为 elm 开发提供支持,包括代码补全、语法检查、代码格式化等特性。"
image: https://user-images.githubusercontent.com/13142418/44625046-7b2f7700-a931-11e8-807e-dba3f73c9e90.png
lang: cn
---
# [可用模块](../../) >> lang#elm
<!-- vim-markdown-toc GFM -->
- [模块简介](#模块简介)
- [功能特性](#功能特性)
- [依赖安装及启用模块](#依赖安装及启用模块)
- [依赖安装](#依赖安装)
- [启用模块](#启用模块)
- [快捷键](#快捷键)
- [语言专属快捷键](#语言专属快捷键)
- [交互式编程](#交互式编程)
<!-- vim-markdown-toc -->
## 模块简介
这一模块为 SpaceVim 提供了 elm 开发支持,包括代码补全、语法检查、以及代码格式化等特性。
## 功能特性
- 代码补全
- 语法高亮、对齐
- 单元测试
- 语法检查
- 文档查询
同时SpaceVim 还为 elm 开发提供了交互式编程。
## 依赖安装及启用模块
### 依赖安装
首先,需要安装 [elm](http://elm-lang.org/) 语言,最方便的安装方式是使用官方的 npm 包。
```sh
npm install -g elm
```
为了可以在 vim 内执行单元测试,需要安装 [elm-test](https://github.com/rtfeldman/node-elm-test)。
```sh
npm install -g elm-test
```
代码补全以及文档查询依赖于 [elm-oracle](https://github.com/elmcast/elm-oracle)。
```sh
npm install -g elm-oracle
```
自动格式化代码,需要安装 [elm-format](https://github.com/avh4/elm-format)。
```sh
npm install -g elm-format
```
### 启用模块
可通过在配置文件内加入如下配置来启用该模块:
```toml
[[layers]]
name = "lang#elm"
```
## 快捷键
### 语言专属快捷键
| 快捷键 | 描述 |
| --------------- | ---------------------- |
| `SPC l d` / `K` | 查询光标下符号的文档 |
| `SPC l m` | 编译当前文档 |
| `SPC l t` | 运行单元测试 |
| `SPC l e` | 显示错误及警告信息 |
| `SPC l w` | 使用浏览器打开相关文档 |
### 交互式编程
启动 `elm repl` 交互进程,快捷键为: `SPC l s i`
![elm repl](https://user-images.githubusercontent.com/13142418/44625046-7b2f7700-a931-11e8-807e-dba3f73c9e90.png)
将代码传输给 REPL 进程执行:
| 快捷键 | 描述 |
| ----------- | ----------------------- |
| `SPC l s b` | 发送整个文件内容至 REPL |
| `SPC l s l` | 发送当前行内容至 REPL |
| `SPC l s s` | 发送已选中的内容至 REPL |

View File

@ -75,6 +75,7 @@ enable = false
| [lang#dart](lang/dart/) | This layer is for dart development, provide autocompletion, syntax checking, code format for dart file. |
| [lang#dockerfile](lang/dockerfile/) | This layer adds DockerFile to SpaceVim |
| [lang#elixir](lang/elixir/) | This layer is for elixir development, provide autocompletion, syntax checking, code format for elixir file. |
| [lang#elm](lang/elm/) | This layer is for elm development, provide autocompletion, syntax checking, code format for elm file. |
| [lang#erlang](lang/erlang/) | This layer is for erlang development, provide autocompletion, syntax checking, code format for erlang file. |
| [lang#fsharp](lang/fsharp/) | This layer adds fsharp language support to SpaceVim |
| [lang#go](lang/go/) | This layer is for golang development. It also provides additional language-specific key mappings. |

97
docs/layers/lang/elm.md Normal file
View File

@ -0,0 +1,97 @@
---
title: "SpaceVim lang#elm layer"
description: "This layer is for elm development, provide autocompletion, syntax checking, code format for elm file."
image: https://user-images.githubusercontent.com/13142418/44625046-7b2f7700-a931-11e8-807e-dba3f73c9e90.png
---
# [Available Layers](../../) >> lang#elm
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Features](#features)
- [Install](#install)
- [Requirements](#requirements)
- [Layer](#layer)
- [Key bindings](#key-bindings)
- [Language specific key bindings](#language-specific-key-bindings)
- [Inferior REPL process](#inferior-repl-process)
<!-- vim-markdown-toc -->
## Description
This layer is for elm development.
## Features
- Code completion
- Syntax highlighting, indent
- Running unite test
- Syntax checking
- Find symbol doc
SpaceVim also provides REPL support for elm.
## Install
### Requirements
First, make sure you have the [Elm Platform](http://elm-lang.org/install) installed. The simplest method to get started is to use the official [npm](https://www.npmjs.com/package/elm) package.
```sh
npm install -g elm
```
In order to run unit tests from within vim, install [elm-test](https://github.com/rtfeldman/node-elm-test)
```sh
npm install -g elm-test
```
For code completion and doc lookups, install [elm-oracle](https://github.com/elmcast/elm-oracle).
```sh
npm install -g elm-oracle
```
To automatically format your code, install [elm-format](https://github.com/avh4/elm-format).
```sh
npm install -g elm-format
```
### Layer
To use this configuration layer, update custom configuration file with:
```toml
[[layers]]
name = "lang#elm"
```
## Key bindings
### Language specific key bindings
| Key binding | Description |
| --------------- | -------------------------- |
| `SPC l d` / `K` | Show doc of cursor symbol |
| `SPC l m` | Compile the current buffer |
| `SPC l t` | Runs the tests |
| `SPC l e` | Show error detail |
| `SPC l w` | Browse symbol doc |
### Inferior REPL process
Start a `elm repl` inferior REPL process with `SPC l s i`.
![elm repl](https://user-images.githubusercontent.com/13142418/44625046-7b2f7700-a931-11e8-807e-dba3f73c9e90.png)
Send code to inferior process commands:
| Key Binding | Description |
| ----------- | ------------------------------------------------ |
| `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 |

86
syntax/SpaceVimREPL.vim Normal file
View File

@ -0,0 +1,86 @@
if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimREPL'
finish
endif
let b:current_syntax = 'SpaceVimREPL'
syntax case ignore
syn match SpaceVimREPLLabel /\[REPL executable\]/
syn match SpaceVimREPLRunnerCmd /\(\[REPL executable\]\ \)\@<=.*/
hi def link SpaceVimREPLLabel String
hi def link RunnerCmd Comment
let s:shellcmd_colors =
\ [
\ '#6c6c6c', '#ff6666', '#66ff66', '#ffd30a',
\ '#1e95fd', '#ff13ff', '#1bc8c8', '#c0c0c0',
\ '#383838', '#ff4444', '#44ff44', '#ffb30a',
\ '#6699ff', '#f820ff', '#4ae2e2', '#ffffff',
\]
function! s:highlight_shell_cmd() abort
let highlight_table = {
\ '0' : ' cterm=NONE ctermfg=NONE ctermbg=NONE gui=NONE guifg=NONE guibg=NONE',
\ '1' : ' cterm=BOLD gui=BOLD',
\ '3' : ' cterm=ITALIC gui=ITALIC',
\ '4' : ' cterm=UNDERLINE gui=UNDERLINE',
\ '7' : ' cterm=REVERSE gui=REVERSE',
\ '8' : ' ctermfg=0 ctermbg=0 guifg=#000000 guibg=#000000',
\ '9' : ' gui=UNDERCURL',
\ '21' : ' cterm=UNDERLINE gui=UNDERLINE',
\ '22' : ' gui=NONE',
\ '23' : ' gui=NONE',
\ '24' : ' gui=NONE',
\ '25' : ' gui=NONE',
\ '27' : ' gui=NONE',
\ '28' : ' ctermfg=NONE ctermbg=NONE guifg=NONE guibg=NONE',
\ '29' : ' gui=NONE',
\ '39' : ' ctermfg=NONE guifg=NONE',
\ '49' : ' ctermbg=NONE guibg=NONE',
\ '90' : ' ctermfg=245 guifg=#928374',
\ '95' : ' ctermfg=175 guifg=#d3869b',
\}
for color in range(30, 37)
" Foreground color pattern.
let highlight_table[color] = printf(' ctermfg=%d guifg=%s',
\ color - 30, s:shellcmd_colors[color - 30])
for color2 in [1, 3, 4, 7]
" Type;Foreground color pattern
let highlight_table[color2 . ';' . color] =
\ highlight_table[color2] . highlight_table[color]
endfor
endfor
for color in range(40, 47)
" Background color pattern.
let highlight_table[color] = printf(' ctermbg=%d guibg=%s',
\ color - 40, s:shellcmd_colors[color - 40])
for color2 in range(30, 37)
" Foreground;Background color pattern.
let highlight_table[color2 . ';' . color] =
\ highlight_table[color2] . highlight_table[color]
endfor
endfor
syntax match SpaceVimRunner__Output_Shellcmd_Conceal
\ contained conceal '\e\[[0-9;]*m'
\ containedin=SpaceVimRunner__Output_Shellcmd
syntax match SpaceVimRunner__Output_Shellcmd_Conceal
\ contained conceal '\e\[?1h'
\ containedin=SpaceVimRunner__Output_Shellcmd
syntax match uniteSource__Output_Shellcmd_Ignore
\ contained conceal '\e\[?\d[hl]\|\e=\r\|\r\|\e>'
\ containedin=SpaceVimRunner__Output_Shellcmd
for [key, highlight] in items(highlight_table)
let syntax_name = 'SpaceVimRunner__Output_Shellcmd_Color'
\ . substitute(key, ';', '_', 'g')
let syntax_command = printf('start=+\e\[0\?%sm+ end=+\ze\e[\[0*m]\|$+ ' .
\ 'contains=SpaceVimRunner__Output_Shellcmd_Conceal ' .
\ 'containedin=SpaceVimRunner__Output_Shellcmd oneline', key)
execute 'syntax region' syntax_name syntax_command
execute 'highlight' syntax_name highlight
endfor
endfunction
call s:highlight_shell_cmd()

View File

@ -1,5 +1,5 @@
if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimRunner'
finish
finish
endif
let b:current_syntax = 'SpaceVimRunner'
syntax case ignore

View File

@ -28,6 +28,7 @@ The next release is v0.9.0.
- Add `lang#erlang` layer ([#2074](https://github.com/SpaceVim/SpaceVim/pull/2074))
- Add `lang#fsharp` layer ([#2081](https://github.com/SpaceVim/SpaceVim/pull/2081))
- Add `lang#plantuml` layer ([#2085](https://github.com/SpaceVim/SpaceVim/pull/2085))
- Add `lang#elm` layer, improve REPL highlight ([#2088](https://github.com/SpaceVim/SpaceVim/pull/2088))
### Improvement