From 151e0a6e18faf91b6c5df670e8a407a34ba4bf01 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Wed, 22 Aug 2018 20:40:25 +0800 Subject: [PATCH] add lang#erlang layer (#2074) * Add lang#erlang layer * Fix erlang omni patterns * Add doc * Add repl support for erlang * Add lang#erlang layer * Type --- autoload/SpaceVim/layers/lang/erlang.vim | 64 ++++++++++++++++++++++++ config/plugins/deoplete.vim | 5 ++ docs/cn/layers/index.md | 1 + docs/cn/layers/lang/erlang.md | 61 ++++++++++++++++++++++ docs/layers/index.md | 1 + docs/layers/lang/WebAssembly.md | 2 +- docs/layers/lang/erlang.md | 64 ++++++++++++++++++++++++ wiki/en/Following-HEAD.md | 1 + 8 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 autoload/SpaceVim/layers/lang/erlang.vim create mode 100644 docs/cn/layers/lang/erlang.md create mode 100644 docs/layers/lang/erlang.md diff --git a/autoload/SpaceVim/layers/lang/erlang.vim b/autoload/SpaceVim/layers/lang/erlang.vim new file mode 100644 index 000000000..407c7e85c --- /dev/null +++ b/autoload/SpaceVim/layers/lang/erlang.vim @@ -0,0 +1,64 @@ +"============================================================================= +" erlang.vim --- erlang support for SpaceVim +" Copyright (c) 2016-2017 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg at 163.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + +function! SpaceVim#layers#lang#erlang#plugins() abort + let plugins = [] + call add(plugins, ['vim-erlang/vim-erlang-compiler', {'on_ft' : 'erlang'}]) + call add(plugins, ['vim-erlang/vim-erlang-omnicomplete', {'on_ft' : 'erlang'}]) + call add(plugins, ['vim-erlang/vim-erlang-runtime', {'on_ft' : 'erlang'}]) + call add(plugins, ['vim-erlang/vim-erlang-tags', {'on_ft' : 'erlang'}]) + return plugins +endfunction + + +function! SpaceVim#layers#lang#erlang#config() abort + call SpaceVim#plugins#repl#reg('erlang', 'erl') + " call SpaceVim#plugins#runner#reg_runner('erlang', ['erlc -o #TEMP# %s', 'erl -pa #TEMP#']) + call SpaceVim#mapping#space#regesit_lang_mappings('erlang', function('s:language_specified_mappings')) + " call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def')) +endfunction +function! s:language_specified_mappings() abort + " call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], + " \ 'call SpaceVim#plugins#runner#open()', + " \ 'execute current file', 1) + if SpaceVim#layers#lsp#check_filetype('erlang') + nnoremap K :call SpaceVim#lsp#show_doc() + + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], + \ 'call SpaceVim#lsp#show_doc()', 'show_document', 1) + call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], + \ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) + " else + " nnoremap K :call alchemist#exdoc() + " call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], + " \ 'call alchemist#exdoc()', 'show_document', 1) + " call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 't'], + " \ 'call alchemist#jump_tag_stack()', 'jump to tag stack', 1) + endif + let g:_spacevim_mappings_space.l.s = {'name' : '+Send'} + call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'], + \ 'call SpaceVim#plugins#repl#start("erlang")', + \ '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) +endfunction + +function! s:go_to_def() abort + if SpaceVim#layers#lsp#check_filetype('erlang') + call SpaceVim#lsp#go_to_def() + else + normal! gd + endif +endfunction diff --git a/config/plugins/deoplete.vim b/config/plugins/deoplete.vim index 53e69510e..a31bde3bc 100644 --- a/config/plugins/deoplete.vim +++ b/config/plugins/deoplete.vim @@ -95,6 +95,11 @@ let g:deoplete#keyword_patterns.clojure = '[\w!$%&*+/:<=>?@\^_~\-\.#]*' " ocaml let g:deoplete#ignore_sources.ocaml = ['buffer', 'around', 'omni'] +" erlang +let g:deoplete#omni#input_patterns.erlang = get(g:deoplete#omni#input_patterns, 'erlang', [ + \'[^. \t0-9]\.\w*', + \]) + " public settings call deoplete#custom#source('_', 'matchers', ['matcher_full_fuzzy']) call deoplete#custom#source('file/include', 'matchers', ['matcher_head']) diff --git a/docs/cn/layers/index.md b/docs/cn/layers/index.md index 023e58f31..48b1f035d 100644 --- a/docs/cn/layers/index.md +++ b/docs/cn/layers/index.md @@ -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#erlang](lang/erlang/) | 这一模块为 erlang 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 | | [lang#go](lang/go/) | 这一模块为 go 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 | | [lang#haskell](lang/haskell/) | 这一模块为 haskell 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 | | [lang#html](lang/html/) | 这一模块为 html 开发提供支持,包括代码补全、语法检查、代码格式化等特性。 | diff --git a/docs/cn/layers/lang/erlang.md b/docs/cn/layers/lang/erlang.md new file mode 100644 index 000000000..21e37e1af --- /dev/null +++ b/docs/cn/layers/lang/erlang.md @@ -0,0 +1,61 @@ +--- +title: "SpaceVim lang#erlang 模块" +description: "这一模块为 erlang 开发提供支持,包括代码补全、语法检查、代码格式化等特性。" +lang: cn +--- + +# [可用模块](../../) >> lang#erlang + + + +- [模块简介](#模块简介) +- [功能特性](#功能特性) +- [启用模块](#启用模块) +- [快捷键](#快捷键) + - [语言专属快捷键](#语言专属快捷键) + - [交互式编程](#交互式编程) + + + +## 模块简介 + +这一模块为 SpaceVim 提供了 erlang 开发支持,包括代码补全、语法检查、以及代码格式化等特性。 + +## 功能特性 + +- 代码补全 +- 文档查询 +- 跳转定义处 + +同时,SpaceVim 还为 erlang 开发提供了交互式编程和语言服务器等功能。若要启用语言服务器,需要载入 `lsp` 模块。 + +## 启用模块 + +可通过在配置文件内加入如下配置来启用该模块: + +```toml +[[layers]] + name = "lang#erlang" +``` + +## 快捷键 + +### 语言专属快捷键 + +| 按键 | 功能描述 | +| --------------- | --------------------------------------- | +| `SPC l d` / `K` | 展示光标函数或变量相关文档(需要 `lsp` 模块) | +| `SPC l e` | 重命名光标函数或变量(需要 `lsp` 模块) | +| `g d` | 跳至函数或变量定义处(需要 `lsp` 模块) | + +### 交互式编程 + +启动 `erl` 交互进程,快捷键为: `SPC l s i`。 + +将代码传输给 REPL 进程执行: + +| 快捷键 | 描述 | +| ----------- | ----------------------- | +| `SPC l s b` | 发送整个文件内容至 REPL | +| `SPC l s l` | 发送当前行内容至 REPL | +| `SPC l s s` | 发送已选中的内容至 REPL | diff --git a/docs/layers/index.md b/docs/layers/index.md index 57bedc783..5d0308b04 100644 --- a/docs/layers/index.md +++ b/docs/layers/index.md @@ -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#erlang](lang/erlang/) | This layer is for erlang development, provide autocompletion, syntax checking, code format for erlang file. | | [lang#go](lang/go/) | This layer is for golang development. It also provides additional language-specific key mappings. | | [lang#haskell](lang/haskell/) | haskell language support for SpaceVim, includes code completion, syntax checking, jumping to definition, also provides language server protocol support for haskell | | [lang#html](lang/html/) | Edit html in SpaceVim, with this layer, this layer provides code completion, syntax checking and code formatting for html. | diff --git a/docs/layers/lang/WebAssembly.md b/docs/layers/lang/WebAssembly.md index 964e18a86..4adc1564a 100644 --- a/docs/layers/lang/WebAssembly.md +++ b/docs/layers/lang/WebAssembly.md @@ -27,5 +27,5 @@ To use this configuration layer, update custom configuration file with: ```toml [[layers]] - name = "lang#kotlin" + name = "lang#WebAssembly" ``` diff --git a/docs/layers/lang/erlang.md b/docs/layers/lang/erlang.md new file mode 100644 index 000000000..164e73cd3 --- /dev/null +++ b/docs/layers/lang/erlang.md @@ -0,0 +1,64 @@ +--- +title: "SpaceVim lang#elang layer" +description: "This layer is for erlang development, provide autocompletion, syntax checking, code format for erlang file." +--- + +# [Available Layers](../../) >> lang#erlang + + + +- [Description](#description) +- [Features](#features) +- [Install](#install) + - [Layer](#layer) +- [Key bindings](#key-bindings) + - [Language specific key bindings](#language-specific-key-bindings) + - [Inferior REPL process](#inferior-repl-process) + + + +## Description + +This layer is for erlang development. + +## Features + +- code completion +- syntax highlighting +- syntax checking + +SpaceVim also provides REPL, code runner and Language Server protocol support for erlang. to enable language server protocol +for erlang, you need to load `lsp` layer for erlang. + +## Install + +### Layer + +To use this configuration layer, update custom configuration file with: + +```toml +[[layers]] + name = "lang#erlang" +``` + +## Key bindings + +### Language specific key bindings + +| Key binding | Description | +| --------------- | -------------------------------------------- | +| `SPC l d` / `K` | Show doc of cursor symbol (need `lsp` layer) | +| `SPC l e` | Rename symbol (need `lsp` layer) | +| `g d` | Jump to definition (need `lsp` layer) | + +### Inferior REPL process + +Start a `erl` inferior REPL process with `SPC l s i`. + +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 | diff --git a/wiki/en/Following-HEAD.md b/wiki/en/Following-HEAD.md index 7426588ce..eeb00fc71 100644 --- a/wiki/en/Following-HEAD.md +++ b/wiki/en/Following-HEAD.md @@ -25,6 +25,7 @@ The next release is v0.9.0. - Add `lang#nim` layer ([#2018](https://github.com/SpaceVim/SpaceVim/pull/2018)) - Add `lang#purescript` layer ([#2054](https://github.com/SpaceVim/SpaceVim/pull/2054)) - Add `lang#WebAssembly` layer ([#2068](https://github.com/SpaceVim/SpaceVim/pull/2068)) +- Add `lang#erlang` layer ([#2074](https://github.com/SpaceVim/SpaceVim/pull/2074)) ### Improvement