mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a65ffe66d | ||
|
|
b9dae8fbab | ||
|
|
84593f2d7f | ||
|
|
22f6f3b6d3 | ||
|
|
8cd62b9eab | ||
|
|
93e3f020a9 | ||
|
|
81ccd02032 | ||
|
|
2ae1aab49b | ||
|
|
554ae93ef1 | ||
|
|
7a29850ae9 | ||
|
|
c200e7a0c5 | ||
|
|
5529a5e8e2 | ||
|
|
905031eb95 | ||
|
|
76d23a21e6 | ||
|
|
5dd1a7e839 | ||
|
|
bc098370c1 | ||
|
|
b07b46bc0c | ||
|
|
b0823d2068 | ||
|
|
b4a6290b42 | ||
|
|
c324a086b2 | ||
|
|
2bde381723 | ||
|
|
61390f5885 | ||
|
|
f8a0fb37bf | ||
|
|
13fe6ad758 | ||
|
|
78427e4c22 | ||
|
|
829ab22723 | ||
|
|
a8d08c8a49 | ||
|
|
7679a92627 | ||
|
|
ad44c4f7a3 | ||
|
|
3c56c1c7cd | ||
|
|
d4e83d706f | ||
|
|
c47dc02849 | ||
|
|
841cb535df | ||
|
|
e5b26a7308 | ||
|
|
b4b054ebf5 | ||
|
|
08ea94e011 | ||
|
|
ba7a783c7f | ||
|
|
f58692a641 | ||
|
|
0dc7696c89 | ||
|
|
5658b62b7a | ||
|
|
938a2f1667 | ||
|
|
303b3f1b43 | ||
|
|
bf84973173 | ||
|
|
89728a486d | ||
|
|
ae3a0d72cc | ||
|
|
3475a2df67 | ||
|
|
ac42e00864 | ||
|
|
0293cf8346 | ||
|
|
8c139a4546 | ||
|
|
47a036761a | ||
|
|
d2c90dad0a | ||
|
|
7ac92eac0f | ||
|
|
7800dae776 | ||
|
|
a39c9013cc | ||
|
|
25d2786cae | ||
|
|
1f1e821192 | ||
|
|
ae882e85f8 |
@@ -1,7 +1,11 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 1.9.3
|
||||
before_install: sudo apt-get install vim-gtk
|
||||
sudo: false
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- vim-gtk
|
||||
before_script:
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
|
||||
68
README.md
68
README.md
@@ -1,6 +1,6 @@
|
||||
# vim-polyglot [![Build Status][travis-img-url]][travis-url]
|
||||
# vim-polyglot [![Build Status][travis-img-url]][travis-url] []()
|
||||
|
||||
[travis-img-url]: https://travis-ci.org/sheerun/vim-polyglot.png
|
||||
[travis-img-url]: https://travis-ci.org/sheerun/vim-polyglot.svg
|
||||
[travis-url]: https://travis-ci.org/sheerun/vim-polyglot
|
||||
|
||||
A collection of language packs for Vim.
|
||||
@@ -8,7 +8,7 @@ A collection of language packs for Vim.
|
||||
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
|
||||
|
||||
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
|
||||
- It **installs 50+ times faster** than 50+ packages it consist of.
|
||||
- It **installs and updates 70+ times faster** than 70+ packages it consist of.
|
||||
- Solid syntax and indentation support. Only the best language packs.
|
||||
- All unnecessary files are ignored (like enormous documentation from php support).
|
||||
- No support for esoteric languages, only most popular ones (modern too, like `slim`).
|
||||
@@ -18,83 +18,99 @@ A collection of language packs for Vim.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Install pathogen, Vundle or NeoBundle package manager.
|
||||
1. Install [Pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [NeoBundle](https://github.com/Shougo/neobundle.vim), or [Plug](https://github.com/junegunn/vim-plug) package manager for Vim.
|
||||
2. Use this repository as submodule or package.
|
||||
|
||||
Optionally download one of the [releases](https://github.com/sheerun/vim-polyglot/releases) and unpack it directly under `~/.vim` directory.
|
||||
|
||||
## Language packs
|
||||
|
||||
- [ansible](https://github.com/pearofducks/ansible-vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent, ftdetect)
|
||||
- [blade](https://github.com/xsbeats/vim-blade) (syntax, indent, ftdetect)
|
||||
- [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin, ftdetect)
|
||||
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
|
||||
- [c/c++](https://github.com/vim-jp/cpp-vim) (syntax)
|
||||
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
|
||||
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
|
||||
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim) (syntax, compiler, ftplugin, ftdetect)
|
||||
- [crystal](https://github.com/rhysd/vim-crystal) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [cql](https://github.com/elubow/cql-vim) (syntax, ftdetect)
|
||||
- [css](https://github.com/JulesWang/css.vim) (syntax)
|
||||
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [dart](https://github.com/dart-lang/dart-vim-plugin) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [dockerfile](https://github.com/honza/dockerfile.vim) (syntax, ftdetect)
|
||||
- [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [elm](https://github.com/lambdatoast/elm.vim) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [emberscript](https://github.com/heartsentwined/vim-ember-script) (syntax, indent, ftplugin, ftdetect)
|
||||
- [emblem](https://github.com/heartsentwined/vim-emblem) (syntax, indent, ftplugin, ftdetect)
|
||||
- [erlang](https://github.com/hcs42/vim-erlang-runtime) (syntax, indent)
|
||||
- [erlang](https://github.com/vim-erlang/vim-erlang-runtime) (syntax, indent, ftdetect)
|
||||
- [fish](https://github.com/dag/vim-fish) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin, ftdetect)
|
||||
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent, ftdetect)
|
||||
- [go](https://github.com/fatih/vim-go) (syntax, indent, ftdetect)
|
||||
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent, ftdetect)
|
||||
- [groovy](https://github.com/vim-scripts/groovy.vim) (syntax)
|
||||
- [haml](https://github.com/tpope/vim-haml) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, ftplugin, ftdetect)
|
||||
- [haskell](https://github.com/raichoo/haskell-vim) ()
|
||||
- [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, indent, ftplugin, ftdetect)
|
||||
- [haskell](https://github.com/neovimhaskell/haskell-vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [haxe](https://github.com/yaymukund/vim-haxe) (syntax, ftdetect)
|
||||
- [html5](https://github.com/othree/html5.vim) (syntax, indent, autoload, ftplugin)
|
||||
- [jade](https://github.com/digitaltoad/vim-jade) (syntax, indent, ftplugin, ftdetect)
|
||||
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect)
|
||||
- [javascript](https://github.com/sheerun/yajs.vim) (syntax, indent)
|
||||
- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect)
|
||||
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, ftplugin, ftdetect)
|
||||
- [json](https://github.com/sheerun/vim-json) (syntax, indent, ftdetect)
|
||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
||||
- [jsx](https://github.com/mxw/vim-jsx) (after)
|
||||
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
||||
- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect)
|
||||
- [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent, ftdetect)
|
||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
||||
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin, ftdetect)
|
||||
- [markdown](https://github.com/tpope/vim-markdown) (syntax, ftplugin, ftdetect)
|
||||
- [nginx](https://github.com/mutewinter/nginx.vim) (syntax, ftdetect)
|
||||
- [nginx](https://github.com/othree/nginx-contrib-vim) (syntax, indent, ftdetect)
|
||||
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, indent, ftdetect)
|
||||
- [nix](https://github.com/spwhitt/vim-nix) (syntax, ftplugin, ftdetect)
|
||||
- [objc](https://github.com/b4winckler/vim-objc) (ftplugin, syntax, indent)
|
||||
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
|
||||
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
|
||||
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect)
|
||||
- [perl](https://github.com/vim-perl/vim-perl) (syntax, indent, ftplugin, ftdetect)
|
||||
- [pgsql](https://github.com/exu/pgsql.vim) (syntax, ftdetect)
|
||||
- [php](https://github.com/StanAngeloff/php.vim) (syntax)
|
||||
- [puppet](https://github.com/rodjek/vim-puppet) (syntax, indent, ftplugin, ftdetect)
|
||||
- [plantuml](https://github.com/aklt/plantuml-syntax) (syntax, ftplugin, ftdetect)
|
||||
- [powershell](https://github.com/Persistent13/vim-ps1) (syntax, indent, ftplugin, ftdetect)
|
||||
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, ftdetect)
|
||||
- [pug](https://github.com/digitaltoad/vim-pug) (syntax, indent, ftplugin, ftdetect)
|
||||
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin, ftdetect)
|
||||
- [purescript](https://github.com/raichoo/purescript-vim) (syntax, indent, ftdetect)
|
||||
- [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent)
|
||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin, ftdetect)
|
||||
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
||||
- [ragel](https://github.com/jneen/ragel.vim) (syntax)
|
||||
- [rspec](https://github.com/sheerun/rspec.vim) (syntax, ftdetect)
|
||||
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [rust](https://github.com/wting/rust.vim) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [rust](https://github.com/rust-lang/rust.vim) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [sbt](https://github.com/derekwyatt/vim-sbt) (syntax, ftdetect)
|
||||
- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftdetect)
|
||||
- [solidity](https://github.com/ethereum/vim-solidity) (syntax, indent, ftdetect)
|
||||
- [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin, ftdetect)
|
||||
- [swift](https://github.com/keith/swift.vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [systemd](https://github.com/kurayama/systemd-vim-syntax) (syntax, ftdetect)
|
||||
- [swift](https://github.com/toyamarinyon/vim-swift) (syntax, indent, ftdetect)
|
||||
- [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin, ftdetect)
|
||||
- [tmux](https://github.com/tejr/vim-tmux) (syntax, ftdetect)
|
||||
- [tomdoc](https://github.com/duwanis/tomdoc.vim) (syntax)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||
- [thrift](https://github.com/solarnz/thrift.vim) (syntax, ftdetect)
|
||||
- [tmux](https://github.com/tejr/vim-tmux) (syntax, ftdetect)
|
||||
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
|
||||
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect)
|
||||
- [twig](https://github.com/beyondwords/vim-twig) (syntax, ftplugin, ftdetect)
|
||||
- [xls](https://github.com/vim-scripts/XSLT-syntax) (syntax)
|
||||
- [yard](https://github.com/sheerun/vim-yardoc) (syntax)
|
||||
- [twig](https://github.com/evidens/vim-twig) (syntax, ftplugin)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
|
||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect)
|
||||
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent, ftdetect)
|
||||
- [xls](https://github.com/vim-scripts/XSLT-syntax) (syntax)
|
||||
- [yaml](https://github.com/stephpy/vim-yaml) (syntax, ftplugin)
|
||||
- [yard](https://github.com/sheerun/vim-yardoc) (syntax)
|
||||
|
||||
## Disabling a language pack
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim ftdetect file
|
||||
"
|
||||
" Language: JSX (JavaScript)
|
||||
" Maintainer: Max Wang <mxawng@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
|
||||
fu! <SID>EnableJSX()
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif
|
||||
return 1
|
||||
endfu
|
||||
|
||||
autocmd BufNewFile,BufRead *.jsx let b:jsx_ext_found = 1
|
||||
autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx
|
||||
autocmd BufNewFile,BufRead *.js
|
||||
\ if <SID>EnableJSX() | set filetype=javascript.jsx | endif
|
||||
|
||||
endif
|
||||
7
after/ftplugin/cabal.vim
Normal file
7
after/ftplugin/cabal.vim
Normal file
@@ -0,0 +1,7 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
setlocal comments=s1fl:{-,mb:-,ex:-},:--
|
||||
setlocal iskeyword+=-,.,*
|
||||
setlocal commentstring=--\ %s
|
||||
|
||||
endif
|
||||
6
after/ftplugin/haskell.vim
Normal file
6
after/ftplugin/haskell.vim
Normal file
@@ -0,0 +1,6 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
setlocal comments=s1fl:{-,mb:-,ex:-},:--
|
||||
setlocal iskeyword+='
|
||||
|
||||
endif
|
||||
11
after/ftplugin/yaml.vim
Normal file
11
after/ftplugin/yaml.vim
Normal file
@@ -0,0 +1,11 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Yaml
|
||||
" Author: Henrique Barcelos
|
||||
" Date: 2014-10-08
|
||||
" URL: https://github.com/hjpbarcelos
|
||||
setlocal autoindent sw=2 ts=2 expandtab
|
||||
" vim:set sw=2:
|
||||
|
||||
endif
|
||||
@@ -9,13 +9,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Do nothing if we don't find the @jsx pragma (and we care).
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | finish | endif
|
||||
|
||||
" Do nothing if we don't have the .jsx extension (and we care).
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | finish | endif
|
||||
|
||||
" Prologue; load in XML indentation.
|
||||
if exists('b:did_indent')
|
||||
let s:did_indent=b:did_indent
|
||||
@@ -33,8 +26,8 @@ setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
" XML indentkeys
|
||||
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||
|
||||
" Self-closing tag regex.
|
||||
let s:sctag = '^\s*\/>\s*;\='
|
||||
" Multiline end tag regex (line beginning with '>' or '/>')
|
||||
let s:endtag = '^\s*\/\?>\s*;\='
|
||||
|
||||
" Get all syntax types at the beginning of a given line.
|
||||
fu! SynSOL(lnum)
|
||||
@@ -83,13 +76,13 @@ fu! GetJsxIndent()
|
||||
if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
|
||||
let ind = XmlIndentGet(v:lnum, 0)
|
||||
|
||||
" Align '/>' with '<' for multiline self-closing tags.
|
||||
if getline(v:lnum) =~? s:sctag
|
||||
" Align '/>' and '>' with '<' for multiline tags.
|
||||
if getline(v:lnum) =~? s:endtag
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
|
||||
" Then correct the indentation of any JSX following '/>'.
|
||||
if getline(v:lnum - 1) =~? s:sctag
|
||||
" Then correct the indentation of any JSX following '/>' or '>'.
|
||||
if getline(v:lnum - 1) =~? s:endtag
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
else
|
||||
|
||||
97
after/indent/objc.vim
Normal file
97
after/indent/objc.vim
Normal file
@@ -0,0 +1,97 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Objective-C
|
||||
" Maintainer: Bjorn Winckler <bjorn.winckler@gmail.com>
|
||||
" Last Change: 2012 Jan 01
|
||||
|
||||
" Ensure 'cpo' is set to Vim default values and restore later
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
"if exists("b:did_indent")
|
||||
" finish
|
||||
"endif
|
||||
"let b:did_indent = 1
|
||||
"setlocal cindent
|
||||
|
||||
setl indentkeys=0{,0},:,0#,!^F,o,O,e,<:>
|
||||
|
||||
setlocal indentexpr=GetObjCIndentImproved()
|
||||
|
||||
" Top level statements which should not be indented, and which should not
|
||||
" cause next (non-blank) line to be indented either.
|
||||
let s:topLev = '^\s*@\%(class\|end\|implementation\|interface\|protocol\|\)\>'
|
||||
|
||||
function! GetObjCIndentImproved()
|
||||
" NOTE: Ignore leading white space to avoid having to deal with space vs.
|
||||
" tab issues. Rely on the indent() function instead.
|
||||
let thisLine = substitute(getline(v:lnum), '^\s*', '', '')
|
||||
|
||||
if thisLine =~# s:topLev || getline(prevnonblank(v:lnum - 1)) =~# s:topLev
|
||||
return 0
|
||||
endif
|
||||
|
||||
" If current line looks like an argument to a message dispatch, then line
|
||||
" up colon with previous line. This will indent the second line so that
|
||||
" the colons line up in
|
||||
"
|
||||
" [obj firstParameter:value
|
||||
" paramB:value2];
|
||||
"
|
||||
" but it will not line up colons in
|
||||
"
|
||||
" if ([obj something:here])
|
||||
" [obj other:here];
|
||||
"
|
||||
let thisColon = match(thisLine, '^\s*\K\k*\zs:')
|
||||
if thisColon > 0
|
||||
let prevLine = substitute(getline(v:lnum - 1), '^\s*', '', '')
|
||||
let prevColon = match(prevLine, ':')
|
||||
if prevColon > 0
|
||||
" Try to align colons, always making sure line is indented at least
|
||||
" one shiftwidth more than the indentation at the beginning of the
|
||||
" message. Avoids situations like this:
|
||||
"
|
||||
" if ([obj a:x
|
||||
" aLongParameter:y])
|
||||
"
|
||||
let [lnum,lcol] = searchpairpos('\[', '', '\]', 'b', 0,
|
||||
\ max([1, v:lnum - 10]))
|
||||
let minInd = &sw + (lnum > 0 ? indent(lnum) : 0)
|
||||
let alignedInd = indent(v:lnum - 1) + prevColon - thisColon
|
||||
return alignedInd > minInd ? alignedInd : minInd
|
||||
endif
|
||||
endif
|
||||
|
||||
let prevLnum = v:lnum - 1
|
||||
let ind = indent(prevLnum)
|
||||
|
||||
" Indent one shiftwidth after opening block, e.g.:
|
||||
"
|
||||
" call_func_with_block(param, ^{
|
||||
" do_stuff();
|
||||
" });
|
||||
"
|
||||
let blockPat = '\^\s*\(([^)]*)\)\?\s*{$'
|
||||
if thisLine =~ '^}'
|
||||
norm '^%'
|
||||
if getline(".") =~ blockPat
|
||||
return indent(".")
|
||||
endif
|
||||
endif
|
||||
|
||||
if getline(prevLnum) =~ blockPat
|
||||
return ind + &sw
|
||||
endif
|
||||
|
||||
return cindent(v:lnum)
|
||||
endfunction
|
||||
|
||||
|
||||
" Restore 'cpo' options
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
||||
@@ -1,37 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vimscript file
|
||||
"
|
||||
" Set up a bunch of configuration variables.
|
||||
"
|
||||
" Also check (if desired) whether or not the @jsx pragma is correctly included
|
||||
" in '%'. Set the result in b:jsx_pragma_found.
|
||||
"
|
||||
" Language: JSX (JavaScript)
|
||||
" Maintainer: Max Wang <mxawng@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Only check once.
|
||||
if exists('b:jsx_pragma_found')
|
||||
finish
|
||||
endif
|
||||
|
||||
" Whether the .jsx extension is required to enable JSX syntax/indent.
|
||||
if !exists('g:jsx_ext_required')
|
||||
let g:jsx_ext_required = 1
|
||||
endif
|
||||
|
||||
" Whether the @jsx pragma is required to enable JSX syntax/indent.
|
||||
if !exists('g:jsx_pragma_required')
|
||||
let g:jsx_pragma_required = 0
|
||||
endif
|
||||
if !g:jsx_pragma_required | finish | endif
|
||||
|
||||
" Look for the @jsx pragma. It must be included in a docblock comment before
|
||||
" anything else in the file (except whitespace).
|
||||
let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/'
|
||||
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
|
||||
|
||||
endif
|
||||
@@ -36,22 +36,56 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
||||
|
||||
" Functions
|
||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
||||
syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen
|
||||
syn match cCustomFunc "\w\+\s*(\@="
|
||||
hi def link cCustomFunc Function
|
||||
|
||||
" Template functions
|
||||
if exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_template_highlight
|
||||
syn region cCustomAngleBrackets matchgroup=AngleBracketContents start="\v%(<operator\_s*)@<!%(%(\_i|template\_s*)@<=\<[<=]@!|\<@<!\<[[:space:]<=]@!)" end='>' contains=@cppSTLgroup,cppStructure,cType,cCustomClass,cCustomAngleBrackets,cNumbers
|
||||
syn match cCustomBrack "<\|>" contains=cCustomAngleBrackets
|
||||
syn match cCustomTemplateFunc "\w\+\s*<.*>(\@=" contains=cCustomBrack,cCustomAngleBrackets
|
||||
hi def link cCustomTemplateFunc Function
|
||||
endif
|
||||
|
||||
" Class and namespace scope
|
||||
if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight
|
||||
syn match cCustomScope "::"
|
||||
syn match cCustomClass "\w\+\s*::" contains=cCustomScope
|
||||
hi def link cCustomClass Function " disabled for now
|
||||
syn match cCustomClass "\w\+\s*::"
|
||||
\contains=cCustomScope
|
||||
" hi def link cCustomClass Function " disabled for now
|
||||
syn match cCustomClass "\<\u\w*\s*\>"
|
||||
endif
|
||||
|
||||
" Template functions
|
||||
if exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_template_highlight
|
||||
|
||||
syn match cCustomAngleBracketStart "<\_[^;()]\{-}>" contained
|
||||
\contains=cCustomAngleBracketStart, cCustomAngleBracketEnd
|
||||
hi def link cCustomAngleBracketStart cCustomAngleBracketContent
|
||||
|
||||
syn match cCustomAngleBracketEnd ">\_[^<>;()]\{-}>" contained
|
||||
\contains=cCustomAngleBracketEnd
|
||||
hi def link cCustomAngleBracketEnd cCustomAngleBracketContent
|
||||
|
||||
syn match cCustomTemplateFunc "\<\l\w*\s*<\_[^;()]\{-}>(\@="hs=s,he=e-1
|
||||
\contains=cCustomAngleBracketStart
|
||||
hi def link cCustomTemplateFunc cCustomFunc
|
||||
|
||||
syn match cCustomTemplateClass "\<\w\+\s*<\_[^;()]\{-}>"
|
||||
\contains=cCustomAngleBracketStart,cCustomTemplateFunc
|
||||
hi def link cCustomTemplateClass cCustomClass
|
||||
|
||||
|
||||
" Remove 'template' from cppStructure and use a custom match
|
||||
syn clear cppStructure
|
||||
syn keyword cppStructure class typename namespace
|
||||
|
||||
syn match cCustomTemplate "\<template\>"
|
||||
hi def link cCustomTemplate cppStructure
|
||||
syn match cTemplateDeclare "\<template\_s*<\_[^;()]\{-}>"
|
||||
\contains=cppStructure,cCustomTemplate,cCustomAngleBracketStart
|
||||
|
||||
" Remove 'operator' from cppStructure and use a custom match
|
||||
syn clear cppOperator
|
||||
syn keyword cppOperator typeid
|
||||
syn keyword cppOperator and bitor or xor compl bitand and_eq or_eq xor_eq not not_eq
|
||||
|
||||
syn match cCustomOperator "\<operator\>"
|
||||
hi def link cCustomOperator cppStructure
|
||||
syn match cTemplateOperatorDeclare "\<operator\_s*<\_[^;()]\{-}>[<>]=\?"
|
||||
\contains=cppOperator,cCustomOperator,cCustomAngleBracketStart
|
||||
endif
|
||||
|
||||
" Alternative syntax that is used in:
|
||||
@@ -136,7 +170,6 @@ syntax keyword cppSTLfunctional binary_negate
|
||||
syntax keyword cppSTLfunctional bit_and
|
||||
syntax keyword cppSTLfunctional bit_not
|
||||
syntax keyword cppSTLfunctional bit_or
|
||||
syntax keyword cppSTLfunctional bit_xor
|
||||
syntax keyword cppSTLfunctional divides
|
||||
syntax keyword cppSTLfunctional equal_to
|
||||
syntax keyword cppSTLfunctional greater
|
||||
|
||||
@@ -11,13 +11,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" Do nothing if we don't find the @jsx pragma (and we care).
|
||||
exec 'source '.fnameescape(expand('<sfile>:p:h:h').'/jsx-config.vim')
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | finish | endif
|
||||
|
||||
" Do nothing if we don't have the .jsx extension (and we care).
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | finish | endif
|
||||
|
||||
" Prologue; load in XML syntax.
|
||||
if exists('b:current_syntax')
|
||||
let s:current_syntax=b:current_syntax
|
||||
@@ -28,20 +21,45 @@ if exists('s:current_syntax')
|
||||
let b:current_syntax=s:current_syntax
|
||||
endif
|
||||
|
||||
" Officially, vim-jsx depends on the pangloss/vim-javascript syntax package
|
||||
" (and is tested against it exclusively). However, in practice, we make some
|
||||
" effort towards compatibility with other packages.
|
||||
"
|
||||
" These are the plugin-to-syntax-element correspondences:
|
||||
"
|
||||
" - pangloss/vim-javascript: jsBlock, jsExpression
|
||||
" - jelera/vim-javascript-syntax: javascriptBlock
|
||||
" - othree/yajs.vim: javascriptNoReserved
|
||||
|
||||
|
||||
" JSX attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
|
||||
" JSX child blocks behave just like JSX attributes, except that (a) they are
|
||||
" syntactically distinct, and (b) they need the syn-extend argument, or else
|
||||
" nested XML end-tag patterns may end the outer jsxRegion.
|
||||
syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
\ extend
|
||||
|
||||
" Highlight JSX regions as XML; recursively match.
|
||||
syn region jsxRegion contains=@XMLSyntax,jsxRegion,jsBlock,javascriptBlock
|
||||
\ start=+<\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
||||
"
|
||||
" Note that we prohibit JSX tags from having a < or word character immediately
|
||||
" preceding it, to avoid conflicts with, respectively, the left shift operator
|
||||
" and generic Flow type annotations (http://flowtype.org/).
|
||||
syn region jsxRegion
|
||||
\ contains=@XMLSyntax,jsxRegion,jsxChild,jsBlock,javascriptBlock
|
||||
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
||||
\ skip=+<!--\_.\{-}-->+
|
||||
\ end=+</\z1\_\s\{-}>+
|
||||
\ end=+/>+
|
||||
\ keepend
|
||||
\ extend
|
||||
|
||||
" JSX attributes should color as JS. Note the trivial end pattern; we let
|
||||
" jsBlock take care of ending the region.
|
||||
syn region xmlString contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
|
||||
" Add jsxRegion to the lowest-level JS syntax cluster.
|
||||
syn cluster jsExpression add=jsxRegion
|
||||
|
||||
" Allow jsxRegion to contain reserved words.
|
||||
syn cluster javascriptNoReserved add=jsxRegion
|
||||
|
||||
endif
|
||||
|
||||
23
after/syntax/objc.vim
Normal file
23
after/syntax/objc.vim
Normal file
@@ -0,0 +1,23 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" ARC type modifiers
|
||||
syn keyword objcTypeModifier __bridge __bridge_retained __bridge_transfer __autoreleasing __strong __weak __unsafe_unretained
|
||||
|
||||
" Block modifiers
|
||||
syn keyword objcTypeModifier __block
|
||||
|
||||
" Remote messaging modifiers
|
||||
syn keyword objcTypeModifier byref
|
||||
|
||||
" Property keywords - these are only highlighted inside '@property (...)'
|
||||
syn keyword objcPropertyAttribute contained getter setter readwrite readonly strong weak copy assign retain nonatomic
|
||||
syn match objcProperty display "^\s*@property\>\s*([^)]*)" contains=objcPropertyAttribute
|
||||
|
||||
" The @property directive must be defined after objcProperty or it won't be
|
||||
" highlighted
|
||||
syn match objcDirective "@property\|@synthesize\|@dynamic\|@package"
|
||||
|
||||
" Highlight property attributes as if they were type modifiers
|
||||
hi def link objcPropertyAttribute objcTypeModifier
|
||||
|
||||
endif
|
||||
@@ -1,11 +1,11 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
|
||||
if !exists('g:rust_conceal') || !has('conceal') || &enc != 'utf-8'
|
||||
if !exists('g:rust_conceal') || g:rust_conceal == 0 || !has('conceal') || &enc != 'utf-8'
|
||||
finish
|
||||
endif
|
||||
|
||||
" For those who don't want to see `::`...
|
||||
if exists('g:rust_conceal_mod_path')
|
||||
if exists('g:rust_conceal_mod_path') && g:rust_conceal_mod_path != 0
|
||||
syn match rustNiceOperator "::" conceal cchar=ㆍ
|
||||
endif
|
||||
|
||||
@@ -20,7 +20,7 @@ syn match rustNiceOperator "=>" contains=rustFatRightArrowHead,rustFatRightArrow
|
||||
syn match rustNiceOperator /\<\@!_\(_*\>\)\@=/ conceal cchar=′
|
||||
|
||||
" For those who don't want to see `pub`...
|
||||
if exists('g:rust_conceal_pub')
|
||||
if exists('g:rust_conceal_pub') && g:rust_conceal_pub != 0
|
||||
syn match rustPublicSigil contained "pu" conceal cchar=*
|
||||
syn match rustPublicRest contained "b" conceal cchar=
|
||||
syn match rustNiceOperator "pub " contains=rustPublicSigil,rustPublicRest
|
||||
@@ -28,7 +28,7 @@ endif
|
||||
|
||||
hi link rustNiceOperator Operator
|
||||
|
||||
if !exists('g:rust_conceal_mod_path')
|
||||
if !exists('g:rust_conceal_mod_path') && g:rust_conceal_mod_path != 0
|
||||
hi! link Conceal Operator
|
||||
endif
|
||||
|
||||
|
||||
64
after/syntax/yaml.vim
Normal file
64
after/syntax/yaml.vim
Normal file
@@ -0,0 +1,64 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1
|
||||
|
||||
" To make this file do stuff, add something like the following (without the
|
||||
" leading ") to your ~/.vimrc:
|
||||
" au BufNewFile,BufRead *.yaml,*.yml so ~/src/PyYaml/YAML.vim
|
||||
|
||||
" Vim syntax/macro file
|
||||
" Language: YAML
|
||||
" Author: Igor Vergeichik <iverg@mail.ru>
|
||||
" Sponsor: Tom Sawyer <transami@transami.net>
|
||||
" Stayven: Ryan King <jking@panoptic.com>
|
||||
" Copyright (c) 2002 Tom Saywer
|
||||
|
||||
" Add an item to a gangly list:
|
||||
"map , o<bs><bs><bs><bs>-<esc>o
|
||||
" Convert to Canonical form:
|
||||
"map \c :%!python -c 'from yaml.redump import redump; import sys; print redump(sys.stdin.read()).rstrip()'
|
||||
|
||||
if version < 600
|
||||
syntax clear
|
||||
endif
|
||||
syntax clear
|
||||
|
||||
syn match yamlDelimiter "[:,-]"
|
||||
syn match yamlBlock "[\[\]\{\}\|\>]"
|
||||
syn match yamlOperator "[?^+-]\|=>"
|
||||
|
||||
syn region yamlComment start="\#" end="$"
|
||||
syn match yamlIndicator "#YAML:\S\+"
|
||||
|
||||
syn region yamlString start="'" end="'" skip="\\'"
|
||||
syn region yamlString start='"' end='"' skip='\\"' contains=yamlEscape
|
||||
syn match yamlEscape +\\[abfnrtv'"\\]+ contained
|
||||
syn match yamlEscape "\\\o\o\=\o\=" contained
|
||||
syn match yamlEscape "\\x\x\+" contained
|
||||
|
||||
syn match yamlType "!\S\+"
|
||||
|
||||
syn keyword yamlConstant NULL Null null NONE None none NIL Nil nil
|
||||
syn keyword yamlConstant TRUE True true YES Yes yes ON On on
|
||||
syn keyword yamlConstant FALSE False false NO No no OFF Off off
|
||||
|
||||
syn match yamlKey "\w\+\ze\s*:"
|
||||
syn match yamlAnchor "&\S\+"
|
||||
syn match yamlAlias "*\S\+"
|
||||
|
||||
" Setupt the hilighting links
|
||||
|
||||
hi link yamlConstant Keyword
|
||||
hi link yamlIndicator PreCondit
|
||||
hi link yamlAnchor Function
|
||||
hi link yamlAlias Function
|
||||
hi link yamlKey Identifier
|
||||
hi link yamlType Type
|
||||
|
||||
hi link yamlComment Comment
|
||||
hi link yamlBlock Operator
|
||||
hi link yamlOperator Operator
|
||||
hi link yamlDelimiter Delimiter
|
||||
hi link yamlString String
|
||||
hi link yamlEscape Special
|
||||
|
||||
|
||||
endif
|
||||
332
autoload/crystal_lang.vim
Normal file
332
autoload/crystal_lang.vim
Normal file
@@ -0,0 +1,332 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:V = vital#of('crystal')
|
||||
let s:P = s:V.import('Process')
|
||||
let s:J = s:V.import('Web.JSON')
|
||||
let s:C = s:V.import('ColorEcho')
|
||||
|
||||
function! s:echo_error(msg, ...) abort
|
||||
echohl ErrorMsg
|
||||
if a:0 == 0
|
||||
echomsg a:msg
|
||||
else
|
||||
echomsg call('printf', [a:msg] + a:000)
|
||||
endif
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
function! s:run_cmd(cmd) abort
|
||||
if !executable(g:crystal_compiler_command)
|
||||
throw "vim-crystal: Error: '" . g:crystal_compiler_command . "' command is not found."
|
||||
endif
|
||||
return s:P.system(a:cmd)
|
||||
endfunction
|
||||
|
||||
function! s:find_root_by_spec(d) abort
|
||||
let dir = finddir('spec', a:d . ';')
|
||||
if dir ==# ''
|
||||
return ''
|
||||
endif
|
||||
|
||||
" Note: ':h:h' for {root}/spec/ -> {root}/spec -> {root}
|
||||
return fnamemodify(dir, ':p:h:h')
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#entrypoint_for(file_path) abort
|
||||
let parent_dir = fnamemodify(a:file_path, ':p:h')
|
||||
let root_dir = s:find_root_by_spec(parent_dir)
|
||||
if root_dir ==# ''
|
||||
" No spec diretory found. No need to make temporary file
|
||||
return a:file_path
|
||||
endif
|
||||
|
||||
let temp_name = root_dir . '/__vim-crystal-temporary-entrypoint-' . fnamemodify(a:file_path, ':t')
|
||||
let contents = [
|
||||
\ 'require "spec"',
|
||||
\ 'require "./spec/**"',
|
||||
\ printf('require "./%s"', fnamemodify(a:file_path, ':p')[strlen(root_dir)+1 : ])
|
||||
\ ]
|
||||
|
||||
let result = writefile(contents, temp_name)
|
||||
if result == -1
|
||||
" Note: When writefile() failed
|
||||
return a:file_path
|
||||
endif
|
||||
|
||||
return temp_name
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#tool(name, file, pos, option_str) abort
|
||||
let entrypoint = crystal_lang#entrypoint_for(a:file)
|
||||
let cmd = printf(
|
||||
\ '%s tool %s --no-color %s --cursor %s:%d:%d %s',
|
||||
\ g:crystal_compiler_command,
|
||||
\ a:name,
|
||||
\ a:option_str,
|
||||
\ a:file,
|
||||
\ a:pos[1],
|
||||
\ a:pos[2],
|
||||
\ entrypoint
|
||||
\ )
|
||||
|
||||
try
|
||||
let output = s:run_cmd(cmd)
|
||||
return {'failed': s:P.get_last_status(), 'output': output}
|
||||
finally
|
||||
" Note:
|
||||
" If the entry point is temporary file, delete it finally.
|
||||
if a:file !=# entrypoint
|
||||
call delete(entrypoint)
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" `pos` is assumed a returned value from getpos()
|
||||
function! crystal_lang#impl(file, pos, option_str) abort
|
||||
return crystal_lang#tool('implementations', a:file, a:pos, a:option_str)
|
||||
endfunction
|
||||
|
||||
function! s:jump_to_impl(impl) abort
|
||||
execute 'edit' a:impl.filename
|
||||
call cursor(a:impl.line, a:impl.column)
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#jump_to_definition(file, pos) abort
|
||||
echo 'analyzing definitions under cursor...'
|
||||
|
||||
let cmd_result = crystal_lang#impl(a:file, a:pos, '--format json')
|
||||
if cmd_result.failed
|
||||
return s:echo_error(cmd_result.output)
|
||||
endif
|
||||
|
||||
let impl = s:J.decode(cmd_result.output)
|
||||
if impl.status !=# 'ok'
|
||||
return s:echo_error(impl.message)
|
||||
endif
|
||||
|
||||
if len(impl.implementations) == 1
|
||||
call s:jump_to_impl(impl.implementations[0])
|
||||
return
|
||||
endif
|
||||
|
||||
let message = "Multiple definitions detected. Choose a number\n\n"
|
||||
for idx in range(len(impl.implementations))
|
||||
let i = impl.implementations[idx]
|
||||
let message .= printf("[%d] %s:%d:%d\n", idx, i.filename, i.line, i.column)
|
||||
endfor
|
||||
let message .= "\n"
|
||||
let idx = str2nr(input(message, "\n> "))
|
||||
call s:jump_to_impl(impl.implementations[idx])
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#context(file, pos, option_str) abort
|
||||
return crystal_lang#tool('context', a:file, a:pos, a:option_str)
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#type_hierarchy(file, option_str) abort
|
||||
let cmd = printf(
|
||||
\ '%s tool hierarchy --no-color %s %s',
|
||||
\ g:crystal_compiler_command,
|
||||
\ a:option_str,
|
||||
\ a:file
|
||||
\ )
|
||||
|
||||
return s:run_cmd(cmd)
|
||||
endfunction
|
||||
|
||||
function! s:find_completion_start() abort
|
||||
let c = col('.')
|
||||
if c <= 1
|
||||
return -1
|
||||
endif
|
||||
|
||||
let line = getline('.')[:c-2]
|
||||
return match(line, '\w\+$')
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#complete(findstart, base) abort
|
||||
if a:findstart
|
||||
echom 'find start'
|
||||
return s:find_completion_start()
|
||||
endif
|
||||
|
||||
let cmd_result = crystal_lang#context(expand('%'), getpos('.'), '--format json')
|
||||
if cmd_result.failed
|
||||
return
|
||||
endif
|
||||
|
||||
let contexts = s:J.decode(cmd_result.output)
|
||||
if contexts.status !=# 'ok'
|
||||
return
|
||||
endif
|
||||
|
||||
let candidates = []
|
||||
|
||||
for c in contexts.contexts
|
||||
for [name, desc] in items(c)
|
||||
let candidates += [{
|
||||
\ 'word': name,
|
||||
\ 'menu': ': ' . desc . ' [var]',
|
||||
\ }]
|
||||
endfor
|
||||
endfor
|
||||
|
||||
return candidates
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#get_spec_switched_path(absolute_path) abort
|
||||
let base = fnamemodify(a:absolute_path, ':t:r')
|
||||
|
||||
" TODO: Make cleverer
|
||||
if base =~# '_spec$'
|
||||
let parent = fnamemodify(substitute(a:absolute_path, '/spec/', '/src/', ''), ':h')
|
||||
return parent . '/' . matchstr(base, '.\+\ze_spec$') . '.cr'
|
||||
else
|
||||
let parent = fnamemodify(substitute(a:absolute_path, '/src/', '/spec/', ''), ':h')
|
||||
return parent . '/' . base . '_spec.cr'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#switch_spec_file(...) abort
|
||||
let path = a:0 == 0 ? expand('%:p') : fnamemodify(a:1, ':p')
|
||||
if path !~# '.cr$'
|
||||
return s:echo_error('Not crystal source file: ' . path)
|
||||
endif
|
||||
|
||||
execute 'edit!' crystal_lang#get_spec_switched_path(path)
|
||||
endfunction
|
||||
|
||||
function! s:run_spec(root, path, ...) abort
|
||||
" Note:
|
||||
" `crystal spec` can't understand absolute path.
|
||||
let cmd = printf(
|
||||
\ '%s spec %s%s',
|
||||
\ g:crystal_compiler_command,
|
||||
\ a:path,
|
||||
\ a:0 == 0 ? '' : (':' . a:1)
|
||||
\ )
|
||||
|
||||
let saved_cwd = getcwd()
|
||||
let cd = haslocaldir() ? 'lcd' : 'cd'
|
||||
try
|
||||
execute cd a:root
|
||||
call s:C.echo(s:run_cmd(cmd))
|
||||
finally
|
||||
execute cd saved_cwd
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#run_all_spec(...) abort
|
||||
let path = a:0 == 0 ? expand('%:p:h') : a:1
|
||||
let root_path = s:find_root_by_spec(path)
|
||||
if root_path ==# ''
|
||||
return s:echo_error("'spec' directory is not found")
|
||||
endif
|
||||
call s:run_spec(root_path, 'spec')
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#run_current_spec(...) abort
|
||||
" /foo/bar/src/poyo.cr
|
||||
let path = a:0 == 0 ? expand('%:p') : fnamemodify(a:1, ':p')
|
||||
if path !~# '.cr$'
|
||||
return s:echo_error('Not crystal source file: ' . path)
|
||||
endif
|
||||
|
||||
" /foo/bar/src
|
||||
let source_dir = fnamemodify(path, ':h')
|
||||
|
||||
" /foo/bar
|
||||
let root_dir = s:find_root_by_spec(source_dir)
|
||||
if root_dir ==# ''
|
||||
return s:echo_error("'spec' directory is not found")
|
||||
endif
|
||||
|
||||
" src
|
||||
let rel_path = source_dir[strlen(root_dir)+1 : ]
|
||||
|
||||
if path =~# '_spec.cr$'
|
||||
call s:run_spec(root_dir, path[strlen(root_dir)+1 : ], line('.'))
|
||||
else
|
||||
let spec_path = substitute(rel_path, '^src', 'spec', '') . '/' . fnamemodify(path, ':t:r') . '_spec.cr'
|
||||
if !filereadable(root_dir . '/' . spec_path)
|
||||
return s:echo_error('Error: Could not find a spec source corresponding to ' . path)
|
||||
endif
|
||||
call s:run_spec(root_dir, spec_path)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#format_string(code, ...) abort
|
||||
let cmd = printf(
|
||||
\ '%s tool format --no-color %s -',
|
||||
\ g:crystal_compiler_command,
|
||||
\ get(a:, 1, '')
|
||||
\ )
|
||||
let output = s:P.system(cmd, a:code)
|
||||
if s:P.get_last_status()
|
||||
throw 'vim-crystal: Error on formatting: ' . output
|
||||
endif
|
||||
return output
|
||||
endfunction
|
||||
|
||||
function! s:get_saved_states() abort
|
||||
let result = {}
|
||||
let fname = bufname('%')
|
||||
let current_winnr = winnr()
|
||||
for i in range(1, winnr('$'))
|
||||
let bufnr = winbufnr(i)
|
||||
if bufnr == -1
|
||||
continue
|
||||
endif
|
||||
if bufname(bufnr) ==# fname
|
||||
execute i 'wincmd w'
|
||||
let result[i] = {
|
||||
\ 'pos': getpos('.'),
|
||||
\ 'screen': winsaveview()
|
||||
\ }
|
||||
endif
|
||||
endfor
|
||||
execute current_winnr 'wincmd w'
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! crystal_lang#format(option_str) abort
|
||||
if !executable(g:crystal_compiler_command)
|
||||
" Finish command silently
|
||||
return
|
||||
endif
|
||||
|
||||
let formatted = crystal_lang#format_string(join(getline(1, '$'), "\n"), a:option_str)
|
||||
let formatted = substitute(formatted, '\n$', '', '')
|
||||
|
||||
let sel_save = &l:selection
|
||||
let ve_save = &virtualedit
|
||||
let &l:selection = 'inclusive'
|
||||
let &virtualedit = ''
|
||||
let [save_g_reg, save_g_regtype] = [getreg('g'), getregtype('g')]
|
||||
let windows_save = s:get_saved_states()
|
||||
|
||||
try
|
||||
call setreg('g', formatted, 'v')
|
||||
silent normal! ggvG$"gp
|
||||
finally
|
||||
call setreg('g', save_g_reg, save_g_regtype)
|
||||
let &l:selection = sel_save
|
||||
let &virtualedit = ve_save
|
||||
let winnr = winnr()
|
||||
for winnr in keys(windows_save)
|
||||
let w = windows_save[winnr]
|
||||
execute winnr 'wincmd w'
|
||||
call setpos('.', w.pos)
|
||||
call winrestview(w.screen)
|
||||
endfor
|
||||
execute winnr 'wincmd w'
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
||||
70
autoload/dart.vim
Normal file
70
autoload/dart.vim
Normal file
@@ -0,0 +1,70 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dart') == -1
|
||||
|
||||
|
||||
function! s:error(text) abort
|
||||
echohl Error
|
||||
echomsg printf('[dart-vim-plugin] %s', a:text)
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
function! s:cexpr(errorformat, joined_lines) abort
|
||||
let temp_errorfomat = &errorformat
|
||||
try
|
||||
let &errorformat = a:errorformat
|
||||
cexpr a:joined_lines
|
||||
copen
|
||||
finally
|
||||
let &errorformat = temp_errorfomat
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! dart#fmt(q_args) abort
|
||||
if executable('dartfmt')
|
||||
let path = expand('%:p:gs:\:/:')
|
||||
if filereadable(path)
|
||||
let joined_lines = system(printf('dartfmt %s %s', a:q_args, shellescape(path)))
|
||||
if 0 == v:shell_error
|
||||
silent % delete _
|
||||
silent put=joined_lines
|
||||
silent 1 delete _
|
||||
else
|
||||
call s:cexpr('line %l\, column %c of %f: %m', joined_lines)
|
||||
endif
|
||||
else
|
||||
call s:error(printf('cannot read a file: "%s"', path))
|
||||
endif
|
||||
else
|
||||
call s:error('cannot execute binary file: dartfmt')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! dart#analyzer(q_args) abort
|
||||
if executable('dartanalyzer')
|
||||
let path = expand('%:p:gs:\:/:')
|
||||
if filereadable(path)
|
||||
let joined_lines = system(printf('dartanalyzer %s %s', a:q_args, shellescape(path)))
|
||||
call s:cexpr('%m (%f\, line %l\, col %c)', joined_lines)
|
||||
else
|
||||
call s:error(printf('cannot read a file: "%s"', path))
|
||||
endif
|
||||
else
|
||||
call s:error('cannot execute binary file: dartanalyzer')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! dart#tojs(q_args) abort
|
||||
if executable('dart2js')
|
||||
let path = expand('%:p:gs:\:/:')
|
||||
if filereadable(path)
|
||||
let joined_lines = system(printf('dart2js %s %s', a:q_args, shellescape(path)))
|
||||
call s:cexpr('%m (%f\, line %l\, col %c)', joined_lines)
|
||||
else
|
||||
call s:error(printf('cannot read a file: "%s"', path))
|
||||
endif
|
||||
else
|
||||
call s:error('cannot execute binary file: dartanalyzer')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
endif
|
||||
12
autoload/elm/io.vim
Normal file
12
autoload/elm/io.vim
Normal file
@@ -0,0 +1,12 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" System IO
|
||||
|
||||
" Craft a system command and run it, returning the output.
|
||||
function! elm#io#system(program, args)
|
||||
let cmd ="which " . a:program . " && " . a:program . " " . a:args
|
||||
return system(cmd)
|
||||
endfunction
|
||||
|
||||
|
||||
endif
|
||||
70
autoload/fish.vim
Normal file
70
autoload/fish.vim
Normal file
@@ -0,0 +1,70 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
function! fish#Indent()
|
||||
let l:prevlnum = prevnonblank(v:lnum - 1)
|
||||
if l:prevlnum ==# 0
|
||||
return 0
|
||||
endif
|
||||
let l:indent = 0
|
||||
let l:prevline = getline(l:prevlnum)
|
||||
if l:prevline =~# '\v^\s*switch>'
|
||||
let l:indent = &shiftwidth * 2
|
||||
elseif l:prevline =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
|
||||
let l:indent = &shiftwidth
|
||||
endif
|
||||
let l:line = getline(v:lnum)
|
||||
if l:line =~# '\v^\s*end>'
|
||||
return indent(v:lnum) - (l:indent ==# 0 ? &shiftwidth : l:indent)
|
||||
elseif l:line =~# '\v^\s*%(case|else)>'
|
||||
return indent(v:lnum) - &shiftwidth
|
||||
endif
|
||||
return indent(l:prevlnum) + l:indent
|
||||
endfunction
|
||||
|
||||
function! fish#Format()
|
||||
if mode() =~# '\v^%(i|R)$'
|
||||
return 1
|
||||
else
|
||||
let l:command = v:lnum.','.(v:lnum+v:count-1).'!fish_indent'
|
||||
echo l:command
|
||||
execute l:command
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! fish#Fold()
|
||||
let l:line = getline(v:lnum)
|
||||
if l:line =~# '\v^\s*%(begin|if|while|for|function|switch)>'
|
||||
return 'a1'
|
||||
elseif l:line =~# '\v^\s*end>'
|
||||
return 's1'
|
||||
else
|
||||
return '='
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! fish#Complete(findstart, base)
|
||||
if a:findstart
|
||||
return getline('.') =~# '\v^\s*$' ? -1 : 0
|
||||
else
|
||||
if empty(a:base)
|
||||
return []
|
||||
endif
|
||||
let l:results = []
|
||||
let l:completions =
|
||||
\ system('fish -c "complete -C'.shellescape(a:base).'"')
|
||||
let l:cmd = substitute(a:base, '\v\S+$', '', '')
|
||||
for l:line in split(l:completions, '\n')
|
||||
let l:tokens = split(l:line, '\t')
|
||||
call add(l:results, {'word': l:cmd.l:tokens[0],
|
||||
\'abbr': l:tokens[0],
|
||||
\'menu': get(l:tokens, 1, '')})
|
||||
endfor
|
||||
return l:results
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! fish#errorformat()
|
||||
return '%Afish: %m,%-G%*\\ ^,%-Z%f (line %l):%s'
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -36,72 +36,74 @@ endfunction
|
||||
" Run {{{1
|
||||
|
||||
function! rust#Run(bang, args)
|
||||
let args = s:ShellTokenize(a:args)
|
||||
if a:bang
|
||||
let idx = index(a:args, '--')
|
||||
let idx = index(l:args, '--')
|
||||
if idx != -1
|
||||
let rustc_args = idx == 0 ? [] : a:args[:idx-1]
|
||||
let args = a:args[idx+1:]
|
||||
let rustc_args = idx == 0 ? [] : l:args[:idx-1]
|
||||
let args = l:args[idx+1:]
|
||||
else
|
||||
let rustc_args = a:args
|
||||
let rustc_args = l:args
|
||||
let args = []
|
||||
endif
|
||||
else
|
||||
let rustc_args = []
|
||||
let args = a:args
|
||||
endif
|
||||
|
||||
let b:rust_last_rustc_args = rustc_args
|
||||
let b:rust_last_args = args
|
||||
let b:rust_last_rustc_args = l:rustc_args
|
||||
let b:rust_last_args = l:args
|
||||
|
||||
call s:WithPath(function("s:Run"), rustc_args, args)
|
||||
endfunction
|
||||
|
||||
function! s:Run(path, rustc_args, args)
|
||||
try
|
||||
let exepath = tempname()
|
||||
if has('win32')
|
||||
let exepath .= '.exe'
|
||||
endif
|
||||
function! s:Run(dict, rustc_args, args)
|
||||
let exepath = a:dict.tmpdir.'/'.fnamemodify(a:dict.path, ':t:r')
|
||||
if has('win32')
|
||||
let exepath .= '.exe'
|
||||
endif
|
||||
|
||||
let rustc_args = [a:path, '-o', exepath] + a:rustc_args
|
||||
let relpath = get(a:dict, 'tmpdir_relpath', a:dict.path)
|
||||
let rustc_args = [relpath, '-o', exepath] + a:rustc_args
|
||||
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let output = system(shellescape(rustc) . " " . join(map(rustc_args, 'shellescape(v:val)')))
|
||||
if output != ''
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
endif
|
||||
if !v:shell_error
|
||||
exe '!' . shellescape(exepath) . " " . join(map(a:args, 'shellescape(v:val)'))
|
||||
endif
|
||||
finally
|
||||
if exists("exepath")
|
||||
silent! call delete(exepath)
|
||||
endif
|
||||
endtry
|
||||
let pwd = a:dict.istemp ? a:dict.tmpdir : ''
|
||||
let output = s:system(pwd, shellescape(rustc) . " " . join(map(rustc_args, 'shellescape(v:val)')))
|
||||
if output != ''
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
endif
|
||||
if !v:shell_error
|
||||
exe '!' . shellescape(exepath) . " " . join(map(a:args, 'shellescape(v:val)'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Expand {{{1
|
||||
|
||||
function! rust#Expand(bang, args)
|
||||
if a:bang && !empty(a:args)
|
||||
let pretty = a:args[0]
|
||||
let args = a:args[1:]
|
||||
let args = s:ShellTokenize(a:args)
|
||||
if a:bang && !empty(l:args)
|
||||
let pretty = remove(l:args, 0)
|
||||
else
|
||||
let pretty = "expanded"
|
||||
let args = a:args
|
||||
endif
|
||||
call s:WithPath(function("s:Expand"), pretty, args)
|
||||
endfunction
|
||||
|
||||
function! s:Expand(path, pretty, args)
|
||||
function! s:Expand(dict, pretty, args)
|
||||
try
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let args = [a:path, '--pretty', a:pretty] + a:args
|
||||
let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)")))
|
||||
if a:pretty =~? '^\%(everybody_loops$\|flowgraph=\)'
|
||||
let flag = '--xpretty'
|
||||
else
|
||||
let flag = '--pretty'
|
||||
endif
|
||||
let relpath = get(a:dict, 'tmpdir_relpath', a:dict.path)
|
||||
let args = [relpath, '-Z', 'unstable-options', l:flag, a:pretty] + a:args
|
||||
let pwd = a:dict.istemp ? a:dict.tmpdir : ''
|
||||
let output = s:system(pwd, shellescape(rustc) . " " . join(map(args, 'shellescape(v:val)')))
|
||||
if v:shell_error
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
@@ -115,6 +117,20 @@ function! s:Expand(path, pretty, args)
|
||||
setl buftype=nofile
|
||||
setl bufhidden=hide
|
||||
setl noswapfile
|
||||
" give the buffer a nice name
|
||||
let suffix = 1
|
||||
let basename = fnamemodify(a:dict.path, ':t:r')
|
||||
while 1
|
||||
let bufname = basename
|
||||
if suffix > 1 | let bufname .= ' ('.suffix.')' | endif
|
||||
let bufname .= '.pretty.rs'
|
||||
if bufexists(bufname)
|
||||
let suffix += 1
|
||||
continue
|
||||
endif
|
||||
exe 'silent noautocmd keepalt file' fnameescape(bufname)
|
||||
break
|
||||
endwhile
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
@@ -122,7 +138,7 @@ endfunction
|
||||
function! rust#CompleteExpand(lead, line, pos)
|
||||
if a:line[: a:pos-1] =~ '^RustExpand!\s*\S*$'
|
||||
" first argument and it has a !
|
||||
let list = ["normal", "expanded", "typed", "expanded,identified", "flowgraph="]
|
||||
let list = ["normal", "expanded", "typed", "expanded,identified", "flowgraph=", "everybody_loops"]
|
||||
if !empty(a:lead)
|
||||
call filter(list, "v:val[:len(a:lead)-1] == a:lead")
|
||||
endif
|
||||
@@ -135,72 +151,120 @@ endfunction
|
||||
" Emit {{{1
|
||||
|
||||
function! rust#Emit(type, args)
|
||||
call s:WithPath(function("s:Emit"), a:type, a:args)
|
||||
let args = s:ShellTokenize(a:args)
|
||||
call s:WithPath(function("s:Emit"), a:type, args)
|
||||
endfunction
|
||||
|
||||
function! s:Emit(path, type, args)
|
||||
function! s:Emit(dict, type, args)
|
||||
try
|
||||
let output_path = a:dict.tmpdir.'/output'
|
||||
|
||||
let rustc = exists("g:rustc_path") ? g:rustc_path : "rustc"
|
||||
|
||||
let args = [a:path, '--emit', a:type, '-o', '-'] + a:args
|
||||
let output = system(shellescape(rustc) . " " . join(map(args, "shellescape(v:val)")))
|
||||
if v:shell_error
|
||||
let relpath = get(a:dict, 'tmpdir_relpath', a:dict.path)
|
||||
let args = [relpath, '--emit', a:type, '-o', output_path] + a:args
|
||||
let pwd = a:dict.istemp ? a:dict.tmpdir : ''
|
||||
let output = s:system(pwd, shellescape(rustc) . " " . join(map(args, 'shellescape(v:val)')))
|
||||
if output != ''
|
||||
echohl WarningMsg
|
||||
echo output
|
||||
echohl None
|
||||
else
|
||||
endif
|
||||
if !v:shell_error
|
||||
new
|
||||
silent put =output
|
||||
exe 'silent keepalt read' fnameescape(output_path)
|
||||
1
|
||||
d
|
||||
if a:type == "ir"
|
||||
if a:type == "llvm-ir"
|
||||
setl filetype=llvm
|
||||
let extension = 'll'
|
||||
elseif a:type == "asm"
|
||||
setl filetype=asm
|
||||
let extension = 's'
|
||||
endif
|
||||
setl buftype=nofile
|
||||
setl bufhidden=hide
|
||||
setl noswapfile
|
||||
if exists('l:extension')
|
||||
" give the buffer a nice name
|
||||
let suffix = 1
|
||||
let basename = fnamemodify(a:dict.path, ':t:r')
|
||||
while 1
|
||||
let bufname = basename
|
||||
if suffix > 1 | let bufname .= ' ('.suffix.')' | endif
|
||||
let bufname .= '.'.extension
|
||||
if bufexists(bufname)
|
||||
let suffix += 1
|
||||
continue
|
||||
endif
|
||||
exe 'silent noautocmd keepalt file' fnameescape(bufname)
|
||||
break
|
||||
endwhile
|
||||
endif
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Utility functions {{{1
|
||||
|
||||
" Invokes func(dict, ...)
|
||||
" Where {dict} is a dictionary with the following keys:
|
||||
" 'path' - The path to the file
|
||||
" 'tmpdir' - The path to a temporary directory that will be deleted when the
|
||||
" function returns.
|
||||
" 'istemp' - 1 if the path is a file inside of {dict.tmpdir} or 0 otherwise.
|
||||
" If {istemp} is 1 then an additional key is provided:
|
||||
" 'tmpdir_relpath' - The {path} relative to the {tmpdir}.
|
||||
"
|
||||
" {dict.path} may be a path to a file inside of {dict.tmpdir} or it may be the
|
||||
" existing path of the current buffer. If the path is inside of {dict.tmpdir}
|
||||
" then it is guaranteed to have a '.rs' extension.
|
||||
function! s:WithPath(func, ...)
|
||||
let buf = bufnr('')
|
||||
let saved = {}
|
||||
let dict = {}
|
||||
try
|
||||
let save_write = &write
|
||||
let saved.write = &write
|
||||
set write
|
||||
let path = expand('%')
|
||||
let pathisempty = empty(path)
|
||||
if pathisempty || !save_write
|
||||
" use a temporary file named 'unnamed.rs' inside a temporary
|
||||
" directory. This produces better error messages
|
||||
let tmpdir = tempname()
|
||||
call mkdir(tmpdir)
|
||||
let dict.path = expand('%')
|
||||
let pathisempty = empty(dict.path)
|
||||
|
||||
let save_cwd = getcwd()
|
||||
silent exe 'lcd' fnameescape(tmpdir)
|
||||
" Always create a tmpdir in case the wrapped command wants it
|
||||
let dict.tmpdir = tempname()
|
||||
call mkdir(dict.tmpdir)
|
||||
|
||||
let path = 'unnamed.rs'
|
||||
if pathisempty || !saved.write
|
||||
let dict.istemp = 1
|
||||
" if we're doing this because of nowrite, preserve the filename
|
||||
if !pathisempty
|
||||
let filename = expand('%:t:r').".rs"
|
||||
else
|
||||
let filename = 'unnamed.rs'
|
||||
endif
|
||||
let dict.tmpdir_relpath = filename
|
||||
let dict.path = dict.tmpdir.'/'.filename
|
||||
|
||||
let save_mod = &mod
|
||||
let saved.mod = &mod
|
||||
set nomod
|
||||
|
||||
silent exe 'keepalt write! ' . fnameescape(path)
|
||||
silent exe 'keepalt write! ' . fnameescape(dict.path)
|
||||
if pathisempty
|
||||
silent keepalt 0file
|
||||
endif
|
||||
else
|
||||
let dict.istemp = 0
|
||||
update
|
||||
endif
|
||||
|
||||
call call(a:func, [path] + a:000)
|
||||
call call(a:func, [dict] + a:000)
|
||||
finally
|
||||
if exists("save_mod") | let &mod = save_mod | endif
|
||||
if exists("save_write") | let &write = save_write | endif
|
||||
if exists("save_cwd") | silent exe 'lcd' fnameescape(save_cwd) | endif
|
||||
if exists("tmpdir") | silent call s:RmDir(tmpdir) | endif
|
||||
if bufexists(buf)
|
||||
for [opt, value] in items(saved)
|
||||
silent call setbufvar(buf, '&'.opt, value)
|
||||
unlet value " avoid variable type mismatches
|
||||
endfor
|
||||
endif
|
||||
if has_key(dict, 'tmpdir') | silent call s:RmDir(dict.tmpdir) | endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
@@ -210,6 +274,71 @@ function! rust#AppendCmdLine(text)
|
||||
return cmd
|
||||
endfunction
|
||||
|
||||
" Tokenize the string according to sh parsing rules
|
||||
function! s:ShellTokenize(text)
|
||||
" states:
|
||||
" 0: start of word
|
||||
" 1: unquoted
|
||||
" 2: unquoted backslash
|
||||
" 3: double-quote
|
||||
" 4: double-quoted backslash
|
||||
" 5: single-quote
|
||||
let l:state = 0
|
||||
let l:current = ''
|
||||
let l:args = []
|
||||
for c in split(a:text, '\zs')
|
||||
if l:state == 0 || l:state == 1 " unquoted
|
||||
if l:c ==# ' '
|
||||
if l:state == 0 | continue | endif
|
||||
call add(l:args, l:current)
|
||||
let l:current = ''
|
||||
let l:state = 0
|
||||
elseif l:c ==# '\'
|
||||
let l:state = 2
|
||||
elseif l:c ==# '"'
|
||||
let l:state = 3
|
||||
elseif l:c ==# "'"
|
||||
let l:state = 5
|
||||
else
|
||||
let l:current .= l:c
|
||||
let l:state = 1
|
||||
endif
|
||||
elseif l:state == 2 " unquoted backslash
|
||||
if l:c !=# "\n" " can it even be \n?
|
||||
let l:current .= l:c
|
||||
endif
|
||||
let l:state = 1
|
||||
elseif l:state == 3 " double-quote
|
||||
if l:c ==# '\'
|
||||
let l:state = 4
|
||||
elseif l:c ==# '"'
|
||||
let l:state = 1
|
||||
else
|
||||
let l:current .= l:c
|
||||
endif
|
||||
elseif l:state == 4 " double-quoted backslash
|
||||
if stridx('$`"\', l:c) >= 0
|
||||
let l:current .= l:c
|
||||
elseif l:c ==# "\n" " is this even possible?
|
||||
" skip it
|
||||
else
|
||||
let l:current .= '\'.l:c
|
||||
endif
|
||||
let l:state = 3
|
||||
elseif l:state == 5 " single-quoted
|
||||
if l:c == "'"
|
||||
let l:state = 1
|
||||
else
|
||||
let l:current .= l:c
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if l:state != 0
|
||||
call add(l:args, l:current)
|
||||
endif
|
||||
return l:args
|
||||
endfunction
|
||||
|
||||
function! s:RmDir(path)
|
||||
" sanity check; make sure it's not empty, /, or $HOME
|
||||
if empty(a:path)
|
||||
@@ -222,6 +351,66 @@ function! s:RmDir(path)
|
||||
silent exe "!rm -rf " . shellescape(a:path)
|
||||
endfunction
|
||||
|
||||
" Executes {cmd} with the cwd set to {pwd}, without changing Vim's cwd.
|
||||
" If {pwd} is the empty string then it doesn't change the cwd.
|
||||
function! s:system(pwd, cmd)
|
||||
let cmd = a:cmd
|
||||
if !empty(a:pwd)
|
||||
let cmd = 'cd ' . shellescape(a:pwd) . ' && ' . cmd
|
||||
endif
|
||||
return system(cmd)
|
||||
endfunction
|
||||
|
||||
" Playpen Support {{{1
|
||||
" Parts of gist.vim by Yasuhiro Matsumoto <mattn.jp@gmail.com> reused
|
||||
" gist.vim available under the BSD license, available at
|
||||
" http://github.com/mattn/gist-vim
|
||||
function! s:has_webapi()
|
||||
if !exists("*webapi#http#post")
|
||||
try
|
||||
call webapi#http#post()
|
||||
catch
|
||||
endtry
|
||||
endif
|
||||
return exists("*webapi#http#post")
|
||||
endfunction
|
||||
|
||||
function! rust#Play(count, line1, line2, ...) abort
|
||||
redraw
|
||||
|
||||
let l:rust_playpen_url = get(g:, 'rust_playpen_url', 'https://play.rust-lang.org/')
|
||||
let l:rust_shortener_url = get(g:, 'rust_shortener_url', 'https://is.gd/')
|
||||
|
||||
if !s:has_webapi()
|
||||
echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let bufname = bufname('%')
|
||||
if a:count < 1
|
||||
let content = join(getline(a:line1, a:line2), "\n")
|
||||
else
|
||||
let save_regcont = @"
|
||||
let save_regtype = getregtype('"')
|
||||
silent! normal! gvy
|
||||
let content = @"
|
||||
call setreg('"', save_regcont, save_regtype)
|
||||
endif
|
||||
|
||||
let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content)
|
||||
|
||||
if strlen(body) > 5000
|
||||
echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let payload = "format=simple&url=".webapi#http#encodeURI(body)
|
||||
let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {})
|
||||
let url = res.content
|
||||
|
||||
redraw | echomsg 'Done: '.url
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim: set noet sw=4 ts=4:
|
||||
|
||||
83
autoload/rustfmt.vim
Normal file
83
autoload/rustfmt.vim
Normal file
@@ -0,0 +1,83 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
|
||||
" Author: Stephen Sugden <stephen@stephensugden.com>
|
||||
"
|
||||
" Adapted from https://github.com/fatih/vim-go
|
||||
|
||||
if !exists("g:rustfmt_autosave")
|
||||
let g:rustfmt_autosave = 0
|
||||
endif
|
||||
|
||||
if !exists("g:rustfmt_command")
|
||||
let g:rustfmt_command = "rustfmt"
|
||||
endif
|
||||
|
||||
if !exists("g:rustfmt_options")
|
||||
let g:rustfmt_options = ""
|
||||
endif
|
||||
|
||||
if !exists("g:rustfmt_fail_silently")
|
||||
let g:rustfmt_fail_silently = 0
|
||||
endif
|
||||
|
||||
let s:got_fmt_error = 0
|
||||
|
||||
function! rustfmt#Format()
|
||||
let l:curw = winsaveview()
|
||||
let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt"
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
let command = g:rustfmt_command . " --write-mode=overwrite "
|
||||
|
||||
let out = systemlist(command . g:rustfmt_options . " " . shellescape(l:tmpname))
|
||||
|
||||
if v:shell_error == 0
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" Replace current file with temp file, then reload buffer
|
||||
call rename(l:tmpname, expand('%'))
|
||||
silent edit!
|
||||
let &syntax = &syntax
|
||||
|
||||
" only clear location list if it was previously filled to prevent
|
||||
" clobbering other additions
|
||||
if s:got_fmt_error
|
||||
let s:got_fmt_error = 0
|
||||
call setloclist(0, [])
|
||||
lwindow
|
||||
endif
|
||||
elseif g:rustfmt_fail_silently == 0
|
||||
" otherwise get the errors and put them in the location list
|
||||
let errors = []
|
||||
|
||||
for line in out
|
||||
" src/lib.rs:13:5: 13:10 error: expected `,`, or `}`, found `value`
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\):\s*\(\d\+:\d\+\s*\)\?\s*error: \(.*\)')
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": @%,
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[5]})
|
||||
endif
|
||||
endfor
|
||||
|
||||
if empty(errors)
|
||||
% | " Couldn't detect rustfmt error format, output errors
|
||||
endif
|
||||
|
||||
if !empty(errors)
|
||||
call setloclist(0, errors, 'r')
|
||||
echohl Error | echomsg "rustfmt returned error" | echohl None
|
||||
endif
|
||||
|
||||
let s:got_fmt_error = 1
|
||||
lwindow
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
endif
|
||||
|
||||
call winrestview(l:curw)
|
||||
endfunction
|
||||
|
||||
endif
|
||||
16
autoload/vital.vim
Normal file
16
autoload/vital.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
function! vital#of(name) abort
|
||||
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital')
|
||||
let file = split(files, "\n")
|
||||
if empty(file)
|
||||
throw 'vital: version file not found: ' . a:name
|
||||
endif
|
||||
let ver = readfile(file[0], 'b')
|
||||
if empty(ver)
|
||||
throw 'vital: invalid version file: ' . a:name
|
||||
endif
|
||||
return vital#_{substitute(ver[0], '\W', '', 'g')}#new()
|
||||
endfunction
|
||||
|
||||
endif
|
||||
313
autoload/vital/_crystal.vim
Normal file
313
autoload/vital/_crystal.vim
Normal file
@@ -0,0 +1,313 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
let s:self_version = expand('<sfile>:t:r')
|
||||
let s:self_file = expand('<sfile>')
|
||||
|
||||
" Note: The extra argument to globpath() was added in Patch 7.2.051.
|
||||
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51')
|
||||
|
||||
let s:loaded = {}
|
||||
let s:cache_module_path = {}
|
||||
let s:cache_sid = {}
|
||||
|
||||
let s:_vital_files_cache_runtimepath = ''
|
||||
let s:_vital_files_cache = []
|
||||
let s:_unify_path_cache = {}
|
||||
|
||||
function! s:import(name, ...) abort
|
||||
let target = {}
|
||||
let functions = []
|
||||
for a in a:000
|
||||
if type(a) == type({})
|
||||
let target = a
|
||||
elseif type(a) == type([])
|
||||
let functions = a
|
||||
endif
|
||||
unlet a
|
||||
endfor
|
||||
let module = s:_import(a:name)
|
||||
if empty(functions)
|
||||
call extend(target, module, 'keep')
|
||||
else
|
||||
for f in functions
|
||||
if has_key(module, f) && !has_key(target, f)
|
||||
let target[f] = module[f]
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return target
|
||||
endfunction
|
||||
|
||||
function! s:load(...) dict abort
|
||||
for arg in a:000
|
||||
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
||||
let target = split(join(as, ''), '\W\+')
|
||||
let dict = self
|
||||
let dict_type = type({})
|
||||
while !empty(target)
|
||||
let ns = remove(target, 0)
|
||||
if !has_key(dict, ns)
|
||||
let dict[ns] = {}
|
||||
endif
|
||||
if type(dict[ns]) == dict_type
|
||||
let dict = dict[ns]
|
||||
else
|
||||
unlet dict
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
if exists('dict')
|
||||
call extend(dict, s:_import(name))
|
||||
endif
|
||||
unlet arg
|
||||
endfor
|
||||
return self
|
||||
endfunction
|
||||
|
||||
function! s:unload() abort
|
||||
let s:loaded = {}
|
||||
let s:cache_sid = {}
|
||||
let s:cache_module_path = {}
|
||||
endfunction
|
||||
|
||||
function! s:exists(name) abort
|
||||
return s:_get_module_path(a:name) !=# ''
|
||||
endfunction
|
||||
|
||||
function! s:search(pattern) abort
|
||||
let paths = s:_vital_files(a:pattern)
|
||||
let modules = sort(map(paths, 's:_file2module(v:val)'))
|
||||
return s:_uniq(modules)
|
||||
endfunction
|
||||
|
||||
function! s:expand_modules(entry, all) abort
|
||||
if type(a:entry) == type([])
|
||||
let candidates = s:_concat(map(copy(a:entry), 's:search(v:val)'))
|
||||
if empty(candidates)
|
||||
throw printf('vital: Any of module %s is not found', string(a:entry))
|
||||
endif
|
||||
if eval(join(map(copy(candidates), 'has_key(a:all, v:val)'), '+'))
|
||||
let modules = []
|
||||
else
|
||||
let modules = [candidates[0]]
|
||||
endif
|
||||
else
|
||||
let modules = s:search(a:entry)
|
||||
if empty(modules)
|
||||
throw printf('vital: Module %s is not found', a:entry)
|
||||
endif
|
||||
endif
|
||||
call filter(modules, '!has_key(a:all, v:val)')
|
||||
for module in modules
|
||||
let a:all[module] = 1
|
||||
endfor
|
||||
return modules
|
||||
endfunction
|
||||
|
||||
function! s:_import(name) abort
|
||||
if type(a:name) == type(0)
|
||||
return s:_build_module(a:name)
|
||||
endif
|
||||
let path = s:_get_module_path(a:name)
|
||||
if path ==# ''
|
||||
throw 'vital: module not found: ' . a:name
|
||||
endif
|
||||
let sid = s:_get_sid_by_script(path)
|
||||
if !sid
|
||||
try
|
||||
execute 'source' fnameescape(path)
|
||||
catch /^Vim\%((\a\+)\)\?:E484/
|
||||
throw 'vital: module not found: ' . a:name
|
||||
catch /^Vim\%((\a\+)\)\?:E127/
|
||||
" Ignore.
|
||||
endtry
|
||||
|
||||
let sid = s:_get_sid_by_script(path)
|
||||
endif
|
||||
return s:_build_module(sid)
|
||||
endfunction
|
||||
|
||||
function! s:_get_module_path(name) abort
|
||||
let key = a:name . '_'
|
||||
if has_key(s:cache_module_path, key)
|
||||
return s:cache_module_path[key]
|
||||
endif
|
||||
if s:_is_absolute_path(a:name) && filereadable(a:name)
|
||||
return a:name
|
||||
endif
|
||||
if a:name ==# ''
|
||||
let paths = [s:self_file]
|
||||
elseif a:name =~# '\v^\u\w*%(\.\u\w*)*$'
|
||||
let paths = s:_vital_files(a:name)
|
||||
else
|
||||
throw 'vital: Invalid module name: ' . a:name
|
||||
endif
|
||||
|
||||
call filter(paths, 'filereadable(expand(v:val, 1))')
|
||||
let path = get(paths, 0, '')
|
||||
let s:cache_module_path[key] = path
|
||||
return path
|
||||
endfunction
|
||||
|
||||
function! s:_get_sid_by_script(path) abort
|
||||
if has_key(s:cache_sid, a:path)
|
||||
return s:cache_sid[a:path]
|
||||
endif
|
||||
|
||||
let path = s:_unify_path(a:path)
|
||||
for line in filter(split(s:_redir('scriptnames'), "\n"),
|
||||
\ 'stridx(v:val, s:self_version) > 0')
|
||||
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
|
||||
if !empty(list) && s:_unify_path(list[2]) ==# path
|
||||
let s:cache_sid[a:path] = list[1] - 0
|
||||
return s:cache_sid[a:path]
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:_file2module(file) abort
|
||||
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
|
||||
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
|
||||
return join(split(tail, '[\\/]\+'), '.')
|
||||
endfunction
|
||||
|
||||
if filereadable(expand('<sfile>:r') . '.VIM')
|
||||
" resolve() is slow, so we cache results.
|
||||
" Note: On windows, vim can't expand path names from 8.3 formats.
|
||||
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
|
||||
" vital load duplicated scripts. Below's :~ avoid this issue.
|
||||
function! s:_unify_path(path) abort
|
||||
if has_key(s:_unify_path_cache, a:path)
|
||||
return s:_unify_path_cache[a:path]
|
||||
endif
|
||||
let value = tolower(fnamemodify(resolve(fnamemodify(
|
||||
\ a:path, ':p')), ':~:gs?[\\/]?/?'))
|
||||
let s:_unify_path_cache[a:path] = value
|
||||
return value
|
||||
endfunction
|
||||
else
|
||||
function! s:_unify_path(path) abort
|
||||
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if s:globpath_third_arg
|
||||
function! s:_runtime_files(path) abort
|
||||
return split(globpath(&runtimepath, a:path, 1), "\n")
|
||||
endfunction
|
||||
else
|
||||
function! s:_runtime_files(path) abort
|
||||
return split(globpath(&runtimepath, a:path), "\n")
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:_vital_files(pattern) abort
|
||||
if s:_vital_files_cache_runtimepath !=# &runtimepath
|
||||
let path = printf('autoload/vital/%s/**/*.vim', s:self_version)
|
||||
let s:_vital_files_cache = s:_runtime_files(path)
|
||||
let mod = ':p:gs?[\\/]\+?/?'
|
||||
call map(s:_vital_files_cache, 'fnamemodify(v:val, mod)')
|
||||
let s:_vital_files_cache_runtimepath = &runtimepath
|
||||
endif
|
||||
let target = substitute(a:pattern, '\.', '/', 'g')
|
||||
let target = substitute(target, '\*', '[^/]*', 'g')
|
||||
let regexp = printf('autoload/vital/%s/%s.vim', s:self_version, target)
|
||||
return filter(copy(s:_vital_files_cache), 'v:val =~# regexp')
|
||||
endfunction
|
||||
|
||||
" Copy from System.Filepath
|
||||
if has('win16') || has('win32') || has('win64')
|
||||
function! s:_is_absolute_path(path) abort
|
||||
return a:path =~? '^[a-z]:[/\\]'
|
||||
endfunction
|
||||
else
|
||||
function! s:_is_absolute_path(path) abort
|
||||
return a:path[0] ==# '/'
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:_build_module(sid) abort
|
||||
if has_key(s:loaded, a:sid)
|
||||
return copy(s:loaded[a:sid])
|
||||
endif
|
||||
let functions = s:_get_functions(a:sid)
|
||||
|
||||
let prefix = '<SNR>' . a:sid . '_'
|
||||
let module = {}
|
||||
for func in functions
|
||||
let module[func] = function(prefix . func)
|
||||
endfor
|
||||
if has_key(module, '_vital_created')
|
||||
call module._vital_created(module)
|
||||
endif
|
||||
let export_module = filter(copy(module), 'v:key =~# "^\\a"')
|
||||
let s:loaded[a:sid] = get(g:, 'vital_debug', 0) ? module : export_module
|
||||
if has_key(module, '_vital_loaded')
|
||||
let V = vital#{s:self_version}#new()
|
||||
call module._vital_loaded(V)
|
||||
endif
|
||||
return copy(s:loaded[a:sid])
|
||||
endfunction
|
||||
|
||||
if exists('+regexpengine')
|
||||
function! s:_get_functions(sid) abort
|
||||
let funcs = s:_redir(printf("function /\\%%#=2^\<SNR>%d_", a:sid))
|
||||
let map_pat = '<SNR>' . a:sid . '_\zs\w\+'
|
||||
return map(split(funcs, "\n"), 'matchstr(v:val, map_pat)')
|
||||
endfunction
|
||||
else
|
||||
function! s:_get_functions(sid) abort
|
||||
let prefix = '<SNR>' . a:sid . '_'
|
||||
let funcs = s:_redir('function')
|
||||
let filter_pat = '^\s*function ' . prefix
|
||||
let map_pat = prefix . '\zs\w\+'
|
||||
return map(filter(split(funcs, "\n"),
|
||||
\ 'stridx(v:val, prefix) > 0 && v:val =~# filter_pat'),
|
||||
\ 'matchstr(v:val, map_pat)')
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if exists('*uniq')
|
||||
function! s:_uniq(list) abort
|
||||
return uniq(a:list)
|
||||
endfunction
|
||||
else
|
||||
function! s:_uniq(list) abort
|
||||
let i = len(a:list) - 1
|
||||
while 0 < i
|
||||
if a:list[i] ==# a:list[i - 1]
|
||||
call remove(a:list, i)
|
||||
let i -= 2
|
||||
else
|
||||
let i -= 1
|
||||
endif
|
||||
endwhile
|
||||
return a:list
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:_concat(lists) abort
|
||||
let result_list = []
|
||||
for list in a:lists
|
||||
let result_list += list
|
||||
endfor
|
||||
return result_list
|
||||
endfunction
|
||||
|
||||
function! s:_redir(cmd) abort
|
||||
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
|
||||
set verbose=0 verbosefile=
|
||||
redir => res
|
||||
silent! execute a:cmd
|
||||
redir END
|
||||
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! vital#{s:self_version}#new() abort
|
||||
return s:_import('')
|
||||
endfunction
|
||||
|
||||
endif
|
||||
182
autoload/vital/_crystal/ColorEcho.vim
Normal file
182
autoload/vital/_crystal/ColorEcho.vim
Normal file
@@ -0,0 +1,182 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:_is_available() abort
|
||||
if has('gui_running')
|
||||
return 1
|
||||
endif
|
||||
|
||||
if has('win32') || has('win64')
|
||||
return 0
|
||||
endif
|
||||
|
||||
return exists('&t_Co') && (&t_Co == 8 || &t_Co == 256)
|
||||
endfunction
|
||||
|
||||
function! s:is_available() abort
|
||||
if exists('s:is_available_cache')
|
||||
return s:is_available_cache
|
||||
endif
|
||||
let s:is_available_cache = s:_is_available()
|
||||
return s:is_available_cache
|
||||
endfunction
|
||||
|
||||
function! s:_define_ansi_highlights() abort
|
||||
hi ansiNone cterm=NONE gui=NONE
|
||||
|
||||
hi ansiBlackBg ctermbg=black guibg=black cterm=none gui=none
|
||||
hi ansiRedBg ctermbg=red guibg=red cterm=none gui=none
|
||||
hi ansiGreenBg ctermbg=green guibg=green cterm=none gui=none
|
||||
hi ansiYellowBg ctermbg=yellow guibg=yellow cterm=none gui=none
|
||||
hi ansiBlueBg ctermbg=blue guibg=blue cterm=none gui=none
|
||||
hi ansiMagentaBg ctermbg=magenta guibg=magenta cterm=none gui=none
|
||||
hi ansiCyanBg ctermbg=cyan guibg=cyan cterm=none gui=none
|
||||
hi ansiWhiteBg ctermbg=white guibg=white cterm=none gui=none
|
||||
hi ansiGrayBg ctermbg=gray guibg=gray cterm=none gui=none
|
||||
|
||||
hi ansiBlackFg ctermfg=black guifg=black cterm=none gui=none
|
||||
hi ansiRedFg ctermfg=red guifg=red cterm=none gui=none
|
||||
hi ansiGreenFg ctermfg=green guifg=green cterm=none gui=none
|
||||
hi ansiYellowFg ctermfg=yellow guifg=yellow cterm=none gui=none
|
||||
hi ansiBlueFg ctermfg=blue guifg=blue cterm=none gui=none
|
||||
hi ansiMagentaFg ctermfg=magenta guifg=magenta cterm=none gui=none
|
||||
hi ansiCyanFg ctermfg=cyan guifg=cyan cterm=none gui=none
|
||||
hi ansiWhiteFg ctermfg=white guifg=white cterm=none gui=none
|
||||
hi ansiGrayFg ctermfg=gray guifg=gray cterm=none gui=none
|
||||
|
||||
hi ansiBoldBlackFg ctermfg=black guifg=black cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldRedFg ctermfg=red guifg=red cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldGreenFg ctermfg=green guifg=green cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldYellowFg ctermfg=yellow guifg=yellow cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldBlueFg ctermfg=blue guifg=blue cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldMagentaFg ctermfg=magenta guifg=magenta cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldCyanFg ctermfg=cyan guifg=cyan cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldWhiteFg ctermfg=white guifg=white cterm=none gui=none cterm=bold gui=bold
|
||||
hi ansiBoldGrayFg ctermfg=gray guifg=gray cterm=none gui=none cterm=bold gui=bold
|
||||
|
||||
hi ansiUnderlineBlackFg ctermfg=black guifg=black cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineRedFg ctermfg=red guifg=red cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineGreenFg ctermfg=green guifg=green cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineYellowFg ctermfg=yellow guifg=yellow cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineBlueFg ctermfg=blue guifg=blue cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineMagentaFg ctermfg=magenta guifg=magenta cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineCyanFg ctermfg=cyan guifg=cyan cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineWhiteFg ctermfg=white guifg=white cterm=none gui=none cterm=underline gui=underline
|
||||
hi ansiUnderlineGrayFg ctermfg=gray guifg=gray cterm=none gui=none cterm=underline gui=underline
|
||||
|
||||
endfunction
|
||||
|
||||
let s:echorizer = {
|
||||
\ 'value': '',
|
||||
\ 'attr': '',
|
||||
\ }
|
||||
|
||||
function s:echorizer.eat() abort
|
||||
let matched = match(self.value, '\e\[\d*;\=m')
|
||||
if matched == -1
|
||||
return {}
|
||||
endif
|
||||
|
||||
let matched_end = matchend(self.value, '\e\[\d*;\=m')
|
||||
|
||||
let token = {
|
||||
\ 'body': matched == 0 ? '' : self.value[ : matched-1],
|
||||
\ 'code': matchstr(self.value[matched : matched_end-1], '\d\+')
|
||||
\ }
|
||||
|
||||
let self.value = self.value[matched_end : ]
|
||||
|
||||
return token
|
||||
endfunction
|
||||
|
||||
let s:COLORS = {
|
||||
\ 0: "None",
|
||||
\ 30: "BlackFg",
|
||||
\ 31: "RedFg",
|
||||
\ 32: "GreenFg",
|
||||
\ 33: "YellowFg",
|
||||
\ 34: "BlueFg",
|
||||
\ 35: "MagentaFg",
|
||||
\ 36: "CyanFg",
|
||||
\ 37: "WhiteFg",
|
||||
\ 40: "BlackBg",
|
||||
\ 41: "RedBg",
|
||||
\ 42: "GreenBg",
|
||||
\ 43: "YellowBg",
|
||||
\ 44: "BlueBg",
|
||||
\ 45: "MagentaBg",
|
||||
\ 46: "CyanBg",
|
||||
\ 47: "WhiteBg",
|
||||
\ 90: "GrayFg",
|
||||
\ }
|
||||
|
||||
function s:echorizer.echo_ansi(code) abort
|
||||
if !has_key(s:COLORS, a:code)
|
||||
return
|
||||
endif
|
||||
|
||||
execute 'echohl' 'ansi' . self.attr . s:COLORS[a:code]
|
||||
|
||||
if a:code == 0
|
||||
let self.attr = ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function s:echorizer.echo() abort
|
||||
echo
|
||||
|
||||
while 1
|
||||
let token = self.eat()
|
||||
if token == {}
|
||||
break
|
||||
endif
|
||||
|
||||
if token.body !=# ''
|
||||
echon token.body
|
||||
endif
|
||||
|
||||
" TODO: Now only one attribute can be specified
|
||||
if token.code == 1
|
||||
let self.attr = 'Bold'
|
||||
elseif token.code == 4
|
||||
let self.attr = 'Underline'
|
||||
elseif token.code ==# ''
|
||||
call self.echo_ansi(0)
|
||||
else
|
||||
call self.echo_ansi(token.code)
|
||||
endif
|
||||
endwhile
|
||||
|
||||
echon self.value
|
||||
echohl None
|
||||
let self.value = ''
|
||||
endfunction
|
||||
|
||||
function! s:get_echorizer(str) abort
|
||||
let e = deepcopy(s:echorizer)
|
||||
let e.value = a:str
|
||||
return e
|
||||
endfunction
|
||||
|
||||
function! s:echo(str) abort
|
||||
if !s:is_available()
|
||||
echo substitute(a:str, '\e[.*m', '', 'g')
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists('g:__vital_color_echo_already_highlighted')
|
||||
call s:_define_ansi_highlights()
|
||||
let g:__vital_color_echo_already_highlighted = 1
|
||||
endif
|
||||
|
||||
let echorizer = s:get_echorizer(a:str)
|
||||
call echorizer.echo()
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
||||
446
autoload/vital/_crystal/Data/List.vim
Normal file
446
autoload/vital/_crystal/Data/List.vim
Normal file
@@ -0,0 +1,446 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
" Utilities for list.
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:pop(list) abort
|
||||
return remove(a:list, -1)
|
||||
endfunction
|
||||
|
||||
function! s:push(list, val) abort
|
||||
call add(a:list, a:val)
|
||||
return a:list
|
||||
endfunction
|
||||
|
||||
function! s:shift(list) abort
|
||||
return remove(a:list, 0)
|
||||
endfunction
|
||||
|
||||
function! s:unshift(list, val) abort
|
||||
return insert(a:list, a:val)
|
||||
endfunction
|
||||
|
||||
function! s:cons(x, xs) abort
|
||||
return [a:x] + a:xs
|
||||
endfunction
|
||||
|
||||
function! s:conj(xs, x) abort
|
||||
return a:xs + [a:x]
|
||||
endfunction
|
||||
|
||||
" Removes duplicates from a list.
|
||||
function! s:uniq(list) abort
|
||||
return s:uniq_by(a:list, 'v:val')
|
||||
endfunction
|
||||
|
||||
" Removes duplicates from a list.
|
||||
function! s:uniq_by(list, f) abort
|
||||
let list = map(copy(a:list), printf('[v:val, %s]', a:f))
|
||||
let i = 0
|
||||
let seen = {}
|
||||
while i < len(list)
|
||||
let key = string(list[i][1])
|
||||
if has_key(seen, key)
|
||||
call remove(list, i)
|
||||
else
|
||||
let seen[key] = 1
|
||||
let i += 1
|
||||
endif
|
||||
endwhile
|
||||
return map(list, 'v:val[0]')
|
||||
endfunction
|
||||
|
||||
function! s:clear(list) abort
|
||||
if !empty(a:list)
|
||||
unlet! a:list[0 : len(a:list) - 1]
|
||||
endif
|
||||
return a:list
|
||||
endfunction
|
||||
|
||||
" Concatenates a list of lists.
|
||||
" XXX: Should we verify the input?
|
||||
function! s:concat(list) abort
|
||||
let memo = []
|
||||
for Value in a:list
|
||||
let memo += Value
|
||||
endfor
|
||||
return memo
|
||||
endfunction
|
||||
|
||||
" Take each elements from lists to a new list.
|
||||
function! s:flatten(list, ...) abort
|
||||
let limit = a:0 > 0 ? a:1 : -1
|
||||
let memo = []
|
||||
if limit == 0
|
||||
return a:list
|
||||
endif
|
||||
let limit -= 1
|
||||
for Value in a:list
|
||||
let memo +=
|
||||
\ type(Value) == type([]) ?
|
||||
\ s:flatten(Value, limit) :
|
||||
\ [Value]
|
||||
unlet! Value
|
||||
endfor
|
||||
return memo
|
||||
endfunction
|
||||
|
||||
" Sorts a list with expression to compare each two values.
|
||||
" a:a and a:b can be used in {expr}.
|
||||
function! s:sort(list, expr) abort
|
||||
if type(a:expr) == type(function('function'))
|
||||
return sort(a:list, a:expr)
|
||||
endif
|
||||
let s:expr = a:expr
|
||||
return sort(a:list, 's:_compare')
|
||||
endfunction
|
||||
|
||||
function! s:_compare(a, b) abort
|
||||
return eval(s:expr)
|
||||
endfunction
|
||||
|
||||
" Sorts a list using a set of keys generated by mapping the values in the list
|
||||
" through the given expr.
|
||||
" v:val is used in {expr}
|
||||
function! s:sort_by(list, expr) abort
|
||||
let pairs = map(a:list, printf('[v:val, %s]', a:expr))
|
||||
return map(s:sort(pairs,
|
||||
\ 'a:a[1] ==# a:b[1] ? 0 : a:a[1] ># a:b[1] ? 1 : -1'), 'v:val[0]')
|
||||
endfunction
|
||||
|
||||
" Returns a maximum value in {list} through given {expr}.
|
||||
" Returns 0 if {list} is empty.
|
||||
" v:val is used in {expr}
|
||||
function! s:max_by(list, expr) abort
|
||||
if empty(a:list)
|
||||
return 0
|
||||
endif
|
||||
let list = map(copy(a:list), a:expr)
|
||||
return a:list[index(list, max(list))]
|
||||
endfunction
|
||||
|
||||
" Returns a minimum value in {list} through given {expr}.
|
||||
" Returns 0 if {list} is empty.
|
||||
" v:val is used in {expr}
|
||||
" FIXME: -0x80000000 == 0x80000000
|
||||
function! s:min_by(list, expr) abort
|
||||
return s:max_by(a:list, '-(' . a:expr . ')')
|
||||
endfunction
|
||||
|
||||
" Returns List of character sequence between [a:from, a:to]
|
||||
" e.g.: s:char_range('a', 'c') returns ['a', 'b', 'c']
|
||||
function! s:char_range(from, to) abort
|
||||
return map(
|
||||
\ range(char2nr(a:from), char2nr(a:to)),
|
||||
\ 'nr2char(v:val)'
|
||||
\)
|
||||
endfunction
|
||||
|
||||
" Returns true if a:list has a:value.
|
||||
" Returns false otherwise.
|
||||
function! s:has(list, value) abort
|
||||
return index(a:list, a:value) isnot -1
|
||||
endfunction
|
||||
|
||||
" Returns true if a:list[a:index] exists.
|
||||
" Returns false otherwise.
|
||||
" NOTE: Returns false when a:index is negative number.
|
||||
function! s:has_index(list, index) abort
|
||||
" Return true when negative index?
|
||||
" let index = a:index >= 0 ? a:index : len(a:list) + a:index
|
||||
return 0 <= a:index && a:index < len(a:list)
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Data.List.span
|
||||
function! s:span(f, xs) abort
|
||||
let border = len(a:xs)
|
||||
for i in range(len(a:xs))
|
||||
if !eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
|
||||
let border = i
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
return border == 0 ? [[], copy(a:xs)] : [a:xs[: border - 1], a:xs[border :]]
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Data.List.break
|
||||
function! s:break(f, xs) abort
|
||||
return s:span(printf('!(%s)', a:f), a:xs)
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Data.List.takeWhile
|
||||
function! s:take_while(f, xs) abort
|
||||
return s:span(a:f, a:xs)[0]
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Data.List.partition
|
||||
function! s:partition(f, xs) abort
|
||||
return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')]
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.all
|
||||
function! s:all(f, xs) abort
|
||||
return !s:any(printf('!(%s)', a:f), a:xs)
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.any
|
||||
function! s:any(f, xs) abort
|
||||
return !empty(filter(map(copy(a:xs), a:f), 'v:val'))
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.and
|
||||
function! s:and(xs) abort
|
||||
return s:all('v:val', a:xs)
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.or
|
||||
function! s:or(xs) abort
|
||||
return s:any('v:val', a:xs)
|
||||
endfunction
|
||||
|
||||
function! s:map_accum(expr, xs, init) abort
|
||||
let memo = []
|
||||
let init = a:init
|
||||
for x in a:xs
|
||||
let expr = substitute(a:expr, 'v:memo', init, 'g')
|
||||
let expr = substitute(expr, 'v:val', x, 'g')
|
||||
let [tmp, init] = eval(expr)
|
||||
call add(memo, tmp)
|
||||
endfor
|
||||
return memo
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.foldl
|
||||
function! s:foldl(f, init, xs) abort
|
||||
let memo = a:init
|
||||
for x in a:xs
|
||||
let expr = substitute(a:f, 'v:val', string(x), 'g')
|
||||
let expr = substitute(expr, 'v:memo', string(memo), 'g')
|
||||
unlet memo
|
||||
let memo = eval(expr)
|
||||
endfor
|
||||
return memo
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.foldl1
|
||||
function! s:foldl1(f, xs) abort
|
||||
if len(a:xs) == 0
|
||||
throw 'vital: Data.List: foldl1'
|
||||
endif
|
||||
return s:foldl(a:f, a:xs[0], a:xs[1:])
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.foldr
|
||||
function! s:foldr(f, init, xs) abort
|
||||
return s:foldl(a:f, a:init, reverse(copy(a:xs)))
|
||||
endfunction
|
||||
|
||||
" similar to Haskell's Prelude.fold11
|
||||
function! s:foldr1(f, xs) abort
|
||||
if len(a:xs) == 0
|
||||
throw 'vital: Data.List: foldr1'
|
||||
endif
|
||||
return s:foldr(a:f, a:xs[-1], a:xs[0:-2])
|
||||
endfunction
|
||||
|
||||
" similar to python's zip()
|
||||
function! s:zip(...) abort
|
||||
return map(range(min(map(copy(a:000), 'len(v:val)'))), "map(copy(a:000), 'v:val['.v:val.']')")
|
||||
endfunction
|
||||
|
||||
" similar to zip(), but goes until the longer one.
|
||||
function! s:zip_fill(xs, ys, filler) abort
|
||||
if empty(a:xs) && empty(a:ys)
|
||||
return []
|
||||
elseif empty(a:ys)
|
||||
return s:cons([a:xs[0], a:filler], s:zip_fill(a:xs[1 :], [], a:filler))
|
||||
elseif empty(a:xs)
|
||||
return s:cons([a:filler, a:ys[0]], s:zip_fill([], a:ys[1 :], a:filler))
|
||||
else
|
||||
return s:cons([a:xs[0], a:ys[0]], s:zip_fill(a:xs[1 :], a:ys[1: ], a:filler))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Inspired by Ruby's with_index method.
|
||||
function! s:with_index(list, ...) abort
|
||||
let base = a:0 > 0 ? a:1 : 0
|
||||
return map(copy(a:list), '[v:val, v:key + base]')
|
||||
endfunction
|
||||
|
||||
" similar to Ruby's detect or Haskell's find.
|
||||
function! s:find(list, default, f) abort
|
||||
for x in a:list
|
||||
if eval(substitute(a:f, 'v:val', string(x), 'g'))
|
||||
return x
|
||||
endif
|
||||
endfor
|
||||
return a:default
|
||||
endfunction
|
||||
|
||||
" Returns the index of the first element which satisfies the given expr.
|
||||
function! s:find_index(xs, f, ...) abort
|
||||
let len = len(a:xs)
|
||||
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0
|
||||
let default = a:0 > 1 ? a:2 : -1
|
||||
if start >=# len || start < 0
|
||||
return default
|
||||
endif
|
||||
for i in range(start, len - 1)
|
||||
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
|
||||
return i
|
||||
endif
|
||||
endfor
|
||||
return default
|
||||
endfunction
|
||||
|
||||
" Returns the index of the last element which satisfies the given expr.
|
||||
function! s:find_last_index(xs, f, ...) abort
|
||||
let len = len(a:xs)
|
||||
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : len - 1
|
||||
let default = a:0 > 1 ? a:2 : -1
|
||||
if start >=# len || start < 0
|
||||
return default
|
||||
endif
|
||||
for i in range(start, 0, -1)
|
||||
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
|
||||
return i
|
||||
endif
|
||||
endfor
|
||||
return default
|
||||
endfunction
|
||||
|
||||
" Similar to find_index but returns the list of indices satisfying the given expr.
|
||||
function! s:find_indices(xs, f, ...) abort
|
||||
let len = len(a:xs)
|
||||
let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0
|
||||
let result = []
|
||||
if start >=# len || start < 0
|
||||
return result
|
||||
endif
|
||||
for i in range(start, len - 1)
|
||||
if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g'))
|
||||
call add(result, i)
|
||||
endif
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
" Return non-zero if a:list1 and a:list2 have any common item(s).
|
||||
" Return zero otherwise.
|
||||
function! s:has_common_items(list1, list2) abort
|
||||
return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1'))
|
||||
endfunction
|
||||
|
||||
function! s:intersect(list1, list2) abort
|
||||
let items = []
|
||||
" for funcref
|
||||
for X in a:list1
|
||||
if index(a:list2, X) != -1 && index(items, X) == -1
|
||||
let items += [X]
|
||||
endif
|
||||
endfor
|
||||
return items
|
||||
endfunction
|
||||
|
||||
" similar to Ruby's group_by.
|
||||
function! s:group_by(xs, f) abort
|
||||
let result = {}
|
||||
let list = map(copy(a:xs), printf('[v:val, %s]', a:f))
|
||||
for x in list
|
||||
let Val = x[0]
|
||||
let key = type(x[1]) !=# type('') ? string(x[1]) : x[1]
|
||||
if has_key(result, key)
|
||||
call add(result[key], Val)
|
||||
else
|
||||
let result[key] = [Val]
|
||||
endif
|
||||
unlet Val
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! s:_default_compare(a, b) abort
|
||||
return a:a <# a:b ? -1 : a:a ># a:b ? 1 : 0
|
||||
endfunction
|
||||
|
||||
function! s:binary_search(list, value, ...) abort
|
||||
let Predicate = a:0 >= 1 ? a:1 : 's:_default_compare'
|
||||
let dic = a:0 >= 2 ? a:2 : {}
|
||||
let start = 0
|
||||
let end = len(a:list) - 1
|
||||
|
||||
while 1
|
||||
if start > end
|
||||
return -1
|
||||
endif
|
||||
|
||||
let middle = (start + end) / 2
|
||||
|
||||
let compared = call(Predicate, [a:value, a:list[middle]], dic)
|
||||
|
||||
if compared < 0
|
||||
let end = middle - 1
|
||||
elseif compared > 0
|
||||
let start = middle + 1
|
||||
else
|
||||
return middle
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:product(lists) abort
|
||||
let result = [[]]
|
||||
for pool in a:lists
|
||||
let tmp = []
|
||||
for x in result
|
||||
let tmp += map(copy(pool), 'x + [v:val]')
|
||||
endfor
|
||||
let result = tmp
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! s:permutations(list, ...) abort
|
||||
if a:0 > 1
|
||||
throw 'vital: Data.List: too many arguments'
|
||||
endif
|
||||
let r = a:0 == 1 ? a:1 : len(a:list)
|
||||
if r > len(a:list)
|
||||
return []
|
||||
elseif r < 0
|
||||
throw 'vital: Data.List: {r} must be non-negative integer'
|
||||
endif
|
||||
let n = len(a:list)
|
||||
let result = []
|
||||
for indices in s:product(map(range(r), 'range(n)'))
|
||||
if len(s:uniq(indices)) == r
|
||||
call add(result, map(indices, 'a:list[v:val]'))
|
||||
endif
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! s:combinations(list, r) abort
|
||||
if a:r > len(a:list)
|
||||
return []
|
||||
elseif a:r < 0
|
||||
throw 'vital: Data:List: {r} must be non-negative integer'
|
||||
endif
|
||||
let n = len(a:list)
|
||||
let result = []
|
||||
for indices in s:permutations(range(n), a:r)
|
||||
if s:sort(copy(indices), 'a:a - a:b') == indices
|
||||
call add(result, map(indices, 'a:list[v:val]'))
|
||||
endif
|
||||
endfor
|
||||
return result
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||
|
||||
endif
|
||||
572
autoload/vital/_crystal/Data/String.vim
Normal file
572
autoload/vital/_crystal/Data/String.vim
Normal file
@@ -0,0 +1,572 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
" Utilities for string.
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:_vital_loaded(V) abort
|
||||
let s:V = a:V
|
||||
let s:P = s:V.import('Prelude')
|
||||
let s:L = s:V.import('Data.List')
|
||||
endfunction
|
||||
|
||||
function! s:_vital_depends() abort
|
||||
return ['Prelude', 'Data.List']
|
||||
endfunction
|
||||
|
||||
" Substitute a:from => a:to by string.
|
||||
" To substitute by pattern, use substitute() instead.
|
||||
function! s:replace(str, from, to) abort
|
||||
return s:_replace(a:str, a:from, a:to, 'g')
|
||||
endfunction
|
||||
|
||||
" Substitute a:from => a:to only once.
|
||||
" cf. s:replace()
|
||||
function! s:replace_first(str, from, to) abort
|
||||
return s:_replace(a:str, a:from, a:to, '')
|
||||
endfunction
|
||||
|
||||
" implement of replace() and replace_first()
|
||||
function! s:_replace(str, from, to, flags) abort
|
||||
return substitute(a:str, '\V'.escape(a:from, '\'), escape(a:to, '\'), a:flags)
|
||||
endfunction
|
||||
|
||||
function! s:scan(str, pattern) abort
|
||||
let list = []
|
||||
call substitute(a:str, a:pattern, '\=add(list, submatch(0)) == [] ? "" : ""', 'g')
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! s:reverse(str) abort
|
||||
return join(reverse(split(a:str, '.\zs')), '')
|
||||
endfunction
|
||||
|
||||
function! s:starts_with(str, prefix) abort
|
||||
return stridx(a:str, a:prefix) == 0
|
||||
endfunction
|
||||
|
||||
function! s:ends_with(str, suffix) abort
|
||||
let idx = strridx(a:str, a:suffix)
|
||||
return 0 <= idx && idx + len(a:suffix) == len(a:str)
|
||||
endfunction
|
||||
|
||||
function! s:common_head(strs) abort
|
||||
if empty(a:strs)
|
||||
return ''
|
||||
endif
|
||||
let len = len(a:strs)
|
||||
if len == 1
|
||||
return a:strs[0]
|
||||
endif
|
||||
let strs = len == 2 ? a:strs : sort(copy(a:strs))
|
||||
let pat = substitute(strs[0], '.', '\="[" . escape(submatch(0), "^\\") . "]"', 'g')
|
||||
return pat == '' ? '' : matchstr(strs[-1], '\C^\%[' . pat . ']')
|
||||
endfunction
|
||||
|
||||
" Split to two elements of List. ([left, right])
|
||||
" e.g.: s:split3('neocomplcache', 'compl') returns ['neo', 'compl', 'cache']
|
||||
function! s:split_leftright(expr, pattern) abort
|
||||
let [left, _, right] = s:split3(a:expr, a:pattern)
|
||||
return [left, right]
|
||||
endfunction
|
||||
|
||||
function! s:split3(expr, pattern) abort
|
||||
let ERROR = ['', '', '']
|
||||
if a:expr ==# '' || a:pattern ==# ''
|
||||
return ERROR
|
||||
endif
|
||||
let begin = match(a:expr, a:pattern)
|
||||
if begin is -1
|
||||
return ERROR
|
||||
endif
|
||||
let end = matchend(a:expr, a:pattern)
|
||||
let left = begin <=# 0 ? '' : a:expr[: begin - 1]
|
||||
let right = a:expr[end :]
|
||||
return [left, a:expr[begin : end-1], right]
|
||||
endfunction
|
||||
|
||||
" Slices into strings determines the number of substrings.
|
||||
" e.g.: s:nsplit("neo compl cache", 2, '\s') returns ['neo', 'compl cache']
|
||||
function! s:nsplit(expr, n, ...) abort
|
||||
let pattern = get(a:000, 0, '\s')
|
||||
let keepempty = get(a:000, 1, 1)
|
||||
let ret = []
|
||||
let expr = a:expr
|
||||
if a:n <= 1
|
||||
return [expr]
|
||||
endif
|
||||
while 1
|
||||
let pos = match(expr, pattern)
|
||||
if pos == -1
|
||||
if expr !~ pattern || keepempty
|
||||
call add(ret, expr)
|
||||
endif
|
||||
break
|
||||
elseif pos >= 0
|
||||
let left = pos > 0 ? expr[:pos-1] : ''
|
||||
if pos > 0 || keepempty
|
||||
call add(ret, left)
|
||||
endif
|
||||
let ml = len(matchstr(expr, pattern))
|
||||
if pos == 0 && ml == 0
|
||||
let pos = 1
|
||||
endif
|
||||
let expr = expr[pos+ml :]
|
||||
endif
|
||||
if len(expr) == 0
|
||||
break
|
||||
endif
|
||||
if len(ret) == a:n - 1
|
||||
call add(ret, expr)
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
" Returns the number of character in a:str.
|
||||
" NOTE: This returns proper value
|
||||
" even if a:str contains multibyte character(s).
|
||||
" s:strchars(str) {{{
|
||||
if exists('*strchars')
|
||||
function! s:strchars(str) abort
|
||||
return strchars(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:strchars(str) abort
|
||||
return strlen(substitute(copy(a:str), '.', 'x', 'g'))
|
||||
endfunction
|
||||
endif "}}}
|
||||
|
||||
" Returns the bool of contains any multibyte character in s:str
|
||||
function! s:contains_multibyte(str) abort "{{{
|
||||
return strlen(a:str) != s:strchars(a:str)
|
||||
endfunction "}}}
|
||||
|
||||
" Remove last character from a:str.
|
||||
" NOTE: This returns proper value
|
||||
" even if a:str contains multibyte character(s).
|
||||
function! s:chop(str) abort "{{{
|
||||
return substitute(a:str, '.$', '', '')
|
||||
endfunction "}}}
|
||||
|
||||
" Remove last \r,\n,\r\n from a:str.
|
||||
function! s:chomp(str) abort "{{{
|
||||
return substitute(a:str, '\%(\r\n\|[\r\n]\)$', '', '')
|
||||
endfunction "}}}
|
||||
|
||||
" wrap() and its internal functions
|
||||
" * _split_by_wcswidth_once()
|
||||
" * _split_by_wcswidth()
|
||||
" * _concat()
|
||||
" * wrap()
|
||||
"
|
||||
" NOTE _concat() is just a copy of Data.List.concat().
|
||||
" FIXME don't repeat yourself
|
||||
function! s:_split_by_wcswidth_once(body, x) abort
|
||||
let fst = s:strwidthpart(a:body, a:x)
|
||||
let snd = s:strwidthpart_reverse(a:body, s:wcswidth(a:body) - s:wcswidth(fst))
|
||||
return [fst, snd]
|
||||
endfunction
|
||||
|
||||
function! s:_split_by_wcswidth(body, x) abort
|
||||
let memo = []
|
||||
let body = a:body
|
||||
while s:wcswidth(body) > a:x
|
||||
let [tmp, body] = s:_split_by_wcswidth_once(body, a:x)
|
||||
call add(memo, tmp)
|
||||
endwhile
|
||||
call add(memo, body)
|
||||
return memo
|
||||
endfunction
|
||||
|
||||
function! s:trim(str) abort
|
||||
return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$')
|
||||
endfunction
|
||||
|
||||
function! s:trim_start(str) abort
|
||||
return matchstr(a:str,'^\s*\zs.\{-}$')
|
||||
endfunction
|
||||
|
||||
function! s:trim_end(str) abort
|
||||
return matchstr(a:str,'^.\{-}\ze\s*$')
|
||||
endfunction
|
||||
|
||||
function! s:wrap(str,...) abort
|
||||
let _columns = a:0 > 0 ? a:1 : &columns
|
||||
return s:L.concat(
|
||||
\ map(split(a:str, '\r\n\|[\r\n]'), 's:_split_by_wcswidth(v:val, _columns - 1)'))
|
||||
endfunction
|
||||
|
||||
function! s:nr2byte(nr) abort
|
||||
if a:nr < 0x80
|
||||
return nr2char(a:nr)
|
||||
elseif a:nr < 0x800
|
||||
return nr2char(a:nr/64+192).nr2char(a:nr%64+128)
|
||||
else
|
||||
return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:nr2enc_char(charcode) abort
|
||||
if &encoding == 'utf-8'
|
||||
return nr2char(a:charcode)
|
||||
endif
|
||||
let char = s:nr2byte(a:charcode)
|
||||
if strlen(char) > 1
|
||||
let char = strtrans(iconv(char, 'utf-8', &encoding))
|
||||
endif
|
||||
return char
|
||||
endfunction
|
||||
|
||||
function! s:nr2hex(nr) abort
|
||||
let n = a:nr
|
||||
let r = ""
|
||||
while n
|
||||
let r = '0123456789ABCDEF'[n % 16] . r
|
||||
let n = n / 16
|
||||
endwhile
|
||||
return r
|
||||
endfunction
|
||||
|
||||
" If a ==# b, returns -1.
|
||||
" If a !=# b, returns first index of different character.
|
||||
function! s:diffidx(a, b) abort
|
||||
return a:a ==# a:b ? -1 : strlen(s:common_head([a:a, a:b]))
|
||||
endfunction
|
||||
|
||||
function! s:substitute_last(expr, pat, sub) abort
|
||||
return substitute(a:expr, printf('.*\zs%s', a:pat), a:sub, '')
|
||||
endfunction
|
||||
|
||||
function! s:dstring(expr) abort
|
||||
let x = substitute(string(a:expr), "^'\\|'$", '', 'g')
|
||||
let x = substitute(x, "''", "'", 'g')
|
||||
return printf('"%s"', escape(x, '"'))
|
||||
endfunction
|
||||
|
||||
function! s:lines(str) abort
|
||||
return split(a:str, '\r\?\n')
|
||||
endfunction
|
||||
|
||||
function! s:_pad_with_char(str, left, right, char) abort
|
||||
return repeat(a:char, a:left). a:str. repeat(a:char, a:right)
|
||||
endfunction
|
||||
|
||||
function! s:pad_left(str, width, ...) abort
|
||||
let char = get(a:, 1, ' ')
|
||||
if strdisplaywidth(char) != 1
|
||||
throw "vital: Data.String: Can't use non-half-width characters for padding."
|
||||
endif
|
||||
let left = max([0, a:width - strdisplaywidth(a:str)])
|
||||
return s:_pad_with_char(a:str, left, 0, char)
|
||||
endfunction
|
||||
|
||||
function! s:pad_right(str, width, ...) abort
|
||||
let char = get(a:, 1, ' ')
|
||||
if strdisplaywidth(char) != 1
|
||||
throw "vital: Data.String: Can't use non-half-width characters for padding."
|
||||
endif
|
||||
let right = max([0, a:width - strdisplaywidth(a:str)])
|
||||
return s:_pad_with_char(a:str, 0, right, char)
|
||||
endfunction
|
||||
|
||||
function! s:pad_both_sides(str, width, ...) abort
|
||||
let char = get(a:, 1, ' ')
|
||||
if strdisplaywidth(char) != 1
|
||||
throw "vital: Data.String: Can't use non-half-width characters for padding."
|
||||
endif
|
||||
let space = max([0, a:width - strdisplaywidth(a:str)])
|
||||
let left = space / 2
|
||||
let right = space - left
|
||||
return s:_pad_with_char(a:str, left, right, char)
|
||||
endfunction
|
||||
|
||||
function! s:pad_between_letters(str, width, ...) abort
|
||||
let char = get(a:, 1, ' ')
|
||||
if strdisplaywidth(char) != 1
|
||||
throw "vital: Data.String: Can't use non-half-width characters for padding."
|
||||
endif
|
||||
let letters = split(a:str, '\zs')
|
||||
let each_width = a:width / len(letters)
|
||||
let str = join(map(letters, 's:pad_both_sides(v:val, each_width, char)'), '')
|
||||
if a:width - strdisplaywidth(str) > 0
|
||||
return char. s:pad_both_sides(str, a:width - 1, char)
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! s:justify_equal_spacing(str, width, ...) abort
|
||||
let char = get(a:, 1, ' ')
|
||||
if strdisplaywidth(char) != 1
|
||||
throw "vital: Data.String: Can't use non-half-width characters for padding."
|
||||
endif
|
||||
let letters = split(a:str, '\zs')
|
||||
let first_letter = letters[0]
|
||||
" {width w/o the first letter} / {length w/o the first letter}
|
||||
let each_width = (a:width - strdisplaywidth(first_letter)) / (len(letters) - 1)
|
||||
let remainder = (a:width - strdisplaywidth(first_letter)) % (len(letters) - 1)
|
||||
return first_letter. join(s:L.concat([
|
||||
\ map(letters[1:remainder], 's:pad_left(v:val, each_width + 1, char)'),
|
||||
\ map(letters[remainder + 1:], 's:pad_left(v:val, each_width, char)')
|
||||
\ ]), '')
|
||||
endfunction
|
||||
|
||||
function! s:levenshtein_distance(str1, str2) abort
|
||||
let letters1 = split(a:str1, '\zs')
|
||||
let letters2 = split(a:str2, '\zs')
|
||||
let length1 = len(letters1)
|
||||
let length2 = len(letters2)
|
||||
let distances = map(range(1, length1 + 1), 'map(range(1, length2 + 1), "0")')
|
||||
|
||||
for i1 in range(0, length1)
|
||||
let distances[i1][0] = i1
|
||||
endfor
|
||||
for i2 in range(0, length2)
|
||||
let distances[0][i2] = i2
|
||||
endfor
|
||||
|
||||
for i1 in range(1, length1)
|
||||
for i2 in range(1, length2)
|
||||
let cost = (letters1[i1 - 1] ==# letters2[i2 - 1]) ? 0 : 1
|
||||
|
||||
let distances[i1][i2] = min([
|
||||
\ distances[i1 - 1][i2 ] + 1,
|
||||
\ distances[i1 ][i2 - 1] + 1,
|
||||
\ distances[i1 - 1][i2 - 1] + cost,
|
||||
\])
|
||||
endfor
|
||||
endfor
|
||||
|
||||
return distances[length1][length2]
|
||||
endfunction
|
||||
|
||||
function! s:padding_by_displaywidth(expr, width, float) abort
|
||||
let padding_char = ' '
|
||||
let n = a:width - strdisplaywidth(a:expr)
|
||||
if n <= 0
|
||||
let n = 0
|
||||
endif
|
||||
if a:float < 0
|
||||
return a:expr . repeat(padding_char, n)
|
||||
elseif 0 < a:float
|
||||
return repeat(padding_char, n) . a:expr
|
||||
else
|
||||
if n % 2 is 0
|
||||
return repeat(padding_char, n / 2) . a:expr . repeat(padding_char, n / 2)
|
||||
else
|
||||
return repeat(padding_char, (n - 1) / 2) . a:expr . repeat(padding_char, (n - 1) / 2) . padding_char
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:split_by_displaywidth(expr, width, float, is_wrap) abort
|
||||
if a:width is 0
|
||||
return ['']
|
||||
endif
|
||||
|
||||
let lines = []
|
||||
|
||||
let cs = split(a:expr, '\zs')
|
||||
let cs_index = 0
|
||||
|
||||
let text = ''
|
||||
while cs_index < len(cs)
|
||||
if cs[cs_index] is "\n"
|
||||
let text = s:padding_by_displaywidth(text, a:width, a:float)
|
||||
let lines += [text]
|
||||
let text = ''
|
||||
else
|
||||
let w = strdisplaywidth(text . cs[cs_index])
|
||||
|
||||
if w < a:width
|
||||
let text .= cs[cs_index]
|
||||
elseif a:width < w
|
||||
let text = s:padding_by_displaywidth(text, a:width, a:float)
|
||||
else
|
||||
let text .= cs[cs_index]
|
||||
endif
|
||||
|
||||
if a:width <= w
|
||||
let lines += [text]
|
||||
let text = ''
|
||||
if a:is_wrap
|
||||
if a:width < w
|
||||
if a:width < strdisplaywidth(cs[cs_index])
|
||||
while get(cs, cs_index, "\n") isnot "\n"
|
||||
let cs_index += 1
|
||||
endwhile
|
||||
continue
|
||||
else
|
||||
let text = cs[cs_index]
|
||||
endif
|
||||
endif
|
||||
else
|
||||
while get(cs, cs_index, "\n") isnot "\n"
|
||||
let cs_index += 1
|
||||
endwhile
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
||||
endif
|
||||
let cs_index += 1
|
||||
endwhile
|
||||
|
||||
if !empty(text)
|
||||
let lines += [ s:padding_by_displaywidth(text, a:width, a:float) ]
|
||||
endif
|
||||
|
||||
return lines
|
||||
endfunction
|
||||
|
||||
function! s:hash(str) abort
|
||||
if exists('*sha256')
|
||||
return sha256(a:str)
|
||||
else
|
||||
" This gives up sha256ing but just adds up char with index.
|
||||
let sum = 0
|
||||
for i in range(len(a:str))
|
||||
let sum += char2nr(a:str[i]) * (i + 1)
|
||||
endfor
|
||||
|
||||
return printf('%x', sum)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:truncate(str, width) abort
|
||||
" Original function is from mattn.
|
||||
" http://github.com/mattn/googlereader-vim/tree/master
|
||||
|
||||
if a:str =~# '^[\x00-\x7f]*$'
|
||||
return len(a:str) < a:width ?
|
||||
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
|
||||
endif
|
||||
|
||||
let ret = a:str
|
||||
let width = s:wcswidth(a:str)
|
||||
if width > a:width
|
||||
let ret = s:strwidthpart(ret, a:width)
|
||||
let width = s:wcswidth(ret)
|
||||
endif
|
||||
|
||||
if width < a:width
|
||||
let ret .= repeat(' ', a:width - width)
|
||||
endif
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! s:truncate_skipping(str, max, footer_width, separator) abort
|
||||
let width = s:wcswidth(a:str)
|
||||
if width <= a:max
|
||||
let ret = a:str
|
||||
else
|
||||
let header_width = a:max - s:wcswidth(a:separator) - a:footer_width
|
||||
let ret = s:strwidthpart(a:str, header_width) . a:separator
|
||||
\ . s:strwidthpart_reverse(a:str, a:footer_width)
|
||||
endif
|
||||
return s:truncate(ret, a:max)
|
||||
endfunction
|
||||
|
||||
function! s:strwidthpart(str, width) abort
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
let strarr = split(a:str, '\zs')
|
||||
let width = s:wcswidth(a:str)
|
||||
let index = len(strarr)
|
||||
let diff = (index + 1) / 2
|
||||
let rightindex = index - 1
|
||||
while width > a:width
|
||||
let index = max([rightindex - diff + 1, 0])
|
||||
let partwidth = s:wcswidth(join(strarr[(index):(rightindex)], ''))
|
||||
if width - partwidth >= a:width || diff <= 1
|
||||
let width -= partwidth
|
||||
let rightindex = index - 1
|
||||
endif
|
||||
if diff > 1
|
||||
let diff = diff / 2
|
||||
endif
|
||||
endwhile
|
||||
return index ? join(strarr[:index - 1], '') : ''
|
||||
endfunction
|
||||
|
||||
function! s:strwidthpart_reverse(str, width) abort
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
let strarr = split(a:str, '\zs')
|
||||
let width = s:wcswidth(a:str)
|
||||
let strlen = len(strarr)
|
||||
let diff = (strlen + 1) / 2
|
||||
let leftindex = 0
|
||||
let index = -1
|
||||
while width > a:width
|
||||
let index = min([leftindex + diff, strlen]) - 1
|
||||
let partwidth = s:wcswidth(join(strarr[(leftindex):(index)], ''))
|
||||
if width - partwidth >= a:width || diff <= 1
|
||||
let width -= partwidth
|
||||
let leftindex = index + 1
|
||||
endif
|
||||
if diff > 1
|
||||
let diff = diff / 2
|
||||
endif
|
||||
endwhile
|
||||
return index < strlen ? join(strarr[(index + 1):], '') : ''
|
||||
endfunction
|
||||
|
||||
if v:version >= 703
|
||||
" Use builtin function.
|
||||
function! s:wcswidth(str) abort
|
||||
return strwidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:wcswidth(str) abort
|
||||
if a:str =~# '^[\x00-\x7f]*$'
|
||||
return strlen(a:str)
|
||||
endif
|
||||
let mx_first = '^\(.\)'
|
||||
let str = a:str
|
||||
let width = 0
|
||||
while 1
|
||||
let ucs = char2nr(substitute(str, mx_first, '\1', ''))
|
||||
if ucs == 0
|
||||
break
|
||||
endif
|
||||
let width += s:_wcwidth(ucs)
|
||||
let str = substitute(str, mx_first, '', '')
|
||||
endwhile
|
||||
return width
|
||||
endfunction
|
||||
|
||||
" UTF-8 only.
|
||||
function! s:_wcwidth(ucs) abort
|
||||
let ucs = a:ucs
|
||||
if (ucs >= 0x1100
|
||||
\ && (ucs <= 0x115f
|
||||
\ || ucs == 0x2329
|
||||
\ || ucs == 0x232a
|
||||
\ || (ucs >= 0x2e80 && ucs <= 0xa4cf
|
||||
\ && ucs != 0x303f)
|
||||
\ || (ucs >= 0xac00 && ucs <= 0xd7a3)
|
||||
\ || (ucs >= 0xf900 && ucs <= 0xfaff)
|
||||
\ || (ucs >= 0xfe30 && ucs <= 0xfe6f)
|
||||
\ || (ucs >= 0xff00 && ucs <= 0xff60)
|
||||
\ || (ucs >= 0xffe0 && ucs <= 0xffe6)
|
||||
\ || (ucs >= 0x20000 && ucs <= 0x2fffd)
|
||||
\ || (ucs >= 0x30000 && ucs <= 0x3fffd)
|
||||
\ ))
|
||||
return 2
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
endif
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||
|
||||
endif
|
||||
389
autoload/vital/_crystal/Prelude.vim
Normal file
389
autoload/vital/_crystal/Prelude.vim
Normal file
@@ -0,0 +1,389 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if v:version ># 703 ||
|
||||
\ (v:version is 703 && has('patch465'))
|
||||
function! s:glob(expr) abort
|
||||
return glob(a:expr, 1, 1)
|
||||
endfunction
|
||||
else
|
||||
function! s:glob(expr) abort
|
||||
let R = glob(a:expr, 1)
|
||||
return split(R, '\n')
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:globpath(path, expr) abort
|
||||
let R = globpath(a:path, a:expr, 1)
|
||||
return split(R, '\n')
|
||||
endfunction
|
||||
|
||||
" Wrapper functions for type().
|
||||
let [
|
||||
\ s:__TYPE_NUMBER,
|
||||
\ s:__TYPE_STRING,
|
||||
\ s:__TYPE_FUNCREF,
|
||||
\ s:__TYPE_LIST,
|
||||
\ s:__TYPE_DICT,
|
||||
\ s:__TYPE_FLOAT] = [
|
||||
\ type(3),
|
||||
\ type(""),
|
||||
\ type(function('tr')),
|
||||
\ type([]),
|
||||
\ type({}),
|
||||
\ has('float') ? type(str2float('0')) : -1]
|
||||
" __TYPE_FLOAT = -1 when -float
|
||||
" This doesn't match to anything.
|
||||
|
||||
" Number or Float
|
||||
function! s:is_numeric(Value) abort
|
||||
let _ = type(a:Value)
|
||||
return _ ==# s:__TYPE_NUMBER
|
||||
\ || _ ==# s:__TYPE_FLOAT
|
||||
endfunction
|
||||
|
||||
" Number
|
||||
function! s:is_number(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_NUMBER
|
||||
endfunction
|
||||
|
||||
" Float
|
||||
function! s:is_float(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_FLOAT
|
||||
endfunction
|
||||
" String
|
||||
function! s:is_string(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_STRING
|
||||
endfunction
|
||||
" Funcref
|
||||
function! s:is_funcref(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_FUNCREF
|
||||
endfunction
|
||||
" List
|
||||
function! s:is_list(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_LIST
|
||||
endfunction
|
||||
" Dictionary
|
||||
function! s:is_dict(Value) abort
|
||||
return type(a:Value) ==# s:__TYPE_DICT
|
||||
endfunction
|
||||
|
||||
function! s:truncate_skipping(str, max, footer_width, separator) abort
|
||||
call s:_warn_deprecated("truncate_skipping", "Data.String.truncate_skipping")
|
||||
|
||||
let width = s:wcswidth(a:str)
|
||||
if width <= a:max
|
||||
let ret = a:str
|
||||
else
|
||||
let header_width = a:max - s:wcswidth(a:separator) - a:footer_width
|
||||
let ret = s:strwidthpart(a:str, header_width) . a:separator
|
||||
\ . s:strwidthpart_reverse(a:str, a:footer_width)
|
||||
endif
|
||||
|
||||
return s:truncate(ret, a:max)
|
||||
endfunction
|
||||
|
||||
function! s:truncate(str, width) abort
|
||||
" Original function is from mattn.
|
||||
" http://github.com/mattn/googlereader-vim/tree/master
|
||||
|
||||
call s:_warn_deprecated("truncate", "Data.String.truncate")
|
||||
|
||||
if a:str =~# '^[\x00-\x7f]*$'
|
||||
return len(a:str) < a:width ?
|
||||
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
|
||||
endif
|
||||
|
||||
let ret = a:str
|
||||
let width = s:wcswidth(a:str)
|
||||
if width > a:width
|
||||
let ret = s:strwidthpart(ret, a:width)
|
||||
let width = s:wcswidth(ret)
|
||||
endif
|
||||
|
||||
if width < a:width
|
||||
let ret .= repeat(' ', a:width - width)
|
||||
endif
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! s:strwidthpart(str, width) abort
|
||||
call s:_warn_deprecated("strwidthpart", "Data.String.strwidthpart")
|
||||
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
let ret = a:str
|
||||
let width = s:wcswidth(a:str)
|
||||
while width > a:width
|
||||
let char = matchstr(ret, '.$')
|
||||
let ret = ret[: -1 - len(char)]
|
||||
let width -= s:wcswidth(char)
|
||||
endwhile
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
function! s:strwidthpart_reverse(str, width) abort
|
||||
call s:_warn_deprecated("strwidthpart_reverse", "Data.String.strwidthpart_reverse")
|
||||
|
||||
if a:width <= 0
|
||||
return ''
|
||||
endif
|
||||
let ret = a:str
|
||||
let width = s:wcswidth(a:str)
|
||||
while width > a:width
|
||||
let char = matchstr(ret, '^.')
|
||||
let ret = ret[len(char) :]
|
||||
let width -= s:wcswidth(char)
|
||||
endwhile
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
if v:version >= 703
|
||||
" Use builtin function.
|
||||
function! s:wcswidth(str) abort
|
||||
call s:_warn_deprecated("wcswidth", "Data.String.wcswidth")
|
||||
return strwidth(a:str)
|
||||
endfunction
|
||||
else
|
||||
function! s:wcswidth(str) abort
|
||||
call s:_warn_deprecated("wcswidth", "Data.String.wcswidth")
|
||||
|
||||
if a:str =~# '^[\x00-\x7f]*$'
|
||||
return strlen(a:str)
|
||||
end
|
||||
|
||||
let mx_first = '^\(.\)'
|
||||
let str = a:str
|
||||
let width = 0
|
||||
while 1
|
||||
let ucs = char2nr(substitute(str, mx_first, '\1', ''))
|
||||
if ucs == 0
|
||||
break
|
||||
endif
|
||||
let width += s:_wcwidth(ucs)
|
||||
let str = substitute(str, mx_first, '', '')
|
||||
endwhile
|
||||
return width
|
||||
endfunction
|
||||
|
||||
" UTF-8 only.
|
||||
function! s:_wcwidth(ucs) abort
|
||||
let ucs = a:ucs
|
||||
if (ucs >= 0x1100
|
||||
\ && (ucs <= 0x115f
|
||||
\ || ucs == 0x2329
|
||||
\ || ucs == 0x232a
|
||||
\ || (ucs >= 0x2e80 && ucs <= 0xa4cf
|
||||
\ && ucs != 0x303f)
|
||||
\ || (ucs >= 0xac00 && ucs <= 0xd7a3)
|
||||
\ || (ucs >= 0xf900 && ucs <= 0xfaff)
|
||||
\ || (ucs >= 0xfe30 && ucs <= 0xfe6f)
|
||||
\ || (ucs >= 0xff00 && ucs <= 0xff60)
|
||||
\ || (ucs >= 0xffe0 && ucs <= 0xffe6)
|
||||
\ || (ucs >= 0x20000 && ucs <= 0x2fffd)
|
||||
\ || (ucs >= 0x30000 && ucs <= 0x3fffd)
|
||||
\ ))
|
||||
return 2
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
endif
|
||||
|
||||
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
|
||||
let s:is_cygwin = has('win32unix')
|
||||
let s:is_mac = !s:is_windows && !s:is_cygwin
|
||||
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
||||
\ (!isdirectory('/proc') && executable('sw_vers')))
|
||||
let s:is_unix = has('unix')
|
||||
|
||||
function! s:is_windows() abort
|
||||
return s:is_windows
|
||||
endfunction
|
||||
|
||||
function! s:is_cygwin() abort
|
||||
return s:is_cygwin
|
||||
endfunction
|
||||
|
||||
function! s:is_mac() abort
|
||||
return s:is_mac
|
||||
endfunction
|
||||
|
||||
function! s:is_unix() abort
|
||||
return s:is_unix
|
||||
endfunction
|
||||
|
||||
function! s:_warn_deprecated(name, alternative) abort
|
||||
try
|
||||
echohl Error
|
||||
echomsg "Prelude." . a:name . " is deprecated! Please use " . a:alternative . " instead."
|
||||
finally
|
||||
echohl None
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:smart_execute_command(action, word) abort
|
||||
execute a:action . ' ' . (a:word == '' ? '' : '`=a:word`')
|
||||
endfunction
|
||||
|
||||
function! s:escape_file_searching(buffer_name) abort
|
||||
return escape(a:buffer_name, '*[]?{}, ')
|
||||
endfunction
|
||||
|
||||
function! s:escape_pattern(str) abort
|
||||
return escape(a:str, '~"\.^$[]*')
|
||||
endfunction
|
||||
|
||||
function! s:getchar(...) abort
|
||||
let c = call('getchar', a:000)
|
||||
return type(c) == type(0) ? nr2char(c) : c
|
||||
endfunction
|
||||
|
||||
function! s:getchar_safe(...) abort
|
||||
let c = s:input_helper('getchar', a:000)
|
||||
return type(c) == type("") ? c : nr2char(c)
|
||||
endfunction
|
||||
|
||||
function! s:input_safe(...) abort
|
||||
return s:input_helper('input', a:000)
|
||||
endfunction
|
||||
|
||||
function! s:input_helper(funcname, args) abort
|
||||
let success = 0
|
||||
if inputsave() !=# success
|
||||
throw 'vital: Prelude: inputsave() failed'
|
||||
endif
|
||||
try
|
||||
return call(a:funcname, a:args)
|
||||
finally
|
||||
if inputrestore() !=# success
|
||||
throw 'vital: Prelude: inputrestore() failed'
|
||||
endif
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:set_default(var, val) abort
|
||||
if !exists(a:var) || type({a:var}) != type(a:val)
|
||||
let {a:var} = a:val
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:substitute_path_separator(path) abort
|
||||
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
||||
endfunction
|
||||
|
||||
function! s:path2directory(path) abort
|
||||
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_git(path) abort
|
||||
let parent = a:path
|
||||
|
||||
while 1
|
||||
let path = parent . '/.git'
|
||||
if isdirectory(path) || filereadable(path)
|
||||
return parent
|
||||
endif
|
||||
let next = fnamemodify(parent, ':h')
|
||||
if next == parent
|
||||
return ''
|
||||
endif
|
||||
let parent = next
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_svn(path) abort
|
||||
let search_directory = a:path
|
||||
let directory = ''
|
||||
|
||||
let find_directory = s:escape_file_searching(search_directory)
|
||||
let d = finddir('.svn', find_directory . ';')
|
||||
if d == ''
|
||||
return ''
|
||||
endif
|
||||
|
||||
let directory = fnamemodify(d, ':p:h:h')
|
||||
|
||||
" Search parent directories.
|
||||
let parent_directory = s:path2directory(
|
||||
\ fnamemodify(directory, ':h'))
|
||||
|
||||
if parent_directory != ''
|
||||
let d = finddir('.svn', parent_directory . ';')
|
||||
if d != ''
|
||||
let directory = s:_path2project_directory_svn(parent_directory)
|
||||
endif
|
||||
endif
|
||||
return directory
|
||||
endfunction
|
||||
|
||||
function! s:_path2project_directory_others(vcs, path) abort
|
||||
let vcs = a:vcs
|
||||
let search_directory = a:path
|
||||
|
||||
let find_directory = s:escape_file_searching(search_directory)
|
||||
let d = finddir(vcs, find_directory . ';')
|
||||
if d == ''
|
||||
return ''
|
||||
endif
|
||||
return fnamemodify(d, ':p:h:h')
|
||||
endfunction
|
||||
|
||||
function! s:path2project_directory(path, ...) abort
|
||||
let is_allow_empty = get(a:000, 0, 0)
|
||||
let search_directory = s:path2directory(a:path)
|
||||
let directory = ''
|
||||
|
||||
" Search VCS directory.
|
||||
for vcs in ['.git', '.bzr', '.hg', '.svn']
|
||||
if vcs ==# '.git'
|
||||
let directory = s:_path2project_directory_git(search_directory)
|
||||
elseif vcs ==# '.svn'
|
||||
let directory = s:_path2project_directory_svn(search_directory)
|
||||
else
|
||||
let directory = s:_path2project_directory_others(vcs, search_directory)
|
||||
endif
|
||||
if directory != ''
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Search project file.
|
||||
if directory == ''
|
||||
for d in ['build.xml', 'prj.el', '.project', 'pom.xml', 'package.json',
|
||||
\ 'Makefile', 'configure', 'Rakefile', 'NAnt.build',
|
||||
\ 'P4CONFIG', 'tags', 'gtags']
|
||||
let d = findfile(d, s:escape_file_searching(search_directory) . ';')
|
||||
if d != ''
|
||||
let directory = fnamemodify(d, ':p:h')
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if directory == ''
|
||||
" Search /src/ directory.
|
||||
let base = s:substitute_path_separator(search_directory)
|
||||
if base =~# '/src/'
|
||||
let directory = base[: strridx(base, '/src/') + 3]
|
||||
endif
|
||||
endif
|
||||
|
||||
if directory == '' && !is_allow_empty
|
||||
" Use original path.
|
||||
let directory = search_directory
|
||||
endif
|
||||
|
||||
return s:substitute_path_separator(directory)
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||
|
||||
endif
|
||||
185
autoload/vital/_crystal/Process.vim
Normal file
185
autoload/vital/_crystal/Process.vim
Normal file
@@ -0,0 +1,185 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
" TODO: move all comments to doc file.
|
||||
"
|
||||
"
|
||||
" FIXME: This module name should be Vital.System ?
|
||||
" But the name has been already taken.
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
|
||||
" FIXME: Unfortunately, can't use s:_vital_loaded() for this purpose.
|
||||
" Because these variables are used when this script file is loaded.
|
||||
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
|
||||
let s:is_unix = has('unix')
|
||||
" As of 7.4.122, the system()'s 1st argument is converted internally by Vim.
|
||||
" Note that Patch 7.4.122 does not convert system()'s 2nd argument and
|
||||
" return-value. We must convert them manually.
|
||||
let s:need_trans = v:version < 704 || (v:version == 704 && !has('patch122'))
|
||||
|
||||
let s:TYPE_DICT = type({})
|
||||
let s:TYPE_LIST = type([])
|
||||
let s:TYPE_STRING = type("")
|
||||
|
||||
|
||||
" Execute program in the background from Vim.
|
||||
" Return an empty string always.
|
||||
"
|
||||
" If a:expr is a List, shellescape() each argument.
|
||||
" If a:expr is a String, the arguments are passed as-is.
|
||||
"
|
||||
" Windows:
|
||||
" Using :!start , execute program without via cmd.exe.
|
||||
" Spawning 'expr' with 'noshellslash'
|
||||
" keep special characters from unwanted expansion.
|
||||
" (see :help shellescape())
|
||||
"
|
||||
" Unix:
|
||||
" using :! , execute program in the background by shell.
|
||||
function! s:spawn(expr, ...) abort
|
||||
let shellslash = 0
|
||||
if s:is_windows
|
||||
let shellslash = &l:shellslash
|
||||
setlocal noshellslash
|
||||
endif
|
||||
try
|
||||
if type(a:expr) is s:TYPE_LIST
|
||||
let special = 1
|
||||
let cmdline = join(map(a:expr, 'shellescape(v:val, special)'), ' ')
|
||||
elseif type(a:expr) is s:TYPE_STRING
|
||||
let cmdline = a:expr
|
||||
if a:0 && a:1
|
||||
" for :! command
|
||||
let cmdline = substitute(cmdline, '\([!%#]\|<[^<>]\+>\)', '\\\1', 'g')
|
||||
endif
|
||||
else
|
||||
throw 'Process.spawn(): invalid argument (value type:'.type(a:expr).')'
|
||||
endif
|
||||
if s:is_windows
|
||||
silent execute '!start' cmdline
|
||||
else
|
||||
silent execute '!' cmdline '&'
|
||||
endif
|
||||
finally
|
||||
if s:is_windows
|
||||
let &l:shellslash = shellslash
|
||||
endif
|
||||
endtry
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" iconv() wrapper for safety.
|
||||
function! s:iconv(expr, from, to) abort
|
||||
if a:from == '' || a:to == '' || a:from ==? a:to
|
||||
return a:expr
|
||||
endif
|
||||
let result = iconv(a:expr, a:from, a:to)
|
||||
return result != '' ? result : a:expr
|
||||
endfunction
|
||||
|
||||
" Check vimproc.
|
||||
function! s:has_vimproc() abort
|
||||
if !exists('s:exists_vimproc')
|
||||
try
|
||||
call vimproc#version()
|
||||
let s:exists_vimproc = 1
|
||||
catch
|
||||
let s:exists_vimproc = 0
|
||||
endtry
|
||||
endif
|
||||
return s:exists_vimproc
|
||||
endfunction
|
||||
|
||||
" * {command} [, {input} [, {timeout}]]
|
||||
" * {command} [, {dict}]
|
||||
" {dict} = {
|
||||
" use_vimproc: bool,
|
||||
" input: string,
|
||||
" timeout: bool,
|
||||
" background: bool,
|
||||
" }
|
||||
function! s:system(str, ...) abort
|
||||
" Process optional arguments at first
|
||||
" because use_vimproc is required later
|
||||
" for a:str argument.
|
||||
let input = ''
|
||||
let use_vimproc = s:has_vimproc()
|
||||
let background = 0
|
||||
let args = []
|
||||
if a:0 ==# 1
|
||||
" {command} [, {dict}]
|
||||
" a:1 = {dict}
|
||||
if type(a:1) is s:TYPE_DICT
|
||||
if has_key(a:1, 'use_vimproc')
|
||||
let use_vimproc = a:1.use_vimproc
|
||||
endif
|
||||
if has_key(a:1, 'input')
|
||||
let args += [s:iconv(a:1.input, &encoding, 'char')]
|
||||
endif
|
||||
if use_vimproc && has_key(a:1, 'timeout')
|
||||
" ignores timeout unless you have vimproc.
|
||||
let args += [a:1.timeout]
|
||||
endif
|
||||
if has_key(a:1, 'background')
|
||||
let background = a:1.background
|
||||
endif
|
||||
elseif type(a:1) is s:TYPE_STRING
|
||||
let args += [s:iconv(a:1, &encoding, 'char')]
|
||||
else
|
||||
throw 'Process.system(): invalid argument (value type:'.type(a:1).')'
|
||||
endif
|
||||
elseif a:0 >= 2
|
||||
" {command} [, {input} [, {timeout}]]
|
||||
" a:000 = [{input} [, {timeout}]]
|
||||
let [input; rest] = a:000
|
||||
let input = s:iconv(input, &encoding, 'char')
|
||||
let args += [input] + rest
|
||||
endif
|
||||
|
||||
" Process a:str argument.
|
||||
if type(a:str) is s:TYPE_LIST
|
||||
let expr = use_vimproc ? '"''" . v:val . "''"' : 's:shellescape(v:val)'
|
||||
let command = join(map(copy(a:str), expr), ' ')
|
||||
elseif type(a:str) is s:TYPE_STRING
|
||||
let command = a:str
|
||||
else
|
||||
throw 'Process.system(): invalid argument (value type:'.type(a:str).')'
|
||||
endif
|
||||
if s:need_trans
|
||||
let command = s:iconv(command, &encoding, 'char')
|
||||
endif
|
||||
let args = [command] + args
|
||||
if background && (use_vimproc || !s:is_windows)
|
||||
let args[0] = args[0] . ' &'
|
||||
endif
|
||||
|
||||
let funcname = use_vimproc ? 'vimproc#system' : 'system'
|
||||
let output = call(funcname, args)
|
||||
let output = s:iconv(output, 'char', &encoding)
|
||||
return output
|
||||
endfunction
|
||||
|
||||
function! s:get_last_status() abort
|
||||
return s:has_vimproc() ?
|
||||
\ vimproc#get_last_status() : v:shell_error
|
||||
endfunction
|
||||
|
||||
if s:is_windows
|
||||
function! s:shellescape(command) abort
|
||||
return substitute(a:command, '[&()[\]{}^=;!''+,`~]', '^\0', 'g')
|
||||
endfunction
|
||||
else
|
||||
function! s:shellescape(...) abort
|
||||
return call('shellescape', a:000)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||
|
||||
endif
|
||||
112
autoload/vital/_crystal/Web/JSON.vim
Normal file
112
autoload/vital/_crystal/Web/JSON.vim
Normal file
@@ -0,0 +1,112 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:_true() abort
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:_false() abort
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:_null() abort
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
let s:const = {}
|
||||
let s:const.true = function('s:_true')
|
||||
let s:const.false = function('s:_false')
|
||||
let s:const.null = function('s:_null')
|
||||
|
||||
function! s:_resolve(val, prefix) abort
|
||||
let t = type(a:val)
|
||||
if t == type('')
|
||||
let m = matchlist(a:val, '^' . a:prefix . '\(null\|true\|false\)$')
|
||||
if !empty(m)
|
||||
return s:const[m[1]]
|
||||
endif
|
||||
elseif t == type([]) || t == type({})
|
||||
return map(a:val, 's:_resolve(v:val, a:prefix)')
|
||||
endif
|
||||
return a:val
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:_vital_created(module) abort
|
||||
" define constant variables
|
||||
call extend(a:module, s:const)
|
||||
endfunction
|
||||
|
||||
function! s:_vital_loaded(V) abort
|
||||
let s:V = a:V
|
||||
let s:string = s:V.import('Data.String')
|
||||
endfunction
|
||||
|
||||
function! s:_vital_depends() abort
|
||||
return ['Data.String']
|
||||
endfunction
|
||||
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
function! s:decode(json, ...) abort
|
||||
let settings = extend({
|
||||
\ 'use_token': 0,
|
||||
\}, get(a:000, 0, {}))
|
||||
let json = iconv(a:json, "utf-8", &encoding)
|
||||
let json = join(split(json, "\n"), '')
|
||||
let json = substitute(json, '\\u34;', '\\"', 'g')
|
||||
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=s:string.nr2enc_char("0x".submatch(1))', 'g')
|
||||
if settings.use_token
|
||||
let prefix = '__Web.JSON__'
|
||||
while stridx(json, prefix) != -1
|
||||
let prefix .= '_'
|
||||
endwhile
|
||||
let [null,true,false] = map(['null','true','false'], 'prefix . v:val')
|
||||
sandbox return s:_resolve(eval(json), prefix)
|
||||
else
|
||||
let [null,true,false] = [s:const.null(),s:const.true(),s:const.false()]
|
||||
sandbox return eval(json)
|
||||
endif
|
||||
endfunction
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
" @vimlint(EVL102, 0, l:true)
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
|
||||
function! s:encode(val) abort
|
||||
if type(a:val) == 0
|
||||
return a:val
|
||||
elseif type(a:val) == 1
|
||||
let json = '"' . escape(a:val, '\"') . '"'
|
||||
let json = substitute(json, "\r", '\\r', 'g')
|
||||
let json = substitute(json, "\n", '\\n', 'g')
|
||||
let json = substitute(json, "\t", '\\t', 'g')
|
||||
return iconv(json, &encoding, "utf-8")
|
||||
elseif type(a:val) == 2
|
||||
if s:const.true == a:val
|
||||
return 'true'
|
||||
elseif s:const.false == a:val
|
||||
return 'false'
|
||||
elseif s:const.null == a:val
|
||||
return 'null'
|
||||
else
|
||||
" backward compatibility
|
||||
return string(a:val)
|
||||
endif
|
||||
elseif type(a:val) == 3
|
||||
return '[' . join(map(copy(a:val), 's:encode(v:val)'), ',') . ']'
|
||||
elseif type(a:val) == 4
|
||||
return '{' . join(map(keys(a:val), 's:encode(v:val).":".s:encode(a:val[v:val])'), ',') . '}'
|
||||
else
|
||||
return string(a:val)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||
|
||||
endif
|
||||
@@ -1,9 +1,9 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
||||
|
||||
" Vim completion for HTML5 data file
|
||||
" Language: HTML5
|
||||
" Maintainer: othree <othree@gmail.com>
|
||||
" Last Change: 2011 Apr 9
|
||||
" Language: HTML (version 5.1 Draft 2016 Jan 13)
|
||||
" Maintainer: Kao, Wei-Ko(othree) ( othree AT gmail DOT com )
|
||||
" Last Change: 2016 Jan 20
|
||||
|
||||
|
||||
" Lang Tag: {{{
|
||||
@@ -598,9 +598,13 @@ let g:xmldata_html5 = {
|
||||
\ global_attributes
|
||||
\ ],
|
||||
\ 'menu': [
|
||||
\ flow_elements + ['li'],
|
||||
\ flow_elements + ['menuitem'],
|
||||
\ extend(copy(global_attributes), {'type': ['toolbar', 'context'], 'label': []})
|
||||
\ ],
|
||||
\ 'menuitem': [
|
||||
\ flow_elements + ['li'],
|
||||
\ extend(copy(global_attributes), {'type': ['toolbar', 'context'], 'label': [], 'icon': [], 'disabled': [], 'checked': [], 'radiogroup': [], 'default': [], 'command': []})
|
||||
\ ],
|
||||
\ 'meta': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'name': ['application-name', 'author', 'description', 'generator', 'referrer', 'creator', 'googlebot', 'publisher', 'robots', 'slurp', 'viewport', 'theme-color'], 'http-equiv': ['refresh', 'default-style', 'content-type'], 'content': [], 'charset': charset})
|
||||
|
||||
56
build
56
build
@@ -3,7 +3,7 @@
|
||||
set -E
|
||||
|
||||
DIRS="syntax indent compiler autoload ftplugin ftdetect after/syntax after/indent after/ftplugin after/ftdetect"
|
||||
DIRS_BASIC="syntax indent ftdetect after/syntax after/indent after/ftdetect"
|
||||
DIRS_BASIC="syntax compiler indent ftdetect after/syntax after/indent after/ftdetect"
|
||||
DIRS_ALL="syntax indent compiler autoload ftplugin ftdetect after"
|
||||
|
||||
OUTPUT=""
|
||||
@@ -96,76 +96,92 @@ EOF
|
||||
}
|
||||
|
||||
PACKS="
|
||||
ansible:pearofducks/ansible-vim
|
||||
arduino:sudar/vim-arduino-syntax
|
||||
blade:xsbeats/vim-blade
|
||||
blade:jwalton512/vim-blade
|
||||
c++11:octol/vim-cpp-enhanced-highlight
|
||||
c/c++:vim-jp/cpp-vim
|
||||
c/c++:vim-jp/vim-cpp
|
||||
cjsx:mtscout6/vim-cjsx
|
||||
clojure:guns/vim-clojure-static
|
||||
coffee-script:kchmck/vim-coffee-script
|
||||
cjsx:mtscout6/vim-cjsx
|
||||
cryptol:victoredwardocallaghan/cryptol.vim
|
||||
crystal:rhysd/vim-crystal
|
||||
cql:elubow/cql-vim
|
||||
css:JulesWang/css.vim
|
||||
cucumber:tpope/vim-cucumber
|
||||
dart:dart-lang/dart-vim-plugin
|
||||
dockerfile:honza/dockerfile.vim
|
||||
elixir:elixir-lang/vim-elixir
|
||||
elm:lambdatoast/elm.vim
|
||||
emberscript:heartsentwined/vim-ember-script
|
||||
emblem:heartsentwined/vim-emblem
|
||||
erlang:hcs42/vim-erlang-runtime
|
||||
erlang:vim-erlang/vim-erlang-runtime
|
||||
fish:dag/vim-fish
|
||||
git:tpope/vim-git
|
||||
glsl:tikhomirov/vim-glsl
|
||||
go:fatih/vim-go:_BASIC
|
||||
groovy:vim-scripts/groovy.vim
|
||||
haml:tpope/vim-haml
|
||||
handlebars:mustache/vim-mustache-handlebars
|
||||
haskell:raichoo/haskell-vim
|
||||
haskell:neovimhaskell/haskell-vim
|
||||
haxe:yaymukund/vim-haxe
|
||||
html5:othree/html5.vim
|
||||
jade:digitaltoad/vim-jade
|
||||
jasmine:glanotte/vim-jasmine
|
||||
javascript:sheerun/yajs.vim
|
||||
julia:dcjones/julia-minimalist-vim
|
||||
javascript:pangloss/vim-javascript
|
||||
json:sheerun/vim-json
|
||||
jst:briancollins/vim-jst
|
||||
jsx:mxw/vim-jsx:_ALL
|
||||
julia:dcjones/julia-minimalist-vim
|
||||
kotlin:udalov/kotlin-vim
|
||||
latex:LaTeX-Box-Team/LaTeX-Box
|
||||
less:groenewege/vim-less
|
||||
liquid:tpope/vim-liquid
|
||||
mako:sophacles/vim-bundle-mako
|
||||
markdown:tpope/vim-markdown
|
||||
nginx:mutewinter/nginx.vim
|
||||
nginx:othree/nginx-contrib-vim
|
||||
nim:zah/nim.vim:_BASIC
|
||||
nix:spwhitt/vim-nix
|
||||
objc:b4winckler/vim-objc
|
||||
ocaml:jrk/vim-ocaml
|
||||
octave:vim-scripts/octave.vim--
|
||||
opencl:petRUShka/vim-opencl
|
||||
perl:vim-perl/vim-perl
|
||||
pgsql:exu/pgsql.vim
|
||||
php:StanAngeloff/php.vim
|
||||
puppet:rodjek/vim-puppet
|
||||
plantuml:aklt/plantuml-syntax
|
||||
powershell:Persistent13/vim-ps1
|
||||
protobuf:uarun/vim-protobuf
|
||||
pug:digitaltoad/vim-pug
|
||||
puppet:voxpupuli/vim-puppet
|
||||
purescript:raichoo/purescript-vim
|
||||
python:mitsuhiko/vim-python-combined
|
||||
qml:peterhoeg/vim-qml
|
||||
r-lang:vim-scripts/R.vim
|
||||
ragel:jneen/ragel.vim
|
||||
rspec:sheerun/rspec.vim
|
||||
ruby:vim-ruby/vim-ruby
|
||||
rust:wting/rust.vim
|
||||
rust:rust-lang/rust.vim
|
||||
sbt:derekwyatt/vim-sbt
|
||||
scala:derekwyatt/vim-scala
|
||||
slim:slim-template/vim-slim
|
||||
solidity:ethereum/vim-solidity
|
||||
stylus:wavded/vim-stylus
|
||||
swift:keith/swift.vim
|
||||
systemd:kurayama/systemd-vim-syntax
|
||||
swift:toyamarinyon/vim-swift
|
||||
textile:timcharper/textile.vim
|
||||
tmux:tejr/vim-tmux
|
||||
tomdoc:duwanis/tomdoc.vim
|
||||
typescript:leafgarland/typescript-vim
|
||||
vbnet:vim-scripts/vbnet.vim
|
||||
thrift:solarnz/thrift.vim
|
||||
tmux:tejr/vim-tmux
|
||||
tomdoc:wellbredgrapefruit/tomdoc.vim
|
||||
toml:cespare/vim-toml
|
||||
twig:beyondwords/vim-twig
|
||||
xls:vim-scripts/XSLT-syntax
|
||||
yard:sheerun/vim-yardoc
|
||||
twig:evidens/vim-twig
|
||||
typescript:leafgarland/typescript-vim
|
||||
vala:tkztmk/vim-vala
|
||||
vbnet:vim-scripts/vbnet.vim
|
||||
vcl:smerrill/vcl-vim-plugin
|
||||
vm:lepture/vim-velocity
|
||||
xls:vim-scripts/XSLT-syntax
|
||||
yaml:stephpy/vim-yaml
|
||||
yard:sheerun/vim-yardoc
|
||||
"
|
||||
|
||||
rm -rf tmp
|
||||
|
||||
24
compiler/cryptol.vim
Normal file
24
compiler/cryptol.vim
Normal file
@@ -0,0 +1,24 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
|
||||
|
||||
" Vim compiler file
|
||||
" Compiler: Cryptol version 1.8.19-academic Compiler
|
||||
" Maintainer: Edward O'Callaghan <victoredwardocallaghan AT gmail DOT com>
|
||||
" Latest Revision: 25-Apr-2013
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "cryptol"
|
||||
|
||||
if exists(":CompilerSet") != 2
|
||||
command = -nargs =* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
" TODO: Work out errorformat for the Cryptol compiler, see
|
||||
" :help errorformat
|
||||
CompilerSet errorformat& " use the default 'errorformat'
|
||||
|
||||
" "%<" means the current file name without extension.
|
||||
CompilerSet makeprg=cryptol\ -o\ %<\ %
|
||||
|
||||
endif
|
||||
@@ -1,10 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
" Vim compiler file
|
||||
" Language: ExUnit
|
||||
" Maintainer: Rein Henrichs <rein.henrichs@gmail.com>
|
||||
" URL: https://github.com/elixir-lang/vim-elixir
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
@@ -16,9 +11,15 @@ endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
CompilerSet makeprg=mix\ test
|
||||
CompilerSet errorformat=%A\ \ %.)\ %m(%.%#),%C\ \ \ \ \ **%m,%C\ \ \ \ \ \ \ %m,%Z\ \ \ \ \ at\ %f:%l,%-G%.%#
|
||||
CompilerSet errorformat=
|
||||
\%E\ \ %n)\ %m,
|
||||
\%+G\ \ \ \ \ **\ %m,
|
||||
\%+G\ \ \ \ \ stacktrace:,
|
||||
\%C\ \ \ \ \ %f:%l,
|
||||
\%+G\ \ \ \ \ \ \ (%\\w%\\+)\ %f:%l:\ %m,
|
||||
\%+G\ \ \ \ \ \ \ %f:%l:\ %.%#,
|
||||
\**\ (%\\w%\\+)\ %f:%l:\ %m
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
11
compiler/fish.vim
Normal file
11
compiler/fish.vim
Normal file
@@ -0,0 +1,11 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
if exists('current_compiler')
|
||||
finish
|
||||
endif
|
||||
let current_compiler = 'fish'
|
||||
|
||||
CompilerSet makeprg=fish\ --no-execute\ %
|
||||
execute 'CompilerSet errorformat='.escape(fish#errorformat(), ' ')
|
||||
|
||||
endif
|
||||
45
compiler/go.vim
Normal file
45
compiler/go.vim
Normal file
@@ -0,0 +1,45 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
|
||||
|
||||
" Copyright 2013 The Go Authors. All rights reserved.
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" compiler/go.vim: Vim compiler file for Go.
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "go"
|
||||
|
||||
if exists(":CompilerSet") != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo-=C
|
||||
if filereadable("makefile") || filereadable("Makefile")
|
||||
CompilerSet makeprg=make
|
||||
else
|
||||
CompilerSet makeprg=go\ build
|
||||
endif
|
||||
|
||||
" Define the patterns that will be recognized by QuickFix when parsing the
|
||||
" output of Go command that use this errorforamt (when called make, cexpr or
|
||||
" lmake, lexpr). This is the global errorformat, however some command might
|
||||
" use a different output, for those we define them directly and modify the
|
||||
" errorformat ourselves. More information at:
|
||||
" http://vimdoc.sourceforge.net/htmldoc/quickfix.html#errorformat
|
||||
CompilerSet errorformat =%-G#\ %.%# " Ignore lines beginning with '#' ('# command-line-arguments' line sometimes appears?)
|
||||
CompilerSet errorformat+=%-G%.%#panic:\ %m " Ignore lines containing 'panic: message'
|
||||
CompilerSet errorformat+=%Ecan\'t\ load\ package:\ %m " Start of multiline error string is 'can\'t load package'
|
||||
CompilerSet errorformat+=%A%f:%l:%c:\ %m " Start of multiline unspecified string is 'filename:linenumber:columnnumber:'
|
||||
CompilerSet errorformat+=%A%f:%l:\ %m " Start of multiline unspecified string is 'filename:linenumber:'
|
||||
CompilerSet errorformat+=%C%*\\s%m " Continuation of multiline error message is indented
|
||||
CompilerSet errorformat+=%-G%.%# " All lines not matching any of the above patterns are ignored
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
||||
endif
|
||||
27
compiler/nim.vim
Normal file
27
compiler/nim.vim
Normal file
@@ -0,0 +1,27 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
|
||||
let current_compiler = "nim"
|
||||
|
||||
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
CompilerSet makeprg=nim\ c\ $*
|
||||
|
||||
CompilerSet errorformat=
|
||||
\%-GHint:\ %m,
|
||||
\%E%f(%l\\,\ %c)\ Error:\ %m,
|
||||
\%W%f(%l\\,\ %c)\ Hint:\ %m
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
|
||||
endif
|
||||
@@ -24,9 +24,10 @@ CompilerSet errorformat=
|
||||
\%f:%l:\ %tarning:\ %m,
|
||||
\%E%.%#:in\ `load':\ %f:%l:%m,
|
||||
\%E%f:%l:in\ `%*[^']':\ %m,
|
||||
\%-Z\ \ \ \ \ \#\ %f:%l:%.%#,
|
||||
\%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#,
|
||||
\%E\ \ %\\d%\\+)%.%#,
|
||||
\%C\ \ \ \ \ %m,
|
||||
\%C%\\s%#,
|
||||
\%-G%.%#
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
@@ -17,7 +17,7 @@ if exists(":CompilerSet") != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
if exists("g:rustc_makeprg_no_percent") && g:rustc_makeprg_no_percent == 1
|
||||
if exists("g:rustc_makeprg_no_percent") && g:rustc_makeprg_no_percent != 0
|
||||
CompilerSet makeprg=rustc
|
||||
else
|
||||
CompilerSet makeprg=rustc\ \%
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
function! s:isAnsible()
|
||||
let filepath = expand("%:p")
|
||||
let filename = expand("%:t")
|
||||
if filepath =~ '\v/(tasks|roles|handlers)/.*\.ya?ml$' | return 1 | en
|
||||
if filepath =~ '\v/(group|host)_vars/' | return 1 | en
|
||||
if filename =~ '\v(playbook|site|main|local)\.ya?ml$' | return 1 | en
|
||||
let shebang = getline(1)
|
||||
if shebang =~# '^#!.*/bin/env\s\+ansible-playbook\>' | return 1 | en
|
||||
if shebang =~# '^#!.*/bin/ansible-playbook\>' | return 1 | en
|
||||
return 0
|
||||
endfunction
|
||||
:au BufNewFile,BufRead * if s:isAnsible() | set ft=ansible | en
|
||||
:au BufNewFile,BufRead *.j2 set ft=ansible_template
|
||||
:au BufNewFile,BufRead hosts set ft=ansible_hosts
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'arduino') == -1
|
||||
|
||||
au BufRead,BufNewFile *.ino,*.pde set filetype=arduino
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||
|
||||
au BufNewFile,BufRead *.blade.php set filetype=blade
|
||||
autocmd BufNewFile,BufRead *.blade.php set filetype=blade
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cjsx') == -1
|
||||
|
||||
@@ -30,29 +47,55 @@ function! s:DetectCoffee()
|
||||
endfunction
|
||||
autocmd BufNewFile,BufRead * call s:DetectCoffee()
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cql') == -1
|
||||
|
||||
if has("autocmd")
|
||||
au BufNewFile,BufRead *.cql set filetype=cql
|
||||
endif
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
|
||||
|
||||
au! BufRead,BufNewFile *.cry set filetype=cryptol
|
||||
au! BufRead,BufNewFile *.cyl set filetype=cryptol
|
||||
au! BufRead,BufNewFile *.lcry set filetype=cryptol
|
||||
au! BufRead,BufNewFile *.lcyl set filetype=cryptol
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.cr setlocal filetype=crystal
|
||||
autocmd BufNewFile,BufReadPost Projectfile setlocal filetype=crystal
|
||||
autocmd BufNewFile,BufReadPost *.ecr setlocal filetype=eruby
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cucumber') == -1
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.feature,*.story set filetype=cucumber
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dart') == -1
|
||||
|
||||
autocmd BufRead,BufNewFile *.dart set filetype=dart
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1
|
||||
|
||||
au BufNewFile,BufRead Dockerfile set filetype=dockerfile
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
au BufRead,BufNewFile *.eex set filetype=eelixir
|
||||
au FileType eelixir setl sw=2 sts=2 et iskeyword+=!,?
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
|
||||
au FileType elixir setl sw=2 sts=2 et iskeyword+=!,?
|
||||
function! s:DetectElixir()
|
||||
if getline(1) =~ '^#!.*\<elixir\>'
|
||||
set filetype=elixir
|
||||
endif
|
||||
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
|
||||
au BufRead,BufNewFile *.eex call s:setf('eelixir')
|
||||
au BufRead,BufNewFile * call s:DetectElixir()
|
||||
au FileType elixir,eelixir setl sw=2 sts=2 et iskeyword+=!,?
|
||||
function! s:setf(filetype) abort
|
||||
let &filetype = a:filetype
|
||||
endfunction
|
||||
autocmd BufNewFile,BufRead * call s:DetectElixir()
|
||||
function! s:DetectElixir()
|
||||
if getline(1) =~ '^#!.*\<elixir\>'
|
||||
call s:setf('elixir')
|
||||
endif
|
||||
endfunction
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
au BufNewFile,BufRead *.elm set filetype=elm
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emberscript') == -1
|
||||
|
||||
@@ -64,6 +107,26 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emblem') == -1
|
||||
autocmd BufNewFile,BufRead *.emblem set filetype=emblem
|
||||
autocmd FileType emblem set tabstop=2|set shiftwidth=2|set expandtab
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'erlang') == -1
|
||||
|
||||
au BufNewFile,BufRead *.erl,*.hrl,rebar.config,*.app,*.app.src,*.yaws,*.xrl set ft=erlang
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
autocmd BufRead,BufNewFile *.fish setfiletype fish
|
||||
autocmd BufRead *
|
||||
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
|
||||
\ setlocal filetype=fish |
|
||||
\ endif
|
||||
autocmd BufRead fish_funced_*_*.fish call search('^$')
|
||||
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
|
||||
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
|
||||
autocmd BufNewFile ~/.config/fish/functions/*.fish
|
||||
\ call append(0, ['function '.expand('%:t:r'),
|
||||
\'',
|
||||
\'end']) |
|
||||
\ 2
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit
|
||||
@@ -93,19 +156,22 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
|
||||
|
||||
let s:current_fileformats = ''
|
||||
let s:current_fileencodings = ''
|
||||
function! s:gofiletype_pre()
|
||||
function! s:gofiletype_pre(type)
|
||||
let s:current_fileformats = &g:fileformats
|
||||
let s:current_fileencodings = &g:fileencodings
|
||||
set fileencodings=utf-8 fileformats=unix
|
||||
setlocal filetype=go
|
||||
let &l:filetype = a:type
|
||||
endfunction
|
||||
function! s:gofiletype_post()
|
||||
let &g:fileformats = s:current_fileformats
|
||||
let &g:fileencodings = s:current_fileencodings
|
||||
endfunction
|
||||
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
|
||||
au BufRead *.go call s:gofiletype_pre()
|
||||
au BufRead *.go call s:gofiletype_pre("go")
|
||||
au BufReadPost *.go call s:gofiletype_post()
|
||||
au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix
|
||||
au BufRead *.s call s:gofiletype_pre("asm")
|
||||
au BufReadPost *.s call s:gofiletype_post()
|
||||
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haml') == -1
|
||||
@@ -114,18 +180,54 @@ autocmd BufNewFile,BufRead *.haml,*.hamlbars,*.hamlc setf haml
|
||||
autocmd BufNewFile,BufRead *.sass setf sass
|
||||
autocmd BufNewFile,BufRead *.scss setf scss
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
au BufRead,BufNewFile *.hsc set filetype=haskell
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haxe') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.hx setf haxe
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jade') == -1
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.jade set filetype=jade
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jasmine') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *Spec.js,*_spec.js set filetype=jasmine.javascript syntax=jasmine
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
|
||||
|
||||
au BufNewFile,BufRead *.js setf javascript
|
||||
au BufNewFile,BufRead *.jsm setf javascript
|
||||
au BufNewFile,BufRead Jakefile setf javascript
|
||||
fun! s:SelectJavascript()
|
||||
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
|
||||
set ft=javascript
|
||||
endif
|
||||
endfun
|
||||
au BufNewFile,BufRead * call s:SelectJavascript()
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
|
||||
if !exists('g:jsx_ext_required')
|
||||
let g:jsx_ext_required = 1
|
||||
endif
|
||||
if !exists('g:jsx_pragma_required')
|
||||
let g:jsx_pragma_required = 0
|
||||
endif
|
||||
if g:jsx_pragma_required
|
||||
" Look for the @jsx pragma. It must be included in a docblock comment before
|
||||
" anything else in the file (except whitespace).
|
||||
let s:jsx_pragma_pattern = '\%^\_s*\/\*\*\%(\_.\%(\*\/\)\@!\)*@jsx\_.\{-}\*\/'
|
||||
let b:jsx_pragma_found = search(s:jsx_pragma_pattern, 'npw')
|
||||
endif
|
||||
fu! <SID>EnableJSX()
|
||||
if g:jsx_pragma_required && !b:jsx_pragma_found | return 0 | endif
|
||||
if g:jsx_ext_required && !exists('b:jsx_ext_found') | return 0 | endif
|
||||
return 1
|
||||
endfu
|
||||
autocmd BufNewFile,BufRead *.jsx let b:jsx_ext_found = 1
|
||||
autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx
|
||||
autocmd BufNewFile,BufRead *.js
|
||||
\ if <SID>EnableJSX() | set filetype=javascript.jsx | endif
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.json set filetype=json
|
||||
@@ -168,6 +270,10 @@ au BufNewFile,BufRead */templates/**.liquid,*/layout/**.liquid,*/snippets/**.liq
|
||||
\ let b:liquid_subtype = 'html' |
|
||||
\ set ft=liquid |
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mako') == -1
|
||||
|
||||
au BufRead,BufNewFile *.mako set filetype=mako
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'markdown') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.markdown,*.md,*.mdown,*.mkd,*.mkdn
|
||||
@@ -193,11 +299,22 @@ endif
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nginx') == -1
|
||||
|
||||
au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/*,*/nginx/vhosts.d/*,nginx.conf if &ft == '' | setfiletype nginx | endif
|
||||
au BufRead,BufNewFile *.nginx set ft=nginx
|
||||
au BufRead,BufNewFile */etc/nginx/* set ft=nginx
|
||||
au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx
|
||||
au BufRead,BufNewFile nginx.conf set ft=nginx
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
|
||||
|
||||
au BufNewFile,BufRead *.nim set filetype=nim
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.nix setfiletype nix
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'opencl') == -1
|
||||
|
||||
au BufRead,BufNewFile *.cl set filetype=opencl
|
||||
au! BufRead,BufNewFile *.cl set filetype=opencl
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'perl') == -1
|
||||
|
||||
@@ -230,6 +347,18 @@ endfunction
|
||||
autocmd BufReadPost *.pl,*.pm,*.t call s:DetectPerl6()
|
||||
autocmd BufNew,BufNewFile,BufRead *.nqp setf perl6
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'pgsql') == -1
|
||||
|
||||
au BufNewFile,BufRead *.pgsql setf pgsql
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'plantuml') == -1
|
||||
|
||||
if did_filetype()
|
||||
finish
|
||||
endif
|
||||
autocmd BufRead,BufNewFile * :if getline(1) =~ '^.*startuml.*$'| setfiletype plantuml | endif
|
||||
autocmd BufRead,BufNewFile *.pu,*.uml,*.plantuml set filetype=plantuml
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'protobuf') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.proto setfiletype proto
|
||||
@@ -244,11 +373,21 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'powershell') ==
|
||||
|
||||
au BufNewFile,BufRead *.ps1xml set ft=ps1xml
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'pug') == -1
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.pug set filetype=pug
|
||||
autocmd BufNewFile,BufReadPost *.jade set filetype=pug
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'puppet') == -1
|
||||
|
||||
au! BufRead,BufNewFile *.pp setfiletype puppet
|
||||
au! BufRead,BufNewFile Puppetfile setfiletype ruby
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1
|
||||
|
||||
au BufNewFile,BufRead *.purs setf purescript
|
||||
au FileType purescript let &l:commentstring='{--%s--}'
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'qml') == -1
|
||||
|
||||
autocmd BufRead,BufNewFile *.qml setfiletype qml
|
||||
@@ -320,6 +459,16 @@ endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'swift') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.swift set filetype=swift
|
||||
autocmd BufRead * call s:Swift()
|
||||
function! s:Swift()
|
||||
if !empty(&filetype)
|
||||
return
|
||||
endif
|
||||
let line = getline(1)
|
||||
if line =~ "^#!.*swift"
|
||||
setfiletype swift
|
||||
endif
|
||||
endfunction
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'systemd') == -1
|
||||
|
||||
@@ -350,11 +499,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'toml') == -1
|
||||
autocmd BufNewFile,BufRead *.toml set filetype=toml
|
||||
autocmd BufNewFile,BufRead Cargo.lock set filetype=toml
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.twig set filetype=twig
|
||||
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'typescript') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.ts,*.tsx setlocal filetype=typescript
|
||||
@@ -364,6 +508,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vala') == -1
|
||||
autocmd BufRead *.vala,*.vapi set efm=%f:%l.%c-%[%^:]%#:\ %t%[%^:]%#:\ %m
|
||||
au BufRead,BufNewFile *.vala,*.vapi setfiletype vala
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vcl') == -1
|
||||
|
||||
au BufRead,BufNewFile *.vcl set filetype=vcl
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vm') == -1
|
||||
|
||||
au BufRead,BufNewFile *.vm set ft=velocity syntax=velocity
|
||||
|
||||
8
ftplugin/ansible.vim
Normal file
8
ftplugin/ansible.vim
Normal file
@@ -0,0 +1,8 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
" Slow yaml highlighting workaround
|
||||
if exists('+regexpengine') && ('®expengine' == 0)
|
||||
setlocal regexpengine=1
|
||||
endif
|
||||
|
||||
endif
|
||||
13
ftplugin/ansible_hosts.vim
Normal file
13
ftplugin/ansible_hosts.vim
Normal file
@@ -0,0 +1,13 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
else
|
||||
let b:did_ftplugin = 1
|
||||
endif
|
||||
|
||||
setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions-=c
|
||||
|
||||
let b:undo_ftplugin = "setl comments< commentstring< formatoptions<"
|
||||
|
||||
endif
|
||||
16
ftplugin/blade.vim
Normal file
16
ftplugin/blade.vim
Normal file
@@ -0,0 +1,16 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||
|
||||
" Vim filetype plugin
|
||||
" Language: Blade (Laravel)
|
||||
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! ftplugin/html.vim
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal iskeyword+=@-@
|
||||
|
||||
endif
|
||||
9
ftplugin/cabal.vim
Normal file
9
ftplugin/cabal.vim
Normal file
@@ -0,0 +1,9 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
if exists("g:loaded_haskellvim_cabal")
|
||||
finish
|
||||
endif
|
||||
|
||||
let g:loaded_haskellvim_cabal = 1
|
||||
|
||||
endif
|
||||
50
ftplugin/cryptol/folding.vim
Normal file
50
ftplugin/cryptol/folding.vim
Normal file
@@ -0,0 +1,50 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cryptol') == -1
|
||||
|
||||
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
|
||||
|
||||
"setlocal foldmethod=indent
|
||||
"setlocal foldignore=
|
||||
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=GetPotionFold(v:lnum)
|
||||
|
||||
" Helper function: To tackle non-blank lines,
|
||||
" wish to know their indentation level
|
||||
function! IndentLevel(lnum)
|
||||
return indent(a:lnum) / &shiftwidth
|
||||
endfunction
|
||||
|
||||
" Helper function: .
|
||||
function! NextNonBlankLine(lnum)
|
||||
let numlines = line('$')
|
||||
let current = a:lnum + 1
|
||||
|
||||
while current <= numlines
|
||||
if getline(current) =~? '\v\S'
|
||||
return current
|
||||
endif
|
||||
|
||||
let current += 1
|
||||
endwhile
|
||||
|
||||
return -2
|
||||
endfunction
|
||||
|
||||
function! GetPotionFold(lnum)
|
||||
if getline(a:lnum) =~? '\v^\s*$'
|
||||
return '-1'
|
||||
endif
|
||||
|
||||
let this_indent = IndentLevel(a:lnum)
|
||||
let next_indent = IndentLevel(NextNonBlankLine(a:lnum))
|
||||
|
||||
if next_indent == this_indent
|
||||
return this_indent
|
||||
elseif next_indent < this_indent
|
||||
return this_indent
|
||||
elseif next_indent > this_indent
|
||||
return '>' . next_indent
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endif
|
||||
60
ftplugin/crystal.vim
Normal file
60
ftplugin/crystal.vim
Normal file
@@ -0,0 +1,60 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists('loaded_matchit') && !exists('b:match_words')
|
||||
let b:match_ignorecase = 0
|
||||
|
||||
let b:match_words =
|
||||
\ '\<\%(if\|unless\|case\|while\|until\|for\|do\|class\|module\|struct\|lib\|macro\|ifdef\|def\|fun\|begin\)\>=\@!' .
|
||||
\ ':' .
|
||||
\ '\<\%(else\|elsif\|ensure\|when\|rescue\|break\|redo\|next\|retry\)\>' .
|
||||
\ ':' .
|
||||
\ '\<end\>' .
|
||||
\ ',{:},\[:\],(:)'
|
||||
|
||||
let b:match_skip =
|
||||
\ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
|
||||
\ "\\<crystal\\%(String\\|StringDelimiter\\|ASCIICode\\|Escape\\|" .
|
||||
\ "Interpolation\\|NoInterpolation\\|Comment\\|Documentation\\|" .
|
||||
\ "ConditionalModifier\\|RepeatModifier\\|OptionalDo\\|" .
|
||||
\ "Function\\|BlockArgument\\|KeywordAsMethod\\|ClassVariable\\|" .
|
||||
\ "InstanceVariable\\|GlobalVariable\\|Symbol\\)\\>'"
|
||||
endif
|
||||
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#\ %s
|
||||
setlocal suffixesadd=.cr
|
||||
|
||||
" Set format for quickfix window
|
||||
setlocal errorformat=
|
||||
\%ESyntax\ error\ in\ line\ %l:\ %m,
|
||||
\%ESyntax\ error\ in\ %f:%l:\ %m,
|
||||
\%EError\ in\ %f:%l:\ %m,
|
||||
\%C%p^,
|
||||
\%-C%.%#
|
||||
|
||||
if get(g:, 'crystal_define_mappings', 1)
|
||||
nmap <buffer>gd <Plug>(crystal-jump-to-definition)
|
||||
nmap <buffer>gc <Plug>(crystal-show-context)
|
||||
nmap <buffer>gss <Plug>(crystal-spec-switch)
|
||||
nmap <buffer>gsa <Plug>(crystal-spec-run-all)
|
||||
nmap <buffer>gsc <Plug>(crystal-spec-run-current)
|
||||
endif
|
||||
|
||||
if &l:ofu ==# ''
|
||||
setlocal omnifunc=crystal_lang#complete
|
||||
endif
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim: nowrap sw=2 sts=2 ts=8:
|
||||
|
||||
endif
|
||||
31
ftplugin/dart.vim
Normal file
31
ftplugin/dart.vim
Normal file
@@ -0,0 +1,31 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dart') == -1
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Enable automatic indentation (2 spaces) if variable g:dart_style_guide is set
|
||||
if exists('g:dart_style_guide')
|
||||
setlocal expandtab
|
||||
setlocal shiftwidth=2
|
||||
setlocal softtabstop=2
|
||||
|
||||
setlocal formatoptions-=t
|
||||
endif
|
||||
|
||||
" Set 'comments' to format dashed lists in comments.
|
||||
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
|
||||
|
||||
setlocal commentstring=//%s
|
||||
let s:win_sep = (has('win32') || has('win64')) ? '/' : ''
|
||||
let &l:errorformat =
|
||||
\ join([
|
||||
\ ' %#''file://' . s:win_sep . '%f'': %s: line %l pos %c:%m',
|
||||
\ '%m'
|
||||
\ ], ',')
|
||||
|
||||
|
||||
let b:undo_ftplugin = 'setl et< fo< sw< sts< com< cms<'
|
||||
|
||||
endif
|
||||
@@ -1,9 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
" Vim filetype plugin
|
||||
" Language: Embedded Elixir
|
||||
" URL: https://github.com/elixir-lang/vim-elixir
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
" Vim filetype plugin
|
||||
" Language: Elixir
|
||||
" Maintainer: Carlos Galdino <carloshsgaldino@gmail.com>
|
||||
" URL: https://github.com/elixir-lang/vim-elixir
|
||||
|
||||
if (exists("b:did_ftplugin"))
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
|
||||
" Matchit support
|
||||
if exists("loaded_matchit") && !exists("b:match_words")
|
||||
let b:match_ignorecase = 0
|
||||
|
||||
let b:match_words = '\<\%(do\|fn\)\:\@!\>' .
|
||||
let b:match_words = '\:\@<!\<\%(do\|fn\)\:\@!\>' .
|
||||
\ ':' .
|
||||
\ '\<\%(else\|elsif\|catch\|after\|rescue\)\:\@!\>' .
|
||||
\ ':' .
|
||||
@@ -26,4 +20,42 @@ endif
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
function! GetElixirFilename(word)
|
||||
let word = a:word
|
||||
|
||||
" get first thing that starts uppercase, until the first space or end of line
|
||||
let word = substitute(word,'^\s*\(\u[^ ]\+\).*$','\1','g')
|
||||
|
||||
" remove any trailing characters that don't look like a nested module
|
||||
let word = substitute(word,'\.\U.*$','','g')
|
||||
|
||||
" replace module dots with slash
|
||||
let word = substitute(word,'\.','/','g')
|
||||
|
||||
" remove any special chars
|
||||
let word = substitute(word,'[^A-z0-9-_/]','','g')
|
||||
|
||||
" convert to snake_case
|
||||
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
||||
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
||||
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
|
||||
let word = substitute(word,'-','_','g')
|
||||
let word = tolower(word)
|
||||
|
||||
return word
|
||||
endfunction
|
||||
|
||||
let &l:path =
|
||||
\ join([
|
||||
\ getcwd().'/lib',
|
||||
\ getcwd().'/src',
|
||||
\ getcwd().'/deps/**/lib',
|
||||
\ getcwd().'/deps/**/src',
|
||||
\ &g:path
|
||||
\ ], ',')
|
||||
setlocal includeexpr=GetElixirFilename(v:fname)
|
||||
setlocal suffixesadd=.ex,.exs,.eex,.erl,.yrl,.hrl
|
||||
|
||||
setlocal formatoptions-=t formatoptions+=croqlj
|
||||
|
||||
endif
|
||||
|
||||
86
ftplugin/elm.vim
Normal file
86
ftplugin/elm.vim
Normal file
@@ -0,0 +1,86 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" elm.vim - Plugin for the Elm programming language
|
||||
" Maintainer: Alexander Noriega <http://lambdatoast.com/>
|
||||
" Version: 0.4.3
|
||||
|
||||
" Plugin setup stuff
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Compilation
|
||||
|
||||
function! ElmMake(file)
|
||||
let args = a:file
|
||||
return elm#io#system("elm-make", args)
|
||||
endfunction
|
||||
|
||||
function! ElmMakeCurrentFile()
|
||||
echo ElmMake(expand("%"))
|
||||
endfunction
|
||||
|
||||
function! ElmMakeMain()
|
||||
echo ElmMake("Main.elm")
|
||||
endfunction
|
||||
|
||||
function! ElmMakeFile(file)
|
||||
echo ElmMake(a:file)
|
||||
endfunction
|
||||
|
||||
" REPL
|
||||
|
||||
function! ElmRepl()
|
||||
!elm-repl
|
||||
endfunction
|
||||
|
||||
" Evaluation
|
||||
|
||||
function! ElmEvalLine()
|
||||
return ElmEval(getline("."))
|
||||
endfunction
|
||||
|
||||
function! ElmEvalSelection()
|
||||
let savedReg = @z
|
||||
normal! `<v`>"zy
|
||||
let res = ElmEval(substitute(getreg("z"), "\n", "\\\n", "g"))
|
||||
let @z = savedReg
|
||||
normal! gv
|
||||
endfunction
|
||||
|
||||
function! ElmEval(sourceCode)
|
||||
let currentLine = a:sourceCode
|
||||
let args = "echo '" . currentLine . "' | elm-repl"
|
||||
let result = elm#io#system("echo", args)
|
||||
let cleanResult = "-- " . join(s:Filtered(function("s:IsUsefulReplOutput"), split(result, "\n")), "")
|
||||
put =cleanResult
|
||||
endfunction
|
||||
|
||||
function! s:IsUsefulReplOutput(str)
|
||||
return a:str !~ "^Elm REPL" && a:str !~ "Type :help" && a:str !~ ">\\s*$"
|
||||
endfunction
|
||||
|
||||
" List processing
|
||||
|
||||
function! s:Filtered(fn, l)
|
||||
let new_list = deepcopy(a:l)
|
||||
call filter(new_list, string(a:fn) . '(v:val)')
|
||||
return new_list
|
||||
endfunction
|
||||
|
||||
command -buffer ElmEvalLine call ElmEvalLine()
|
||||
command -buffer ElmEvalSelection call ElmEvalSelection()
|
||||
command -buffer ElmMakeMain call ElmMakeMain()
|
||||
command -buffer -nargs=1 ElmMakeFile call ElmMakeFile <args>
|
||||
command -buffer ElmMakeCurrentFile call ElmMakeCurrentFile()
|
||||
command -buffer ElmRepl call ElmRepl()
|
||||
|
||||
" Define comment convention
|
||||
|
||||
setlocal comments=:--
|
||||
setlocal commentstring=--%s
|
||||
|
||||
endif
|
||||
43
ftplugin/fish.vim
Normal file
43
ftplugin/fish.vim
Normal file
@@ -0,0 +1,43 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#%s
|
||||
setlocal define=\\v^\\s*function>
|
||||
setlocal foldexpr=fish#Fold()
|
||||
setlocal formatoptions+=ron1
|
||||
setlocal formatoptions-=t
|
||||
setlocal include=\\v^\\s*\\.>
|
||||
setlocal iskeyword=@,48-57,-,_,.,/
|
||||
setlocal suffixesadd^=.fish
|
||||
|
||||
" Use the 'j' format option when available.
|
||||
if v:version ># 703 || v:version ==# 703 && has('patch541')
|
||||
setlocal formatoptions+=j
|
||||
endif
|
||||
|
||||
if executable('fish_indent')
|
||||
setlocal formatexpr=fish#Format()
|
||||
endif
|
||||
|
||||
if executable('fish')
|
||||
setlocal omnifunc=fish#Complete
|
||||
for s:path in split(system("fish -c 'echo $fish_function_path'"))
|
||||
execute 'setlocal path+='.s:path
|
||||
endfor
|
||||
else
|
||||
setlocal omnifunc=syntaxcomplete#Complete
|
||||
endif
|
||||
|
||||
" Use the 'man' wrapper function in fish to include fish's man pages.
|
||||
" Have to use a script for this; 'fish -c man' would make the the man page an
|
||||
" argument to fish instead of man.
|
||||
execute 'setlocal keywordprg=fish\ '.expand('<sfile>:p:h:h').'/bin/man.fish'
|
||||
|
||||
let b:match_words =
|
||||
\ escape('<%(begin|function|if|switch|while|for)>:<end>', '<>%|)')
|
||||
|
||||
let b:endwise_addition = 'end'
|
||||
let b:endwise_words = 'begin,function,if,switch,while,for'
|
||||
let b:endwise_syngroups = 'fishKeyword,fishConditional,fishRepeat'
|
||||
|
||||
endif
|
||||
@@ -3,6 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
|
||||
" Vim filetype plugin
|
||||
" Language: generic git output
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" Last Change: 2013 May 30
|
||||
|
||||
" Only do this when not done yet for this buffer
|
||||
if (exists("b:did_ftplugin"))
|
||||
@@ -13,6 +14,8 @@ let b:did_ftplugin = 1
|
||||
if !exists('b:git_dir')
|
||||
if expand('%:p') =~# '[\/]\.git[\/]modules[\/]'
|
||||
" Stay out of the way
|
||||
elseif expand('%:p') =~# '[\/]\.git[\/]worktrees'
|
||||
let b:git_dir = matchstr(expand('%:p'),'.*\.git[\/]worktrees[\/][^\/]\+\>')
|
||||
elseif expand('%:p') =~# '\.git\>'
|
||||
let b:git_dir = matchstr(expand('%:p'),'.*\.git\>')
|
||||
elseif $GIT_DIR != ''
|
||||
|
||||
@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
|
||||
" Vim filetype plugin
|
||||
" Language: git commit file
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" Last Change: 2012 April 7
|
||||
" Last Change: 2013 May 30
|
||||
|
||||
" Only do this when not done yet for this buffer
|
||||
if (exists("b:did_ftplugin"))
|
||||
@@ -13,8 +13,10 @@ endif
|
||||
runtime! ftplugin/git.vim
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal nomodeline tabstop=8 formatoptions-=croq formatoptions+=tl textwidth=72
|
||||
let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw<'
|
||||
setlocal comments=:# commentstring=#\ %s
|
||||
setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72
|
||||
setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=q
|
||||
let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw< com< cms<'
|
||||
|
||||
if exists("g:no_gitcommit_commands") || v:version < 700
|
||||
finish
|
||||
@@ -26,6 +28,8 @@ endif
|
||||
|
||||
command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
|
||||
|
||||
let b:undo_ftplugin = b:undo_ftplugin . "|delc DiffGitCached"
|
||||
|
||||
function! s:diffcomplete(A,L,P)
|
||||
let args = ""
|
||||
if a:P <= match(a:L." -- "," -- ")+3
|
||||
|
||||
@@ -14,10 +14,11 @@ runtime! ftplugin/git.vim
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal comments=:# commentstring=#\ %s formatoptions-=t
|
||||
setlocal nomodeline
|
||||
if !exists("b:undo_ftplugin")
|
||||
let b:undo_ftplugin = ""
|
||||
endif
|
||||
let b:undo_ftplugin = b:undo_ftplugin."|setl com< cms< fo<"
|
||||
let b:undo_ftplugin = b:undo_ftplugin."|setl com< cms< fo< ml<"
|
||||
|
||||
function! s:choose(word)
|
||||
s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e
|
||||
|
||||
20
ftplugin/haskell.vim
Normal file
20
ftplugin/haskell.vim
Normal file
@@ -0,0 +1,20 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
if exists("g:loaded_haskellvim_haskell")
|
||||
finish
|
||||
endif
|
||||
|
||||
let g:loaded_haskellvim_haskell = 1
|
||||
|
||||
function! haskell#sortImports(line1, line2)
|
||||
exe a:line1 . "," . a:line2 . "sort /import\\s\\+\\(qualified\\s\\+\\)\\?/"
|
||||
endfunction
|
||||
|
||||
function! haskell#formatImport(line1, line2)
|
||||
exec a:line1 . ",". a:line2 . "s/import\\s\\+\\([A-Z].*\\)/import \\1"
|
||||
endfunction
|
||||
|
||||
command! -buffer -range HaskellSortImports call haskell#sortImports(<line1>, <line2>)
|
||||
command! -buffer -range HaskellFormatImport call haskell#formatImport(<line1>, <line2>)
|
||||
|
||||
endif
|
||||
@@ -8,4 +8,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
||||
|
||||
" setlocal iskeyword+=-
|
||||
|
||||
setlocal commentstring=<!--%s-->
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
|
||||
|
||||
setlocal suffixesadd+=.js
|
||||
|
||||
endif
|
||||
15
ftplugin/mako.vim
Normal file
15
ftplugin/mako.vim
Normal file
@@ -0,0 +1,15 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mako') == -1
|
||||
|
||||
" Vim filetype plugin file
|
||||
" Language: Mako
|
||||
" Maintainer: Randy Stauner <randy@magnificent-tears.com>
|
||||
" Last Change: 2014-02-07
|
||||
" Version: 0.1
|
||||
|
||||
if exists("b:did_ftplugin") | finish | endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal comments=:##
|
||||
setlocal commentstring=##%s
|
||||
|
||||
endif
|
||||
@@ -11,7 +11,7 @@ endif
|
||||
|
||||
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
||||
|
||||
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
|
||||
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=<!--%s-->
|
||||
setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
|
||||
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:
|
||||
|
||||
|
||||
17
ftplugin/nix.vim
Normal file
17
ftplugin/nix.vim
Normal file
@@ -0,0 +1,17 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin=1
|
||||
|
||||
setlocal comments=
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
" Nixpkgs indent settings
|
||||
setlocal tabstop=2
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
setlocal expandtab
|
||||
|
||||
endif
|
||||
10
ftplugin/objc.vim
Normal file
10
ftplugin/objc.vim
Normal file
@@ -0,0 +1,10 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" Use C++ style comment strings with commentary.vim
|
||||
setl commentstring=//%s
|
||||
|
||||
" Search for include files inside frameworks (used for gf etc.)
|
||||
setl includeexpr=substitute(v:fname,'\\([^/]\\+\\)/\\(.\\+\\)','/System/Library/Frameworks/\\1.framework/Headers/\\2','')
|
||||
|
||||
|
||||
endif
|
||||
22
ftplugin/plantuml.vim
Normal file
22
ftplugin/plantuml.vim
Normal file
@@ -0,0 +1,22 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'plantuml') == -1
|
||||
|
||||
" Vim plugin file
|
||||
" Language: PlantUML
|
||||
" Maintainer: Aaron C. Meadows < language name at shadowguarddev dot com>
|
||||
" Last Change: 19-Jun-2012
|
||||
" Version: 0.1
|
||||
|
||||
if exists("g:loaded_plantuml_plugin")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_plantuml_plugin = 1
|
||||
|
||||
if !exists("g:plantuml_executable_script")
|
||||
let g:plantuml_executable_script="plantuml"
|
||||
endif
|
||||
|
||||
autocmd Filetype plantuml let &l:makeprg=g:plantuml_executable_script . " " . fnameescape(expand("%"))
|
||||
|
||||
setlocal comments=s1:/',mb:',ex:'/,:' commentstring=/'%s'/ formatoptions-=t formatoptions+=croql
|
||||
|
||||
endif
|
||||
@@ -1,7 +1,7 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jade') == -1
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'pug') == -1
|
||||
|
||||
" Vim filetype plugin
|
||||
" Language: Jade
|
||||
" Language: Pug
|
||||
" Maintainer: Joshua Borton
|
||||
" Credits: Tim Pope
|
||||
|
||||
@@ -39,7 +39,7 @@ endif
|
||||
|
||||
" Change the browse dialog on Win32 to show mainly Haml-related files
|
||||
if has("gui_win32")
|
||||
let b:browsefilter="Jade Files (*.jade)\t*.jade\n" . s:browsefilter
|
||||
let b:browsefilter="Pug Files (*.pug)\t*.pug\n" . s:browsefilter
|
||||
endif
|
||||
|
||||
" Load the combined list of match_words for matchit.vim
|
||||
@@ -49,7 +49,7 @@ endif
|
||||
|
||||
setlocal comments=://-,:// commentstring=//\ %s
|
||||
|
||||
setlocal suffixesadd+=.jade
|
||||
setlocal suffixesadd+=.pug
|
||||
|
||||
let b:undo_ftplugin = "setl cms< com< "
|
||||
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
||||
@@ -6,5 +6,6 @@ setl sw=2
|
||||
setl et
|
||||
setl keywordprg=puppet\ describe\ --providers
|
||||
setl iskeyword=-,:,@,48-57,_,192-255
|
||||
setl cms=#\ %s
|
||||
|
||||
endif
|
||||
|
||||
@@ -46,7 +46,7 @@ endif
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
setlocal include=^\\s*\\<\\(load\\>\\\|require\\>\\\|autoload\\s*:\\=[\"']\\=\\h\\w*[\"']\\=,\\)
|
||||
setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
|
||||
setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'\%(\.rb\)\=$','.rb','')
|
||||
setlocal suffixesadd=.rb
|
||||
|
||||
if exists("&ofu") && has("ruby")
|
||||
@@ -138,7 +138,7 @@ if exists('s:ruby_paths') && stridx(&l:tags, join(map(copy(s:ruby_paths),'v:val.
|
||||
let &l:tags = &tags . ',' . join(map(copy(s:ruby_paths),'v:val."/tags"'),',')
|
||||
endif
|
||||
|
||||
if has("gui_win32") && !exists("b:browsefilter")
|
||||
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
|
||||
let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" .
|
||||
\ "All Files (*.*)\t*.*\n"
|
||||
endif
|
||||
@@ -361,7 +361,7 @@ function! RubyCursorFile() abort
|
||||
endtry
|
||||
let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
|
||||
let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
|
||||
let ext = getline('.') =~# '^\s*\%(require\|autoload\)\>' ? '.rb' : ''
|
||||
let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : ''
|
||||
if s:synname() ==# 'rubyConstant'
|
||||
let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
|
||||
let cfile = substitute(cfile,'::','/','g')
|
||||
@@ -369,7 +369,7 @@ function! RubyCursorFile() abort
|
||||
let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
|
||||
return tolower(cfile) . '.rb'
|
||||
elseif getline('.') =~# '^\s*require_relative\s*\(["'']\).*\1\s*$'
|
||||
let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . '.rb'
|
||||
let cfile = expand('%:p:h') . '/' . matchstr(getline('.'),'\(["'']\)\zs.\{-\}\ze\1') . ext
|
||||
elseif getline('.') =~# '^\s*\%(require[( ]\|load[( ]\|autoload[( ]:\w\+,\)\s*\%(::\)\=File\.expand_path(\(["'']\)\.\./.*\1,\s*__FILE__)\s*$'
|
||||
let target = matchstr(getline('.'),'\(["'']\)\.\.\zs/.\{-\}\ze\1')
|
||||
let cfile = expand('%:p:h') . target . ext
|
||||
|
||||
@@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
" Description: Vim syntax file for Rust
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Maintainer: Kevin Ballard <kevin@sb.org>
|
||||
" Last Change: Jul 07, 2014
|
||||
" Last Change: January 29, 2015
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
@@ -20,7 +20,7 @@ set cpo&vim
|
||||
" comments, so we'll use that as our default, but make it easy to switch.
|
||||
" This does not affect indentation at all (I tested it with and without
|
||||
" leader), merely whether a leader is inserted by default or not.
|
||||
if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader == 1
|
||||
if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader != 0
|
||||
" Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why,
|
||||
" but without it, */ gets indented one space even if there were no
|
||||
" leaders. I'm fairly sure that's a Vim bug.
|
||||
@@ -37,7 +37,7 @@ silent! setlocal formatoptions+=j
|
||||
" otherwise it's better than nothing.
|
||||
setlocal smartindent nocindent
|
||||
|
||||
if !exists("g:rust_recommended_style") || g:rust_recommended_style == 1
|
||||
if !exists("g:rust_recommended_style") || g:rust_recommended_style != 0
|
||||
setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
|
||||
setlocal textwidth=99
|
||||
endif
|
||||
@@ -69,7 +69,7 @@ if has("folding") && exists('g:rust_fold') && g:rust_fold != 0
|
||||
endif
|
||||
endif
|
||||
|
||||
if has('conceal') && exists('g:rust_conceal')
|
||||
if has('conceal') && exists('g:rust_conceal') && g:rust_conceal != 0
|
||||
let b:rust_set_conceallevel=1
|
||||
setlocal conceallevel=2
|
||||
endif
|
||||
@@ -84,19 +84,35 @@ xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>
|
||||
onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>
|
||||
onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>
|
||||
|
||||
" %-matching. <:> is handy for generics.
|
||||
set matchpairs+=<:>
|
||||
" There are two minor issues with it; (a) comparison operators in expressions,
|
||||
" where a less-than may match a greater-than later on—this is deemed a trivial
|
||||
" issue—and (b) `Fn() -> X` syntax. This latter issue is irremediable from the
|
||||
" highlighting perspective (built into Vim), but the actual % functionality
|
||||
" can be fixed by this use of matchit.vim.
|
||||
let b:match_skip = 's:comment\|string\|rustArrow'
|
||||
source $VIMRUNTIME/macros/matchit.vim
|
||||
|
||||
" Commands {{{1
|
||||
|
||||
" See |:RustRun| for docs
|
||||
command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
|
||||
command! -nargs=* -complete=file -bang -buffer RustRun call rust#Run(<bang>0, <q-args>)
|
||||
|
||||
" See |:RustExpand| for docs
|
||||
command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
|
||||
command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -buffer RustExpand call rust#Expand(<bang>0, <q-args>)
|
||||
|
||||
" See |:RustEmitIr| for docs
|
||||
command! -nargs=* -bar -buffer RustEmitIr call rust#Emit("ir", [<f-args>])
|
||||
command! -nargs=* -buffer RustEmitIr call rust#Emit("llvm-ir", <q-args>)
|
||||
|
||||
" See |:RustEmitAsm| for docs
|
||||
command! -nargs=* -bar -buffer RustEmitAsm call rust#Emit("asm", [<f-args>])
|
||||
command! -nargs=* -buffer RustEmitAsm call rust#Emit("asm", <q-args>)
|
||||
|
||||
" See |:RustPlay| for docs
|
||||
command! -range=% RustPlay :call rust#Play(<count>, <line1>, <line2>, <f-args>)
|
||||
|
||||
" See |:RustFmt| for docs
|
||||
command! -buffer RustFmt call rustfmt#Format()
|
||||
|
||||
" Mappings {{{1
|
||||
|
||||
@@ -134,6 +150,7 @@ let b:undo_ftplugin = "
|
||||
\|delcommand RustExpand
|
||||
\|delcommand RustEmitIr
|
||||
\|delcommand RustEmitAsm
|
||||
\|delcommand RustPlay
|
||||
\|nunmap <buffer> <D-r>
|
||||
\|nunmap <buffer> <D-R>
|
||||
\|nunmap <buffer> [[
|
||||
@@ -142,6 +159,8 @@ let b:undo_ftplugin = "
|
||||
\|xunmap <buffer> ]]
|
||||
\|ounmap <buffer> [[
|
||||
\|ounmap <buffer> ]]
|
||||
\|set matchpairs-=<:>
|
||||
\|unlet b:match_skip
|
||||
\"
|
||||
|
||||
" }}}1
|
||||
|
||||
8
ftplugin/swift.vim
Normal file
8
ftplugin/swift.vim
Normal file
@@ -0,0 +1,8 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'swift') == -1
|
||||
|
||||
setlocal commentstring=//\ %s
|
||||
" @-@ adds the literal @ to iskeyword for @IBAction and similar
|
||||
setlocal iskeyword+=@-@,#
|
||||
setlocal completefunc=syntaxcomplete#Complete
|
||||
|
||||
endif
|
||||
@@ -8,14 +8,15 @@ if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! ftplugin/html.vim ftplugin/html*.vim ftplugin/html/*.vim
|
||||
unlet! b:did_ftplugin
|
||||
|
||||
setlocal comments=s:{#,ex:#}
|
||||
setlocal formatoptions+=tcqln
|
||||
" setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
|
||||
|
||||
let b:undo_ftplugin .= "|setl cms< com< fo<"
|
||||
if exists("b:did_ftplugin")
|
||||
let b:undo_ftplugin .= "|setlocal comments< formatoptions<"
|
||||
else
|
||||
let b:undo_ftplugin = "setlocal comments< formatoptions<"
|
||||
endif
|
||||
|
||||
" vim:set sw=2:
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ setlocal commentstring=//\ %s
|
||||
" " and insert the comment leader when hitting <CR> or using "o".
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
setlocal suffixesadd+=.ts
|
||||
|
||||
let b:undo_ftplugin = "setl fo< ofu< com< cms<"
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
58
indent/ansible.vim
Normal file
58
indent/ansible.vim
Normal file
@@ -0,0 +1,58 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
setlocal indentexpr=GetAnsibleIndent(v:lnum)
|
||||
setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-,*<Return>
|
||||
setlocal nosmartindent
|
||||
setlocal expandtab
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
setlocal commentstring=#%s
|
||||
setlocal formatoptions=cl
|
||||
" c -> wrap long comments, including #
|
||||
" l -> do not wrap long lines
|
||||
|
||||
let s:comment = '\v^\s*#' " # comment
|
||||
let s:array_entry = '\v^\s*-\s' " - foo
|
||||
let s:named_module_entry = '\v^\s*-\s*(name|hosts):\s*\S' " - name: 'do stuff'
|
||||
let s:dictionary_entry = '\v^\s*[^:-]+:\s*$' " with_items:
|
||||
let s:key_value = '\v^\s*[^:-]+:\s*\S' " apt: name=package
|
||||
let s:scalar_value = '\v:\s*[>|\|]\s*$' " shell: >
|
||||
|
||||
if exists('*GetAnsibleIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
function GetAnsibleIndent(lnum)
|
||||
if a:lnum == 1 || !prevnonblank(a:lnum-1)
|
||||
return 0
|
||||
endif
|
||||
let prevlnum = prevnonblank(a:lnum - 1)
|
||||
let maintain = indent(prevlnum)
|
||||
let increase = maintain + &sw
|
||||
|
||||
let line = getline(prevlnum)
|
||||
if line =~ s:array_entry
|
||||
if line =~ s:named_module_entry
|
||||
return increase
|
||||
else
|
||||
return maintain
|
||||
endif
|
||||
elseif line =~ s:dictionary_entry
|
||||
return increase
|
||||
elseif line =~ s:key_value
|
||||
if line =~ s:scalar_value
|
||||
return increase
|
||||
else
|
||||
return maintain
|
||||
endif
|
||||
else
|
||||
return maintain
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
endif
|
||||
107
indent/blade.vim
107
indent/blade.vim
@@ -1,66 +1,59 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||
|
||||
" Language: Blade
|
||||
" Author: Barry Deeney <sitemaster16@gmail.com>
|
||||
" Version: 0.1
|
||||
" Description: BLADE indent file based on HTML indentation...
|
||||
" Vim indent file
|
||||
" Language: Blade (Laravel)
|
||||
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
||||
|
||||
" Check if this file has already been loaded
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
finish
|
||||
endif
|
||||
|
||||
" Include HTML
|
||||
runtime! indent/html.vim
|
||||
runtime! indent/php.vim
|
||||
silent! unlet b:did_indent
|
||||
|
||||
" What function do we need to use to detect indentation?
|
||||
setlocal indentexpr=BladeIndent()
|
||||
|
||||
" What keys would trigger indentation?
|
||||
setlocal indentkeys=o,O,<Return>,<>>,{,},!^F,0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/
|
||||
|
||||
" THE MAIN INDENT FUNCTION. Return the amount of indent for v:lnum.
|
||||
func! BladeIndent()
|
||||
" What is the current line?
|
||||
let current_line = v:lnum
|
||||
|
||||
" What is the current text?
|
||||
let current_text = tolower(getline(current_line))
|
||||
|
||||
" What was the last non blank line?
|
||||
let previous_line = prevnonblank(current_line)
|
||||
|
||||
" What was the last non blank text?
|
||||
let previous_text = tolower(getline(previous_line))
|
||||
|
||||
" How large are indents??
|
||||
let indent_size = &sw
|
||||
|
||||
" Check if we have a PHPIndent value...
|
||||
let indent = GetPhpIndent()
|
||||
|
||||
" check if we have indent
|
||||
if indent == -1
|
||||
" Check if we have BLADE
|
||||
if current_text =~ '^\s*@' || previous_text =~ '^\s*@'
|
||||
" We need to add to the indent
|
||||
return indent_size * indent(previous_text)
|
||||
endif
|
||||
|
||||
" Check if we have HTML
|
||||
if current_text =~ '^\s*<' || previous_text =~ '^\s*<'
|
||||
" We now give the honors to HtmlIndent()
|
||||
let indent = HtmlIndent()
|
||||
endif
|
||||
endif
|
||||
|
||||
" Give the indent back!
|
||||
return indent
|
||||
endfunc
|
||||
|
||||
" Make sure we store that flag!
|
||||
unlet! b:did_indent
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetBladeIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetBladeIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetBladeIndent()
|
||||
let lnum = prevnonblank(v:lnum-1)
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let line = substitute(substitute(getline(lnum), '\s\+$', '', ''), '^\s\+', '', '')
|
||||
let cline = substitute(substitute(getline(v:lnum), '\s\+$', '', ''), '^\s\+', '', '')
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
if cline =~# '@\%(else\|elseif\|empty\|end\|show\)'
|
||||
let indent = indent - &sw
|
||||
else
|
||||
if exists("*GetBladeIndentCustom")
|
||||
let hindent = GetBladeIndentCustom()
|
||||
else
|
||||
let hindent = HtmlIndent()
|
||||
endif
|
||||
if hindent > -1
|
||||
let indent = hindent
|
||||
endif
|
||||
endif
|
||||
let increase = indent + &sw
|
||||
if indent = indent(lnum)
|
||||
let indent = cindent <= indent ? -1 : increase
|
||||
endif
|
||||
|
||||
if line =~# '@\%(section\)\%(.*\s*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
|
||||
return indent
|
||||
elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\)\%(.*\s*@end\)\@!'
|
||||
return increase
|
||||
else
|
||||
return indent
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
35
indent/cabal.vim
Normal file
35
indent/cabal.vim
Normal file
@@ -0,0 +1,35 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
" indentation for cabal
|
||||
"
|
||||
" author: raichoo (raichoo@googlemail.com)
|
||||
"
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:cabal_indent_section')
|
||||
"executable name
|
||||
">>main-is: Main.hs
|
||||
">>hs-source-dirs: src
|
||||
let g:cabal_indent_section = 2
|
||||
elseif exists('g:cabal_indent_section') && g:cabal_indent_section > 4
|
||||
let g:cabal_indent_section = 4
|
||||
endif
|
||||
|
||||
setlocal indentexpr=GetCabalIndent()
|
||||
setlocal indentkeys=!^F,o,O,<CR>
|
||||
|
||||
function! GetCabalIndent()
|
||||
let l:prevline = getline(v:lnum - 1)
|
||||
|
||||
if l:prevline =~ '\C^\(executable\|library\|flag\|source-repository\|test-suite\|benchmark\)'
|
||||
return g:cabal_indent_section
|
||||
else
|
||||
return match(l:prevline, '\S')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endif
|
||||
639
indent/crystal.vim
Normal file
639
indent/crystal.vim
Normal file
@@ -0,0 +1,639 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:crystal_indent_access_modifier_style')
|
||||
" Possible values: "normal", "indent", "outdent"
|
||||
let g:crystal_indent_access_modifier_style = 'normal'
|
||||
endif
|
||||
|
||||
setlocal nosmartindent
|
||||
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetCrystalIndent(v:lnum)
|
||||
setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,.
|
||||
setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end
|
||||
setlocal indentkeys+==private,=protected,=public
|
||||
|
||||
" Only define the function once.
|
||||
if exists('*GetCrystalIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" 1. Variables {{{1
|
||||
" ============
|
||||
|
||||
" Regex of syntax group names that are or delimit strings/symbols or are comments.
|
||||
let s:syng_strcom = '\<crystal\%(Regexp\|RegexpDelimiter\|RegexpEscape' .
|
||||
\ '\|Symbol\|String\|StringDelimiter\|StringEscape\|ASCIICode' .
|
||||
\ '\|Interpolation\|InterpolationDelimiter\|NoInterpolation\|Comment\|Documentation\)\>'
|
||||
|
||||
" Regex of syntax group names that are strings.
|
||||
let s:syng_string =
|
||||
\ '\<crystal\%(String\|Interpolation\|NoInterpolation\|StringEscape\)\>'
|
||||
|
||||
" Regex of syntax group names that are strings or documentation.
|
||||
let s:syng_stringdoc =
|
||||
\'\<crystal\%(String\|Interpolation\|NoInterpolation\|StringEscape\|Documentation\)\>'
|
||||
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr =
|
||||
\ "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
|
||||
|
||||
" Regex used for words that, at the start of a line, add a level of indent.
|
||||
let s:crystal_indent_keywords =
|
||||
\ '^\s*\zs\<\%(module\|\%(abstract\)\=\s*\%(class\|struct\)\|enum\|if\|for\|macro' .
|
||||
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\|lib' .
|
||||
\ '\|\%(protected\|private\)\=\s*def\):\@!\>' .
|
||||
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' .
|
||||
\ '\|{%\s*\<\%(if\|for\|while\|until\|lib\|case\|unless\|begin\|else\|elsif\|when\)'
|
||||
|
||||
" Regex used for words that, at the start of a line, remove a level of indent.
|
||||
let s:crystal_deindent_keywords =
|
||||
\ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>' .
|
||||
\ '\|{%\s*\<\%(ensure\|else\|rescue\|elsif\|when\|end\)\>'
|
||||
|
||||
" Regex that defines the start-match for the 'end' keyword.
|
||||
" TODO: the do here should be restricted somewhat (only at end of line)?
|
||||
let s:end_start_regex =
|
||||
\ '{%\s*\<\%(if\|for\|while\|until\|unless\|begin\|lib\)\>\|' .
|
||||
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(module\|\%(abstract\)\=\s*\%(class\|struct\)\|enum\|macro\|if\|for\|while\|until\|case\|unless\|begin\|lib' .
|
||||
\ '\|\%(protected\|private\)\=\s*def\):\@!\>' .
|
||||
\ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>'
|
||||
|
||||
" Regex that defines the middle-match for the 'end' keyword.
|
||||
let s:end_middle_regex =
|
||||
\ '{%\s*\<\%(ensure\|else\|when\|elsif\)\>\s*%}\|' .
|
||||
\ '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|elsif\):\@!\>'
|
||||
|
||||
" Regex that defines the end-match for the 'end' keyword.
|
||||
let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>\|{%\s*\<\%(end\)\>'
|
||||
|
||||
" Expression used for searchpair() call for finding match for 'end' keyword.
|
||||
let s:end_skip_expr = s:skip_expr .
|
||||
\ ' || (expand("<cword>") == "do"' .
|
||||
\ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")'
|
||||
|
||||
" Regex that defines continuation lines, not including (, {, or [.
|
||||
let s:non_bracket_continuation_regex = '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines continuation lines.
|
||||
let s:continuation_regex =
|
||||
\ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines continuable keywords
|
||||
let s:continuable_regex =
|
||||
\ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' .
|
||||
\ '\<\%(if\|for\|while\|until\|unless\):\@!\>'
|
||||
|
||||
" Regex that defines bracket continuations
|
||||
let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines end of bracket continuation followed by another continuation
|
||||
let s:bracket_switch_continuation_regex = '^\([^(]\+\zs).\+\)\+'.s:continuation_regex
|
||||
|
||||
" Regex that defines the first part of a splat pattern
|
||||
let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$'
|
||||
|
||||
" Regex that defines blocks.
|
||||
"
|
||||
" Note that there's a slight problem with this regex and s:continuation_regex.
|
||||
" Code like this will be matched by both:
|
||||
"
|
||||
" method_call do |(a, b)|
|
||||
"
|
||||
" The reason is that the pipe matches a hanging "|" operator.
|
||||
"
|
||||
let s:block_regex =
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
|
||||
|
||||
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
|
||||
|
||||
" Regex that describes a leading operator (only a method call's dot for now)
|
||||
let s:leading_operator_regex = '^\s*[.]'
|
||||
|
||||
" Regex that describes all indent access modifiers
|
||||
let s:access_modifier_regex = '\C^\s*\%(public\|protected\|private\)\s*\%(#.*\)\=$'
|
||||
|
||||
" 2. Auxiliary Functions {{{1
|
||||
" ======================
|
||||
|
||||
" Check if the character at lnum:col is inside a string, comment, or is ascii.
|
||||
function s:IsInStringOrComment(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string.
|
||||
function s:IsInString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string or documentation.
|
||||
function s:IsInStringOrDocumentation(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_stringdoc
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string delimiter
|
||||
function s:IsInStringDelimiter(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') ==# 'crystalStringDelimiter'
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
||||
function s:PrevNonBlankNonString(lnum)
|
||||
let in_block = 0
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
while lnum > 0
|
||||
" Go in and out of blocks comments as necessary.
|
||||
" If the line isn't empty (with opt. comment) or in a string, end search.
|
||||
let line = getline(lnum)
|
||||
if line =~# '^=begin'
|
||||
if in_block
|
||||
let in_block = 0
|
||||
else
|
||||
break
|
||||
endif
|
||||
elseif !in_block && line =~# '^=end'
|
||||
let in_block = 1
|
||||
elseif !in_block && line !~# '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
|
||||
\ && s:IsInStringOrComment(lnum, strlen(line)))
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
|
||||
function s:GetMSL(lnum)
|
||||
" Start on the line we're at and use its indent.
|
||||
let msl = a:lnum
|
||||
let msl_body = getline(msl)
|
||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
while lnum > 0
|
||||
" If we have a continuation line, or we're in a string, use line as MSL.
|
||||
" Otherwise, terminate search as we have found our MSL already.
|
||||
let line = getline(lnum)
|
||||
|
||||
if s:Match(msl, s:leading_operator_regex)
|
||||
" If the current line starts with a leading operator, keep its indent
|
||||
" and keep looking for an MSL.
|
||||
let msl = lnum
|
||||
elseif s:Match(lnum, s:splat_regex)
|
||||
" If the above line looks like the "*" of a splat, use the current one's
|
||||
" indentation.
|
||||
"
|
||||
" Example:
|
||||
" Hash[*
|
||||
" method_call do
|
||||
" something
|
||||
"
|
||||
return msl
|
||||
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
||||
\ s:Match(msl, s:non_bracket_continuation_regex)
|
||||
" If the current line is a non-bracket continuation and so is the
|
||||
" previous one, keep its indent and continue looking for an MSL.
|
||||
"
|
||||
" Example:
|
||||
" method_call one,
|
||||
" two,
|
||||
" three
|
||||
"
|
||||
let msl = lnum
|
||||
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
|
||||
" If the current line is a bracket continuation or a block-starter, but
|
||||
" the previous is a non-bracket one, respect the previous' indentation,
|
||||
" and stop here.
|
||||
"
|
||||
" Example:
|
||||
" method_call one,
|
||||
" two {
|
||||
" three
|
||||
"
|
||||
return lnum
|
||||
elseif s:Match(lnum, s:bracket_continuation_regex) &&
|
||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex))
|
||||
" If both lines are bracket continuations (the current may also be a
|
||||
" block-starter), use the current one's and stop here
|
||||
"
|
||||
" Example:
|
||||
" method_call(
|
||||
" other_method_call(
|
||||
" foo
|
||||
return msl
|
||||
elseif s:Match(lnum, s:block_regex) &&
|
||||
\ !s:Match(msl, s:continuation_regex) &&
|
||||
\ !s:Match(msl, s:block_continuation_regex)
|
||||
" If the previous line is a block-starter and the current one is
|
||||
" mostly ordinary, use the current one as the MSL.
|
||||
"
|
||||
" Example:
|
||||
" method_call do
|
||||
" something
|
||||
" something_else
|
||||
return msl
|
||||
else
|
||||
let col = match(line, s:continuation_regex) + 1
|
||||
if (col > 0 && !s:IsInStringOrComment(lnum, col))
|
||||
\ || s:IsInString(lnum, strlen(line))
|
||||
let msl = lnum
|
||||
else
|
||||
break
|
||||
endif
|
||||
endif
|
||||
|
||||
let msl_body = getline(msl)
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
return msl
|
||||
endfunction
|
||||
|
||||
" Check if line 'lnum' has more opening brackets than closing ones.
|
||||
function s:ExtraBrackets(lnum)
|
||||
let opening = {'parentheses': [], 'braces': [], 'brackets': []}
|
||||
let closing = {'parentheses': [], 'braces': [], 'brackets': []}
|
||||
|
||||
let line = getline(a:lnum)
|
||||
let pos = match(line, '[][(){}]', 0)
|
||||
|
||||
" Save any encountered opening brackets, and remove them once a matching
|
||||
" closing one has been found. If a closing bracket shows up that doesn't
|
||||
" close anything, save it for later.
|
||||
while pos != -1
|
||||
if !s:IsInStringOrComment(a:lnum, pos + 1)
|
||||
if line[pos] ==# '('
|
||||
call add(opening.parentheses, {'type': '(', 'pos': pos})
|
||||
elseif line[pos] ==# ')'
|
||||
if empty(opening.parentheses)
|
||||
call add(closing.parentheses, {'type': ')', 'pos': pos})
|
||||
else
|
||||
let opening.parentheses = opening.parentheses[0:-2]
|
||||
endif
|
||||
elseif line[pos] ==# '{'
|
||||
call add(opening.braces, {'type': '{', 'pos': pos})
|
||||
elseif line[pos] ==# '}'
|
||||
if empty(opening.braces)
|
||||
call add(closing.braces, {'type': '}', 'pos': pos})
|
||||
else
|
||||
let opening.braces = opening.braces[0:-2]
|
||||
endif
|
||||
elseif line[pos] ==# '['
|
||||
call add(opening.brackets, {'type': '[', 'pos': pos})
|
||||
elseif line[pos] ==# ']'
|
||||
if empty(opening.brackets)
|
||||
call add(closing.brackets, {'type': ']', 'pos': pos})
|
||||
else
|
||||
let opening.brackets = opening.brackets[0:-2]
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let pos = match(line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
|
||||
" Find the rightmost brackets, since they're the ones that are important in
|
||||
" both opening and closing cases
|
||||
let rightmost_opening = {'type': '(', 'pos': -1}
|
||||
let rightmost_closing = {'type': ')', 'pos': -1}
|
||||
|
||||
for opening in opening.parentheses + opening.braces + opening.brackets
|
||||
if opening.pos > rightmost_opening.pos
|
||||
let rightmost_opening = opening
|
||||
endif
|
||||
endfor
|
||||
|
||||
for closing in closing.parentheses + closing.braces + closing.brackets
|
||||
if closing.pos > rightmost_closing.pos
|
||||
let rightmost_closing = closing
|
||||
endif
|
||||
endfor
|
||||
|
||||
return [rightmost_opening, rightmost_closing]
|
||||
endfunction
|
||||
|
||||
function s:Match(lnum, regex)
|
||||
let line = getline(a:lnum)
|
||||
let offset = match(line, '\C'.a:regex)
|
||||
let col = offset + 1
|
||||
|
||||
while offset > -1 && s:IsInStringOrComment(a:lnum, col)
|
||||
let offset = match(line, '\C'.a:regex, offset + 1)
|
||||
let col = offset + 1
|
||||
endwhile
|
||||
|
||||
if offset > -1
|
||||
return col
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Locates the containing class/module's definition line, ignoring nested classes
|
||||
" along the way.
|
||||
"
|
||||
function! s:FindContainingClass()
|
||||
let saved_position = getpos('.')
|
||||
|
||||
while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
if expand('<cword>') =~# '\<class\|module\>'
|
||||
let found_lnum = line('.')
|
||||
call setpos('.', saved_position)
|
||||
return found_lnum
|
||||
endif
|
||||
endwhile
|
||||
|
||||
call setpos('.', saved_position)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" 3. GetCrystalIndent Function {{{1
|
||||
" =========================
|
||||
|
||||
function GetCrystalIndent(...)
|
||||
" 3.1. Setup {{{2
|
||||
" ----------
|
||||
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
" For the current line, use the first argument if given, else v:lnum
|
||||
let clnum = a:0 ? a:1 : v:lnum
|
||||
|
||||
" Set up variables for restoring position in file. Could use clnum here.
|
||||
let vcol = col('.')
|
||||
|
||||
" 3.2. Work on the current line {{{2
|
||||
" -----------------------------
|
||||
|
||||
" Get the current line.
|
||||
let line = getline(clnum)
|
||||
let ind = -1
|
||||
|
||||
" If this line is an access modifier keyword, align according to the closest
|
||||
" class declaration.
|
||||
if g:crystal_indent_access_modifier_style ==? 'indent'
|
||||
if s:Match(clnum, s:access_modifier_regex)
|
||||
let class_line = s:FindContainingClass()
|
||||
if class_line > 0
|
||||
return indent(class_line) + sw
|
||||
endif
|
||||
endif
|
||||
elseif g:crystal_indent_access_modifier_style ==? 'outdent'
|
||||
if s:Match(clnum, s:access_modifier_regex)
|
||||
let class_line = s:FindContainingClass()
|
||||
if class_line > 0
|
||||
return indent(class_line)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" If we got a closing bracket on an empty line, find its match and indent
|
||||
" according to it. For parentheses we indent to its column - 1, for the
|
||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||
let col = matchend(line, '^\s*[]})]')
|
||||
if col > 0 && !s:IsInStringOrComment(clnum, col)
|
||||
call cursor(clnum, col)
|
||||
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
|
||||
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
||||
if line[col-1] ==# ')' && col('.') != col('$') - 1
|
||||
let ind = virtcol('.') - 1
|
||||
else
|
||||
let ind = indent(s:GetMSL(line('.')))
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If we have a =begin or =end set indent to first column.
|
||||
if match(line, '^\s*\%(=begin\|=end\)$') != -1
|
||||
return 0
|
||||
endif
|
||||
|
||||
" If we have a deindenting keyword, find its match and indent to its level.
|
||||
" TODO: this is messy
|
||||
if s:Match(clnum, s:crystal_deindent_keywords)
|
||||
call cursor(clnum, 1)
|
||||
if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
let msl = s:GetMSL(line('.'))
|
||||
let line = getline(line('.'))
|
||||
|
||||
if strpart(line, 0, col('.') - 1) =~# '=\s*$' &&
|
||||
\ strpart(line, col('.') - 1, 2) !~# 'do'
|
||||
" assignment to case/begin/etc, on the same line, hanging indent
|
||||
let ind = virtcol('.') - 1
|
||||
elseif getline(msl) =~# '=\s*\(#.*\)\=$'
|
||||
" in the case of assignment to the msl, align to the starting line,
|
||||
" not to the msl
|
||||
let ind = indent(line('.'))
|
||||
else
|
||||
" align to the msl
|
||||
let ind = indent(msl)
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If we are in a multi-line string or line-comment, don't do anything to it.
|
||||
if s:IsInStringOrDocumentation(clnum, matchend(line, '^\s*') + 1)
|
||||
return indent('.')
|
||||
endif
|
||||
|
||||
" If we are at the closing delimiter of a "<<" heredoc-style string, set the
|
||||
" indent to 0.
|
||||
if line =~# '^\k\+\s*$'
|
||||
\ && s:IsInStringDelimiter(clnum, 1)
|
||||
\ && search('\V<<'.line, 'nbW') > 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" If the current line starts with a leading operator, add a level of indent.
|
||||
if s:Match(clnum, s:leading_operator_regex)
|
||||
return indent(s:GetMSL(clnum)) + sw
|
||||
endif
|
||||
|
||||
" 3.3. Work on the previous line. {{{2
|
||||
" -------------------------------
|
||||
|
||||
" Find a non-blank, non-multi-line string line above the current line.
|
||||
let lnum = s:PrevNonBlankNonString(clnum - 1)
|
||||
|
||||
" If the line is empty and inside a string, use the previous line.
|
||||
if line =~# '^\s*$' && lnum != prevnonblank(clnum - 1)
|
||||
return indent(prevnonblank(clnum))
|
||||
endif
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Set up variables for the previous line.
|
||||
let line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
if s:Match(lnum, s:continuable_regex) && s:Match(lnum, s:continuation_regex)
|
||||
return indent(s:GetMSL(lnum)) + sw + sw
|
||||
endif
|
||||
|
||||
" If the previous line ended with a block opening, add a level of indent.
|
||||
if s:Match(lnum, s:block_regex)
|
||||
let msl = s:GetMSL(lnum)
|
||||
|
||||
if getline(msl) =~# '=\s*\(#.*\)\=$'
|
||||
" in the case of assignment to the msl, align to the starting line,
|
||||
" not to the msl
|
||||
let ind = indent(lnum) + sw
|
||||
else
|
||||
let ind = indent(msl) + sw
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If the previous line started with a leading operator, use its MSL's level
|
||||
" of indent
|
||||
if s:Match(lnum, s:leading_operator_regex)
|
||||
return indent(s:GetMSL(lnum))
|
||||
endif
|
||||
|
||||
" If the previous line ended with the "*" of a splat, add a level of indent
|
||||
if line =~ s:splat_regex
|
||||
return indent(lnum) + sw
|
||||
endif
|
||||
|
||||
" If the previous line contained unclosed opening brackets and we are still
|
||||
" in them, find the rightmost one and add indent depending on the bracket
|
||||
" type.
|
||||
"
|
||||
" If it contained hanging closing brackets, find the rightmost one, find its
|
||||
" match and indent according to that.
|
||||
if line =~# '[[({]' || line =~# '[])}]\s*\%(#.*\)\=$'
|
||||
let [opening, closing] = s:ExtraBrackets(lnum)
|
||||
|
||||
if opening.pos != -1
|
||||
if opening.type ==# '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
if col('.') + 1 == col('$')
|
||||
return ind + sw
|
||||
else
|
||||
return virtcol('.')
|
||||
endif
|
||||
else
|
||||
let nonspace = matchend(line, '\S', opening.pos + 1) - 1
|
||||
return nonspace > 0 ? nonspace : ind + sw
|
||||
endif
|
||||
elseif closing.pos != -1
|
||||
call cursor(lnum, closing.pos + 1)
|
||||
normal! %
|
||||
|
||||
if s:Match(line('.'), s:crystal_indent_keywords)
|
||||
return indent('.') + sw
|
||||
else
|
||||
return indent('.')
|
||||
endif
|
||||
else
|
||||
call cursor(clnum, vcol)
|
||||
end
|
||||
endif
|
||||
|
||||
" If the previous line ended with an "end", match that "end"s beginning's
|
||||
" indent.
|
||||
let col = s:Match(lnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
|
||||
if col > 0
|
||||
call cursor(lnum, col)
|
||||
if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
|
||||
\ s:end_skip_expr) > 0
|
||||
let n = line('.')
|
||||
let ind = indent('.')
|
||||
let msl = s:GetMSL(n)
|
||||
if msl != n
|
||||
let ind = indent(msl)
|
||||
end
|
||||
return ind
|
||||
endif
|
||||
end
|
||||
|
||||
let col = s:Match(lnum, s:crystal_indent_keywords)
|
||||
if col > 0
|
||||
call cursor(lnum, col)
|
||||
let ind = virtcol('.') - 1 + sw
|
||||
" TODO: make this better (we need to count them) (or, if a searchpair
|
||||
" fails, we know that something is lacking an end and thus we indent a
|
||||
" level
|
||||
if s:Match(lnum, s:end_end_regex)
|
||||
let ind = indent('.')
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" 3.4. Work on the MSL line. {{{2
|
||||
" --------------------------
|
||||
|
||||
" Set up variables to use and search for MSL to the previous line.
|
||||
let p_lnum = lnum
|
||||
let lnum = s:GetMSL(lnum)
|
||||
|
||||
" If the previous line wasn't a MSL.
|
||||
if p_lnum != lnum
|
||||
" If previous line ends bracket and begins non-bracket continuation decrease indent by 1.
|
||||
if s:Match(p_lnum, s:bracket_switch_continuation_regex)
|
||||
return ind - 1
|
||||
" If previous line is a continuation return its indent.
|
||||
" TODO: the || s:IsInString() thing worries me a bit.
|
||||
elseif s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line))
|
||||
return ind
|
||||
endif
|
||||
endif
|
||||
|
||||
" Set up more variables, now that we know we wasn't continuation bound.
|
||||
let line = getline(lnum)
|
||||
let msl_ind = indent(lnum)
|
||||
|
||||
" If the MSL line had an indenting keyword in it, add a level of indent.
|
||||
" TODO: this does not take into account contrived things such as
|
||||
" module Foo; class Bar; end
|
||||
if s:Match(lnum, s:crystal_indent_keywords)
|
||||
let ind = msl_ind + sw
|
||||
if s:Match(lnum, s:end_end_regex)
|
||||
let ind = ind - sw
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If the previous line ended with [*+/.,-=], but wasn't a block ending or a
|
||||
" closing bracket, indent one extra level.
|
||||
if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)')
|
||||
if lnum == p_lnum
|
||||
let ind = msl_ind + sw
|
||||
else
|
||||
let ind = msl_ind
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" }}}2
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim:set sw=2 sts=2 ts=8 et:
|
||||
|
||||
endif
|
||||
@@ -29,6 +29,7 @@ function! GetCucumberIndent()
|
||||
let line = getline(prevnonblank(v:lnum-1))
|
||||
let cline = getline(v:lnum)
|
||||
let nline = getline(nextnonblank(v:lnum+1))
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let syn = s:syn(prevnonblank(v:lnum-1))
|
||||
let csyn = s:syn(v:lnum)
|
||||
let nsyn = s:syn(nextnonblank(v:lnum+1))
|
||||
@@ -37,38 +38,38 @@ function! GetCucumberIndent()
|
||||
return 0
|
||||
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
|
||||
" examples heading
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||
" background, scenario or outline heading
|
||||
return &sw
|
||||
return sw
|
||||
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
|
||||
" line after feature heading
|
||||
return &sw
|
||||
return sw
|
||||
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
|
||||
" line after examples heading
|
||||
return 3 * &sw
|
||||
return 3 * sw
|
||||
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||
" line after background, scenario or outline heading
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
|
||||
" tag or comment before a feature heading
|
||||
return 0
|
||||
elseif cline =~# '^\s*@'
|
||||
" other tags
|
||||
return &sw
|
||||
return sw
|
||||
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
|
||||
" mid-table
|
||||
" preserve indent
|
||||
return indent(prevnonblank(v:lnum-1))
|
||||
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
|
||||
" first line of a table, relative indent
|
||||
return indent(prevnonblank(v:lnum-1)) + &sw
|
||||
return indent(prevnonblank(v:lnum-1)) + sw
|
||||
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
|
||||
" line after a table, relative unindent
|
||||
return indent(prevnonblank(v:lnum-1)) - &sw
|
||||
return indent(prevnonblank(v:lnum-1)) - sw
|
||||
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
|
||||
" comments on scenarios
|
||||
return &sw
|
||||
return sw
|
||||
endif
|
||||
return indent(prevnonblank(v:lnum-1))
|
||||
endfunction
|
||||
|
||||
13
indent/dart.vim
Normal file
13
indent/dart.vim
Normal file
@@ -0,0 +1,13 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dart') == -1
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal cindent
|
||||
setlocal cinoptions+=j1,J1
|
||||
|
||||
let b:undo_indent = 'setl cin< cino<'
|
||||
|
||||
endif
|
||||
@@ -1,10 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Embedded Elixir
|
||||
" URL: https://github.com/elixir-lang/vim-elixir
|
||||
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Elixir
|
||||
" Maintainer: Carlos Galdino <carloshsgaldino@gmail.com>
|
||||
" Last Change: 2013 Apr 24
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
@@ -13,7 +8,7 @@ let b:did_indent = 1
|
||||
setlocal nosmartindent
|
||||
|
||||
setlocal indentexpr=GetElixirIndent()
|
||||
setlocal indentkeys+=0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
|
||||
setlocal indentkeys+=0),0],0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
|
||||
|
||||
if exists("*GetElixirIndent")
|
||||
finish
|
||||
@@ -22,27 +17,41 @@ endif
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" . s:skip_syntax . "'"
|
||||
let s:block_start = 'do\|fn'
|
||||
let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
|
||||
let s:block_end = 'end'
|
||||
let s:symbols_end = '\]\|}'
|
||||
let s:arrow = '^.*->$'
|
||||
let s:pipeline = '^\s*|>.*$'
|
||||
let s:no_colon_before = ':\@<!'
|
||||
let s:no_colon_after = ':\@!'
|
||||
let s:symbols_end = '\]\|}\|)'
|
||||
let s:symbols_start = '\[\|{\|('
|
||||
let s:arrow = '^.*->$'
|
||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:skip_syntax."'"
|
||||
let s:block_start = '\<\%(do\|fn\)\>'
|
||||
let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
|
||||
let s:block_end = 'end'
|
||||
let s:starts_with_pipeline = '^\s*|>.*$'
|
||||
let s:ending_with_assignment = '=\s*$'
|
||||
|
||||
let s:indent_keywords = '\<\%(' . s:block_start . '\|' . s:block_middle . '\)$' . '\|' . s:arrow
|
||||
let s:deindent_keywords = '^\s*\<\%(' . s:block_end . '\|' . s:block_middle . '\)\>' . '\|' . s:arrow
|
||||
let s:indent_keywords = '\<'.s:no_colon_before.'\%('.s:block_start.'\|'.s:block_middle.'\)$'.'\|'.s:arrow
|
||||
let s:deindent_keywords = '^\s*\<\%('.s:block_end.'\|'.s:block_middle.'\)\>'.'\|'.s:arrow
|
||||
|
||||
let s:pair_start = '\<\%('.s:no_colon_before.s:block_start.'\)\>'.s:no_colon_after
|
||||
let s:pair_middle = '\<\%('.s:block_middle.'\)\>'.s:no_colon_after.'\zs'
|
||||
let s:pair_end = '\<\%('.s:no_colon_before.s:block_end.'\)\>\zs'
|
||||
|
||||
let s:inside_block = 0
|
||||
|
||||
function! GetElixirIndent()
|
||||
let lnum = prevnonblank(v:lnum - 1)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let opened_symbol = 0
|
||||
let current_line = getline(v:lnum)
|
||||
let last_line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" TODO: Remove these 2 lines
|
||||
" I don't know why, but for the test on spec/indent/lists_spec.rb:24.
|
||||
" Vim is making some mess on parsing the syntax of 'end', it is being
|
||||
@@ -52,58 +61,71 @@ function! GetElixirIndent()
|
||||
syntax sync fromstart
|
||||
|
||||
if synIDattr(synID(v:lnum, 1, 1), "name") !~ s:skip_syntax
|
||||
let current_line = getline(v:lnum)
|
||||
let last_line = getline(lnum)
|
||||
|
||||
let splited_line = split(last_line, '\zs')
|
||||
let opened_symbol = 0
|
||||
let opened_symbol += count(splited_line, '[') - count(splited_line, ']')
|
||||
let opened_symbol += count(splited_line, '{') - count(splited_line, '}')
|
||||
if last_line !~ s:arrow
|
||||
let split_line = split(last_line, '\zs')
|
||||
let opened_symbol += count(split_line, '(') - count(split_line, ')')
|
||||
let opened_symbol += count(split_line, '[') - count(split_line, ']')
|
||||
let opened_symbol += count(split_line, '{') - count(split_line, '}')
|
||||
end
|
||||
|
||||
let ind += opened_symbol * &sw
|
||||
" if start symbol is followed by a character, indent based on the
|
||||
" whitespace after the symbol, otherwise use the default shiftwidth
|
||||
if last_line =~ '\('.s:symbols_start.'\).'
|
||||
let opened_prefix = matchlist(last_line, '\('.s:symbols_start.'\)\s*')[0]
|
||||
let ind += (opened_symbol * strlen(opened_prefix))
|
||||
else
|
||||
let ind += (opened_symbol * &sw)
|
||||
endif
|
||||
|
||||
if last_line =~ '^\s*\(' . s:symbols_end . '\)'
|
||||
if last_line =~ '^\s*\('.s:symbols_end.'\)' || last_line =~ s:indent_keywords
|
||||
let ind += &sw
|
||||
endif
|
||||
|
||||
if current_line =~ '^\s*\(' . s:symbols_end . '\)'
|
||||
if current_line =~ '^\s*\('.s:symbols_end.'\)'
|
||||
let ind -= &sw
|
||||
endif
|
||||
|
||||
if last_line =~ s:indent_keywords
|
||||
if last_line =~ s:ending_with_assignment && opened_symbol == 0
|
||||
let b:old_ind = indent(lnum)
|
||||
let ind += &sw
|
||||
endif
|
||||
end
|
||||
|
||||
" if line starts with pipeline
|
||||
" and last line contains pipeline(s)
|
||||
" and last line ends with a pipeline,
|
||||
" align them
|
||||
if last_line =~ '|>.*$' &&
|
||||
\ current_line =~ s:pipeline
|
||||
\ current_line =~ s:starts_with_pipeline
|
||||
let ind = float2nr(match(last_line, '|>') / &sw) * &sw
|
||||
|
||||
" if line starts with pipeline
|
||||
" and last line is an attribution
|
||||
" indents pipeline in same level as attribution
|
||||
elseif current_line =~ s:pipeline &&
|
||||
elseif current_line =~ s:starts_with_pipeline &&
|
||||
\ last_line =~ '^[^=]\+=.\+$'
|
||||
let b:old_ind = ind
|
||||
|
||||
if !exists('b:old_ind') || b:old_ind == 0
|
||||
let b:old_ind = indent(lnum)
|
||||
end
|
||||
let ind = float2nr(matchend(last_line, '=\s*[^ ]') / &sw) * &sw
|
||||
endif
|
||||
|
||||
" if last line starts with pipeline
|
||||
" and current line doesn't start with pipeline
|
||||
" returns the indentation before the pipeline
|
||||
if last_line =~ s:pipeline &&
|
||||
\ current_line !~ s:pipeline
|
||||
if last_line =~ s:starts_with_pipeline &&
|
||||
\ current_line !~ s:starts_with_pipeline
|
||||
let ind = b:old_ind
|
||||
endif
|
||||
|
||||
if current_line =~ s:deindent_keywords
|
||||
let bslnum = searchpair( '\<\%(' . s:block_start . '\):\@!\>',
|
||||
\ '\<\%(' . s:block_middle . '\):\@!\>\zs',
|
||||
\ '\<:\@<!' . s:block_end . '\>\zs',
|
||||
let bslnum = searchpair(
|
||||
\ s:pair_start,
|
||||
\ s:pair_middle,
|
||||
\ s:pair_end,
|
||||
\ 'nbW',
|
||||
\ s:block_skip )
|
||||
\ s:block_skip
|
||||
\ )
|
||||
|
||||
let ind = indent(bslnum)
|
||||
endif
|
||||
|
||||
129
indent/elm.vim
Normal file
129
indent/elm.vim
Normal file
@@ -0,0 +1,129 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Haskell
|
||||
" Maintainer: lilydjwg <lilydjwg@gmail.com>
|
||||
" Version: 1.0
|
||||
" References: http://en.wikibooks.org/wiki/Haskell/Indentation
|
||||
" http://book.realworldhaskell.org/read/
|
||||
" See Also: The Align plugin http://www.vim.org/scripts/script.php?script_id=294
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=HaskellIndent()
|
||||
for i in split('0{,:,0#,e', ',')
|
||||
exec "setlocal indentkeys-=" . i
|
||||
endfor
|
||||
setlocal indentkeys+=0=else,0=in,0=where,0),0<bar>
|
||||
setlocal tabstop=8
|
||||
setlocal expandtab
|
||||
|
||||
if !exists('g:Haskell_no_mapping')
|
||||
inoremap <silent> <BS> <C-R>=<SID>HaskellDedent(1)<CR>
|
||||
inoremap <silent> <C-D> <C-R>=<SID>HaskellDedent(0)<CR>
|
||||
endif
|
||||
|
||||
" Only define the functions once.
|
||||
if exists("*HaskellIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:align_map = {
|
||||
\ 'in': '\<let\>',
|
||||
\ '\<else\>': '\<then\>',
|
||||
\ ',': '\v%(\s|\w|^)@<=[[{]%(\s|\w|"|$)@='
|
||||
\ }
|
||||
let s:indent_self = ['=']
|
||||
let s:indent_next = ['let', 'in', 'where', 'do', 'if']
|
||||
let s:indent_if_final = ['=', 'do', '->', 'of', 'where']
|
||||
|
||||
function HaskellIndent()
|
||||
let lnum = v:lnum - 1
|
||||
|
||||
" Hit the start of the file, use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(lnum)
|
||||
let prevline = getline(lnum)
|
||||
let curline = getline(v:lnum)
|
||||
let curwords = split(curline)
|
||||
if len(curwords) > 0
|
||||
if has_key(s:align_map, curwords[0])
|
||||
let word = s:align_map[curwords[0]]
|
||||
let m = -1
|
||||
let line = v:lnum
|
||||
while m == -1
|
||||
let line -= 1
|
||||
if line <= 0
|
||||
return -1
|
||||
endif
|
||||
let m = match(getline(line), word)
|
||||
endwhile
|
||||
return m
|
||||
elseif index(s:indent_self, curwords[0]) != -1
|
||||
return ind + &sw
|
||||
elseif curwords[0] == '|'
|
||||
return match(prevline, '\v%(\s|\w|^)@<=[|=]%(\s|\w)@=')
|
||||
elseif index([')', '}'], curwords[0]) != -1
|
||||
return ind - &sw
|
||||
elseif curwords[0] == 'where'
|
||||
if prevline =~ '\v^\s+\|%(\s|\w)@='
|
||||
return ind - 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let prevwords = split(prevline)
|
||||
if len(prevwords) == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
if prevwords[-1] == 'where' && prevwords[0] == 'module'
|
||||
return 0
|
||||
elseif index(s:indent_if_final, prevwords[-1]) != -1
|
||||
return ind + &sw
|
||||
elseif prevwords[-1] =~ '\v%(\s|\w|^)@<=[[{(]$'
|
||||
return ind + &sw
|
||||
else
|
||||
for word in reverse(prevwords)
|
||||
if index(s:indent_next, word) != -1
|
||||
return match(prevline, '\<'.word.'\>') + len(word) + 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if len(curwords) > 0 && curwords[0] == 'where'
|
||||
return ind + &sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
function s:HaskellDedent(isbs)
|
||||
if a:isbs && strpart(getline('.'), 0, col('.')-1) !~ '^\s\+$'
|
||||
return "\<BS>"
|
||||
endif
|
||||
|
||||
let curind = indent('.')
|
||||
let line = line('.') - 1
|
||||
while curind > 0 && line > 0
|
||||
let ind = indent(line)
|
||||
if ind >= curind
|
||||
let line -= 1
|
||||
else
|
||||
echomsg curind ind
|
||||
call setline('.', repeat(' ', ind) .
|
||||
\ substitute(getline('.'), '^\s\+', '', ''))
|
||||
return ''
|
||||
endif
|
||||
endwhile
|
||||
return a:isbs ? "\<BS>" : ''
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -92,7 +92,7 @@ function! GetErubyIndent(...)
|
||||
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$'
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if cline =~# '^\s*[-=]\=%>\s*$'
|
||||
|
||||
6
indent/fish.vim
Normal file
6
indent/fish.vim
Normal file
@@ -0,0 +1,6 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
setlocal indentexpr=fish#Indent()
|
||||
setlocal indentkeys+==end,=else,=case
|
||||
|
||||
endif
|
||||
@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
|
||||
" Vim indent file
|
||||
" Language: git config file
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" Last Change: 2012 April 7
|
||||
" Last Change: 2013 May 30
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
@@ -22,17 +22,18 @@ if exists("*GetGitconfigIndent")
|
||||
endif
|
||||
|
||||
function! GetGitconfigIndent()
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let line = getline(prevnonblank(v:lnum-1))
|
||||
let cline = getline(v:lnum)
|
||||
if line =~ '\\\@<!\%(\\\\\)*\\$'
|
||||
" odd number of slashes, in a line continuation
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif cline =~ '^\s*\['
|
||||
return 0
|
||||
elseif cline =~ '^\s*\a'
|
||||
return &sw
|
||||
return sw
|
||||
elseif cline == '' && line =~ '^\['
|
||||
return &sw
|
||||
return sw
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
|
||||
@@ -6,4 +6,43 @@ endif
|
||||
|
||||
runtime! indent/html.vim
|
||||
|
||||
" Indent Golang HTML templates
|
||||
setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
|
||||
setlocal indentkeys+==else,=end
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetGoHTMLTmplIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetGoHTMLTmplIndent(lnum)
|
||||
" Get HTML indent
|
||||
if exists('*HtmlIndent')
|
||||
let ind = HtmlIndent()
|
||||
else
|
||||
let ind = HtmlIndentGet(a:lnum)
|
||||
endif
|
||||
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
" If need to indent based on last line
|
||||
let last_line = getline(a:lnum-1)
|
||||
if last_line =~ '^\s*{{\s*\%(if\|else\|range\|with\|define\|block\).*}}'
|
||||
let ind += sw
|
||||
endif
|
||||
|
||||
" End of FuncMap block
|
||||
let current_line = getline(a:lnum)
|
||||
if current_line =~ '^\s*{{\s*\%(else\|end\).*}}'
|
||||
let ind -= sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
@@ -39,10 +39,11 @@ function! GetHamlIndent()
|
||||
let line = substitute(line,'^\s\+','','')
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
if cline =~# '\v^-\s*%(elsif|else|when)>'
|
||||
let indent = cindent < indent ? cindent : indent - &sw
|
||||
let indent = cindent < indent ? cindent : indent - sw
|
||||
endif
|
||||
let increase = indent + &sw
|
||||
let increase = indent + sw
|
||||
if indent == indent(lnum)
|
||||
let indent = cindent <= indent ? -1 : increase
|
||||
endif
|
||||
|
||||
104
indent/handlebars.vim
Normal file
104
indent/handlebars.vim
Normal file
@@ -0,0 +1,104 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'handlebars') == -1
|
||||
|
||||
" Mustache & Handlebars syntax
|
||||
" Language: Mustache, Handlebars
|
||||
" Maintainer: Juvenn Woo <machese@gmail.com>
|
||||
" Screenshot: http://imgur.com/6F408
|
||||
" Version: 2
|
||||
" Last Change: Oct 10th 2015
|
||||
" Remarks: based on eruby indent plugin by tpope
|
||||
" References:
|
||||
" [Mustache](http://github.com/defunkt/mustache)
|
||||
" [Handlebars](https://github.com/wycats/handlebars.js)
|
||||
" [ctemplate](http://code.google.com/p/google-ctemplate/)
|
||||
" [ctemplate doc](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html)
|
||||
" [et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html)
|
||||
|
||||
if exists("b:did_indent_hbs")
|
||||
finish
|
||||
endif
|
||||
|
||||
unlet! b:did_indent
|
||||
setlocal indentexpr=
|
||||
|
||||
runtime! indent/html.vim
|
||||
unlet! b:did_indent
|
||||
|
||||
" Force HTML indent to not keep state.
|
||||
let b:html_indent_usestate = 0
|
||||
|
||||
if &l:indentexpr == ''
|
||||
if &l:cindent
|
||||
let &l:indentexpr = 'cindent(v:lnum)'
|
||||
else
|
||||
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
|
||||
endif
|
||||
endif
|
||||
let b:handlebars_subtype_indentexpr = &l:indentexpr
|
||||
|
||||
let b:did_indent = 1
|
||||
let b:did_indent_hbs = 1
|
||||
|
||||
setlocal indentexpr=GetHandlebarsIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetHandlebarsIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetHandlebarsIndent(...)
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
if a:0 && a:1 == '.'
|
||||
let v:lnum = line('.')
|
||||
elseif a:0 && a:1 =~ '^\d'
|
||||
let v:lnum = a:1
|
||||
endif
|
||||
let vcol = col('.')
|
||||
call cursor(v:lnum,1)
|
||||
call cursor(v:lnum,vcol)
|
||||
exe "let ind = ".b:handlebars_subtype_indentexpr
|
||||
|
||||
" Workaround for Andy Wokula's HTML indent. This should be removed after
|
||||
" some time, since the newest version is fixed in a different way.
|
||||
if b:handlebars_subtype_indentexpr =~# '^HtmlIndent('
|
||||
\ && exists('b:indent')
|
||||
\ && type(b:indent) == type({})
|
||||
\ && has_key(b:indent, 'lnum')
|
||||
" Force HTML indent to not keep state
|
||||
let b:indent.lnum = -1
|
||||
endif
|
||||
let lnum = prevnonblank(v:lnum-1)
|
||||
let line = getline(lnum)
|
||||
let cline = getline(v:lnum)
|
||||
|
||||
" all indent rules only apply if the block opening/closing
|
||||
" tag is on a separate line
|
||||
|
||||
" indent after block {{#block
|
||||
if line =~# '\v\s*\{\{\#.*\s*'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
" unindent after block close {{/block}}
|
||||
if cline =~# '\v^\s*\{\{\/\S*\}\}\s*'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
" unindent {{else}}
|
||||
if cline =~# '\v^\s*\{\{else.*\}\}\s*$'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
" indent again after {{else}}
|
||||
if line =~# '\v^\s*\{\{else.*\}\}\s*$'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
endif
|
||||
446
indent/haskell.vim
Normal file
446
indent/haskell.vim
Normal file
@@ -0,0 +1,446 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
" indentation for haskell
|
||||
"
|
||||
" author: raichoo (raichoo@googlemail.com)
|
||||
"
|
||||
" Modify g:haskell_indent_if and g:haskell_indent_case to
|
||||
" change indentation for `if'(default 3) and `case'(default 5).
|
||||
" Example (in .vimrc):
|
||||
" > let g:haskell_indent_if = 2
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:haskell_indent_if')
|
||||
" if x
|
||||
" >>>then ...
|
||||
" >>>else ...
|
||||
let g:haskell_indent_if = 3
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_case')
|
||||
" case xs of
|
||||
" >>[] -> ...
|
||||
" >>(y:ys) -> ...
|
||||
let g:haskell_indent_case = 2
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_let')
|
||||
" let x = 0 in
|
||||
" >>>>x
|
||||
let g:haskell_indent_let = 4
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_where')
|
||||
" where f :: Int -> Int
|
||||
" >>>>>>f x = x
|
||||
let g:haskell_indent_where = 6
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_do')
|
||||
" do x <- a
|
||||
" >>>y <- b
|
||||
let g:haskell_indent_do = 3
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_in')
|
||||
" let x = 1
|
||||
" >in x
|
||||
let g:haskell_indent_in = 1
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_guard')
|
||||
" f x y
|
||||
" >>|
|
||||
let g:haskell_indent_guard = 2
|
||||
endif
|
||||
|
||||
setlocal indentexpr=GetHaskellIndent()
|
||||
setlocal indentkeys=0{,0},0(,0),0[,0],!^F,o,O,0\=,0=where,0=let,0=deriving,0\,,<space>
|
||||
|
||||
function! s:isInBlock(hlstack)
|
||||
return index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1
|
||||
endfunction
|
||||
|
||||
function! s:getNesting(hlstack)
|
||||
return filter(a:hlstack, 'v:val == "haskellBlock" || v:val == "haskellBrackets" || v:val == "haskellParens"')
|
||||
endfunction
|
||||
|
||||
function! s:getHLStack()
|
||||
return map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
|
||||
endfunction
|
||||
|
||||
" indent matching character
|
||||
function! s:indentMatching(char)
|
||||
normal! 0
|
||||
call search(a:char, 'cW')
|
||||
normal! %
|
||||
return col('.') - 1
|
||||
endfunction
|
||||
|
||||
" backtrack to find guard clause
|
||||
function! s:indentGuard(pos, prevline)
|
||||
let l:l = a:prevline
|
||||
let l:c = 1
|
||||
|
||||
while v:lnum != l:c
|
||||
" empty line, stop looking
|
||||
if l:l =~ '^$'
|
||||
return a:pos
|
||||
" guard found
|
||||
elseif l:l =~ '^\s*|\s\+'
|
||||
return match(l:l, '|')
|
||||
" found less deeper indentation (not starting with `,` or `=`)
|
||||
" stop looking
|
||||
else
|
||||
let l:m = match(l:l, '\S')
|
||||
if l:l !~ '^\s*[=,]' && l:m <= a:pos
|
||||
return l:m + g:haskell_indent_guard
|
||||
endif
|
||||
endif
|
||||
let l:c += 1
|
||||
let l:l = getline(v:lnum - l:c)
|
||||
endwhile
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! GetHaskellIndent()
|
||||
let l:hlstack = s:getHLStack()
|
||||
|
||||
" do not indent in strings and quasiquotes
|
||||
if index(l:hlstack, 'haskellString') > -1 || index(l:hlstack, 'haskellQuasiQuote') > -1
|
||||
return -1
|
||||
endif
|
||||
|
||||
" blockcomment handling
|
||||
if index(l:hlstack, 'haskellBlockComment') > -1
|
||||
for l:c in range(v:lnum - 1, 0, -1)
|
||||
let l:line = getline(l:c)
|
||||
if l:line =~ '{-'
|
||||
return 1 + match(l:line, '{-')
|
||||
endif
|
||||
endfor
|
||||
return 1
|
||||
endif
|
||||
|
||||
let l:prevline = getline(v:lnum - 1)
|
||||
let l:line = getline(v:lnum)
|
||||
|
||||
" reset
|
||||
if l:prevline =~ '^\s*$' && l:line !~ '^\s*\S'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" comment indentation
|
||||
if l:prevline =~ '^\s*--'
|
||||
return match(l:prevline, '\S')
|
||||
endif
|
||||
|
||||
" operator at end of previous line
|
||||
if l:prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" let foo =
|
||||
" >>>>>>bar
|
||||
if l:prevline =~ '\C\<let\>\s\+[^=]\+=\s*$'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let + &shiftwidth
|
||||
endif
|
||||
|
||||
" let x = 1 in
|
||||
" >>>>x
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+\<in\>\?$' && l:line !~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let
|
||||
endif
|
||||
|
||||
" let x = 1
|
||||
" let y = 2
|
||||
"
|
||||
" let x = 1
|
||||
" >in x
|
||||
"
|
||||
" let x = 1
|
||||
" >>>>y = 2
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+$'
|
||||
if l:line =~ '\C^\s*\<let\>'
|
||||
return match(l:prevline, '\C\<let\>')
|
||||
elseif l:line =~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_in
|
||||
else
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let
|
||||
endif
|
||||
endif
|
||||
|
||||
" if handling
|
||||
if l:prevline !~ '\C\<else\>'
|
||||
let l:s = match(l:prevline, '\C\<if\>.*\&.*\zs\<then\>')
|
||||
if l:s > 0
|
||||
return l:s
|
||||
endif
|
||||
|
||||
let l:s = match(l:prevline, '\C\<if\>')
|
||||
if l:s > 0
|
||||
return l:s + g:haskell_indent_if
|
||||
endif
|
||||
endif
|
||||
|
||||
" where
|
||||
" >>foo
|
||||
"
|
||||
" do
|
||||
" >>foo
|
||||
"
|
||||
" foo =
|
||||
" >>bar
|
||||
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\)\s*$'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
"" where foo
|
||||
"" >>>>>>bar
|
||||
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
||||
if l:line =~ '^\s*[=-]>\s' && l:prevline =~ ' :: '
|
||||
return match(l:prevline, ':: ')
|
||||
else
|
||||
return match(l:prevline, '\C\<where\>') + g:haskell_indent_where
|
||||
endif
|
||||
endif
|
||||
|
||||
" do foo
|
||||
" >>>bar
|
||||
if l:prevline =~ '\C\<do\>\s\+\S\+.*$'
|
||||
return match(l:prevline, '\C\<do\>') + g:haskell_indent_do
|
||||
endif
|
||||
|
||||
" case foo of
|
||||
" >>bar -> quux
|
||||
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
|
||||
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
|
||||
endif
|
||||
|
||||
" newtype Foo = Foo
|
||||
" >>deriving
|
||||
if l:prevline =~ '\C\s*\<\(newtype\|data\)\>[^{]\+' && l:line =~ '\C^\s*\<deriving\>'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" foo :: Int
|
||||
" >>>>-> Int
|
||||
"
|
||||
" foo
|
||||
" :: Int
|
||||
" foo
|
||||
if l:prevline =~ '\s::\s'
|
||||
if l:line =~ '^\s*[-=]>'
|
||||
return match(l:prevline, '::\s')
|
||||
elseif match(l:prevline, '^\s\+::') > -1
|
||||
return match(l:prevline, '::\s') - &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
"
|
||||
" foo
|
||||
" :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
if l:prevline =~ '^\s*[-=]>' && l:line !~ '^\s*[-=]>'
|
||||
if s:isInBlock(l:hlstack)
|
||||
return match(l:prevline, '[^\s-=>]')
|
||||
else
|
||||
let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze')
|
||||
let l:l = l:prevline
|
||||
let l:c = 1
|
||||
|
||||
while v:lnum != l:c
|
||||
" fun decl
|
||||
let l:s = match(l:l, l:m)
|
||||
if l:s >= 0
|
||||
if match(l:l, '\C^\s*\<default\>') > -1
|
||||
return l:s - 8
|
||||
else
|
||||
return l:s
|
||||
endif
|
||||
" empty line, stop looking
|
||||
elseif l:l =~ '^$'
|
||||
return 0
|
||||
endif
|
||||
let l:c += 1
|
||||
let l:l = getline(v:lnum - l:c)
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
|
||||
" | otherwise = ...
|
||||
" foo
|
||||
"
|
||||
" | foo
|
||||
" >>, bar
|
||||
"
|
||||
" | foo
|
||||
" >>= bar
|
||||
"
|
||||
" | Foo
|
||||
" >>deriving
|
||||
if l:prevline =~ '^\s\+|' && !s:isInBlock(l:hlstack)
|
||||
if l:line =~ '\s*[,=]'
|
||||
return match(l:prevline, '|')
|
||||
elseif l:line =~ '\C^\s*\<deriving\>'
|
||||
return match(l:prevline, '|')
|
||||
elseif l:line !~ '^\s*|'
|
||||
return match(l:prevline, '|') - g:haskell_indent_guard
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo :: ( Monad m
|
||||
" , Functor f
|
||||
" )
|
||||
">>>>>=> Int
|
||||
if l:prevline =~ '^\s*)' && l:line =~ '^\s*=>'
|
||||
let l:s = match(l:prevline, ')')
|
||||
return l:s - (&shiftwidth + 1)
|
||||
endif
|
||||
|
||||
" module Foo
|
||||
" >>( bar
|
||||
if l:prevline =~ '\C^\<module\>'
|
||||
return &shiftwidth
|
||||
endif
|
||||
|
||||
" foo
|
||||
" >>{
|
||||
if l:line =~ '^\s*{' && l:prevline !~ '^{'
|
||||
let l:s = match(l:prevline, '\S')
|
||||
if l:s >= 0
|
||||
return l:s + &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
" in foo
|
||||
" where bar
|
||||
if l:line =~ '\C^\s*\<where\>'
|
||||
if match(l:prevline, '\C^\s\+in\s\+') == 0
|
||||
return match(l:prevline, 'in') - g:haskell_indent_in
|
||||
endif
|
||||
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" let x = 1
|
||||
" y = 2
|
||||
" >in x + 1
|
||||
if l:line =~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\S') - (4 - g:haskell_indent_in)
|
||||
endif
|
||||
|
||||
" data Foo
|
||||
" >>= Bar
|
||||
"
|
||||
" |
|
||||
" ...
|
||||
" >>=
|
||||
"
|
||||
" foo
|
||||
" >>=
|
||||
if l:line =~ '^\s*='
|
||||
if l:prevline =~ '\C^\<data\>\s\+[^=]\+\s*$'
|
||||
return match(l:prevline, '\C\<data\>') + &shiftwidth
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, '='), l:prevline)
|
||||
if l:s > 0
|
||||
return l:s
|
||||
else
|
||||
return &shiftwidth
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" { foo :: Int
|
||||
" >>,
|
||||
"
|
||||
" |
|
||||
" ...
|
||||
" >>,
|
||||
if l:line =~ '^\s*,'
|
||||
if s:isInBlock(l:hlstack)
|
||||
normal! 0
|
||||
call search(',', 'cW')
|
||||
let l:n = s:getNesting(s:getHLStack())
|
||||
call search('[(\[{]', 'bW')
|
||||
|
||||
while l:n != s:getNesting(s:getHLStack())
|
||||
call search('[(\[{]', 'bW')
|
||||
endwhile
|
||||
|
||||
return col('.') - 1
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, ','), l:prevline)
|
||||
if l:s > -1
|
||||
return l:s
|
||||
end
|
||||
endif
|
||||
endif
|
||||
|
||||
" |
|
||||
" ...
|
||||
" >>|
|
||||
"
|
||||
" data Foo = Bar
|
||||
" >>>>>>>>>|
|
||||
if l:line =~ '^\s*|\s'
|
||||
if l:prevline =~ '\C^\s*\<data\>.\+=.\+$'
|
||||
return match(l:prevline, '=')
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, '|'), l:prevline)
|
||||
if l:s > -1
|
||||
return l:s
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo
|
||||
" >>:: Int
|
||||
if l:line =~ '^\s*::\s'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" indent closing brace, paren or bracket
|
||||
if l:line =~ '^\s*}'
|
||||
return s:indentMatching('}')
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*)'
|
||||
return s:indentMatching(')')
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*]'
|
||||
return s:indentMatching(']')
|
||||
endif
|
||||
"
|
||||
" indent import
|
||||
if l:line =~ '\C^\s*import'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" do not reindent indented lines
|
||||
if match(l:prevline, '\S') < match(l:line, '\S')
|
||||
return -1
|
||||
endif
|
||||
|
||||
if l:line !~ '^\s*[=-]>\s' && l:line =~ '^\s*[!#$%&*+./<>?@\\^|~-]\+'
|
||||
return -1
|
||||
endif
|
||||
|
||||
return match(l:prevline, '\S')
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -177,7 +177,24 @@ call add(s:tags, 'tr')
|
||||
call add(s:tags, 'th')
|
||||
call add(s:tags, 'td')
|
||||
|
||||
let s:no_tags = []
|
||||
|
||||
call add(s:no_tags, 'base')
|
||||
call add(s:no_tags, 'link')
|
||||
call add(s:no_tags, 'meta')
|
||||
call add(s:no_tags, 'hr')
|
||||
call add(s:no_tags, 'br')
|
||||
call add(s:no_tags, 'wbr')
|
||||
call add(s:no_tags, 'img')
|
||||
call add(s:no_tags, 'embed')
|
||||
call add(s:no_tags, 'param')
|
||||
call add(s:no_tags, 'source')
|
||||
call add(s:no_tags, 'track')
|
||||
call add(s:no_tags, 'area')
|
||||
call add(s:no_tags, 'col')
|
||||
call add(s:no_tags, 'input')
|
||||
call add(s:no_tags, 'keygen')
|
||||
call add(s:no_tags, 'menuitem')
|
||||
|
||||
let s:omittable = [
|
||||
\ ['address', 'article', 'aside', 'blockquote', 'dir', 'div', 'dl', 'fieldset', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'],
|
||||
@@ -187,16 +204,21 @@ let s:omittable = [
|
||||
\ ['th', 'td'],
|
||||
\]
|
||||
|
||||
|
||||
let s:html_noindent_tags = join(s:no_tags, '\|')
|
||||
|
||||
if exists('g:html_exclude_tags')
|
||||
for tag in g:html_exclude_tags
|
||||
call remove(s:tags, index(s:tags, tag))
|
||||
endfor
|
||||
let s:html_noindent_tags = s:html_noindent_tags.'\|'.join(g:html_exclude_tags, '\|')
|
||||
endif
|
||||
let s:html_indent_tags = join(s:tags, '\|')
|
||||
let s:html_indent_tags = s:html_indent_tags.'\|\w\+\(-\w\+\)\+'
|
||||
if exists('g:html_indent_tags')
|
||||
let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
||||
endif
|
||||
|
||||
" let s:html_indent_tags = join(s:tags, '\|')
|
||||
let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
|
||||
" if exists('g:html_indent_tags')
|
||||
" let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
||||
" endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
@@ -231,8 +253,8 @@ endfun
|
||||
fun! <SID>HtmlIndentSum(lnum, style)
|
||||
if a:style == match(getline(a:lnum), '^\s*</')
|
||||
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
|
||||
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags)
|
||||
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags)
|
||||
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) - <SID>HtmlIndentOpen(a:lnum, s:html_noindent_tags)
|
||||
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
|
||||
if 0 != open || 0 != close
|
||||
return open - close
|
||||
endif
|
||||
|
||||
@@ -18,7 +18,7 @@ setlocal nosmartindent
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetJavascriptIndent()
|
||||
setlocal formatexpr=Fixedgq(v:lnum,v:count)
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
setlocal indentkeys=0{,0},0),0],0\,:,!^F,o,O,e
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetJavascriptIndent")
|
||||
@@ -28,13 +28,27 @@ endif
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Get shiftwidth value
|
||||
if exists('*shiftwidth')
|
||||
func s:sw()
|
||||
return shiftwidth()
|
||||
endfunc
|
||||
else
|
||||
func s:sw()
|
||||
return &sw
|
||||
endfunc
|
||||
endif
|
||||
|
||||
" 1. Variables {{{1
|
||||
" ============
|
||||
|
||||
let s:js_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
|
||||
|
||||
let s:js_keywords = '^\s*\(break\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
|
||||
let s:expr_case = '^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:syng_strcom = 'string\|regex\|comment\c'
|
||||
let s:syng_strcom = '\%(\%(template\)\@<!string\|regex\|comment\)\c'
|
||||
|
||||
" Regex of syntax group names that are or delimit template strings
|
||||
let s:syng_template = 'template\c'
|
||||
|
||||
" Regex of syntax group names that are strings.
|
||||
let s:syng_string = 'regex\c'
|
||||
@@ -51,25 +65,34 @@ let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_st
|
||||
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
|
||||
|
||||
" Regex that defines continuation lines, not including (, {, or [.
|
||||
let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term
|
||||
let s:continuation_regex = '\%([\\*/.:]\|+\@<!+\|-\@<!-\|\%(<%\)\@<!=\|\W[|&?]\|||\|&&\|[^=]=[^=>].*,\)' . s:line_term
|
||||
|
||||
" Regex that defines continuation lines.
|
||||
" TODO: this needs to deal with if ...: and so on
|
||||
let s:msl_regex = s:continuation_regex
|
||||
let s:msl_regex = s:continuation_regex.'\|'.s:expr_case
|
||||
|
||||
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
|
||||
let s:one_line_scope_regex = '\%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*([^()]*)[^()]*\))[^()]*\))[^()]*\))\)\|=>\)' . s:line_term
|
||||
|
||||
" Regex that defines blocks.
|
||||
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
||||
let s:block_regex = '\%([{([]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
||||
|
||||
let s:var_stmt = '^\s*var'
|
||||
let s:operator_first = '^\s*\%([*/.:?]\|\([-+]\)\1\@!\|||\|&&\)'
|
||||
|
||||
let s:var_stmt = '^\s*\%(const\|let\|var\)'
|
||||
|
||||
let s:comma_first = '^\s*,'
|
||||
let s:comma_last = ',\s*$'
|
||||
|
||||
let s:ternary = '^\s\+[?|:]'
|
||||
let s:ternary_q = '^\s\+?'
|
||||
|
||||
let s:case_indent = s:sw()
|
||||
let s:case_indent_after = s:sw()
|
||||
let s:m = matchlist(&cinoptions, ':\(.\)')
|
||||
if (len(s:m) > 2)
|
||||
let s:case_indent = s:m[1]
|
||||
endif
|
||||
let s:m = matchlist(&cinoptions, '=\(.\)')
|
||||
if (len(s:m) > 2)
|
||||
let s:case_indent_after = s:m[1]
|
||||
endif
|
||||
" 2. Auxiliary Functions {{{1
|
||||
" ======================
|
||||
|
||||
@@ -83,6 +106,11 @@ function s:IsInString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a template string.
|
||||
function s:IsInTempl(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_template
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a multi-line comment.
|
||||
function s:IsInMultilineComment(lnum, col)
|
||||
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
|
||||
@@ -101,13 +129,13 @@ function s:PrevNonBlankNonString(lnum)
|
||||
" Go in and out of blocks comments as necessary.
|
||||
" If the line isn't empty (with opt. comment) or in a string, end search.
|
||||
let line = getline(lnum)
|
||||
if line =~ '/\*'
|
||||
if s:IsInMultilineComment(lnum, matchend(line, '/\*') - 1)
|
||||
if in_block
|
||||
let in_block = 0
|
||||
else
|
||||
break
|
||||
endif
|
||||
elseif !in_block && line =~ '\*/'
|
||||
elseif !in_block && s:IsInMultilineComment(lnum, matchend(line, '\*/') - 1)
|
||||
let in_block = 1
|
||||
elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
|
||||
break
|
||||
@@ -127,9 +155,21 @@ function s:GetMSL(lnum, in_one_line_scope)
|
||||
" Otherwise, terminate search as we have found our MSL already.
|
||||
let line = getline(lnum)
|
||||
let col = match(line, s:msl_regex) + 1
|
||||
let line2 = getline(msl)
|
||||
let col2 = matchend(line2, ')')
|
||||
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
|
||||
let msl = lnum
|
||||
|
||||
" if there are more closing brackets, continue from the line which has the matching opening bracket
|
||||
elseif col2 > 0 && !s:IsInStringOrComment(msl, col2) && s:LineHasOpeningBrackets(msl)[0] == '2' && !a:in_one_line_scope
|
||||
call cursor(msl, 1)
|
||||
if searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
let lnum = line('.')
|
||||
let msl = lnum
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
" Don't use lines that are part of a one line scope as msl unless the
|
||||
" flag in_one_line_scope is set to 1
|
||||
"
|
||||
@@ -140,7 +180,7 @@ function s:GetMSL(lnum, in_one_line_scope)
|
||||
if msl_one_line == 0
|
||||
break
|
||||
endif
|
||||
endif
|
||||
end
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
return msl
|
||||
@@ -193,9 +233,9 @@ function s:GetVarIndent(lnum)
|
||||
|
||||
" if the previous line doesn't end in a comma, return to regular indent
|
||||
if (line !~ s:comma_last)
|
||||
return indent(prev_lnum) - &sw
|
||||
return indent(prev_lnum) - s:sw()
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
return indent(lvar) + s:sw()
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -221,7 +261,7 @@ function s:LineHasOpeningBrackets(lnum)
|
||||
endif
|
||||
let pos = match(line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
|
||||
return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0) . (open_4 > 0)
|
||||
endfunction
|
||||
|
||||
function s:Match(lnum, regex)
|
||||
@@ -302,6 +342,17 @@ function GetJavascriptIndent()
|
||||
" previous nonblank line number
|
||||
let prevline = prevnonblank(v:lnum - 1)
|
||||
|
||||
if (line =~ s:expr_case)
|
||||
if (getline(prevline) =~ s:expr_case)
|
||||
return indent(prevline)
|
||||
else
|
||||
if (getline(prevline) =~ s:block_regex)
|
||||
return indent(prevline) + s:case_indent
|
||||
else
|
||||
return indent(prevline) - s:case_indent_after
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
" If we got a closing bracket on an empty line, find its match and indent
|
||||
" according to it. For parentheses we indent to its column - 1, for the
|
||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||
@@ -323,7 +374,7 @@ function GetJavascriptIndent()
|
||||
return indent(prevline)
|
||||
" otherwise we indent 1 level
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
return indent(lvar) + s:sw()
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -342,15 +393,51 @@ function GetJavascriptIndent()
|
||||
|
||||
" If the line is comma first, dedent 1 level
|
||||
if (getline(prevline) =~ s:comma_first)
|
||||
return indent(prevline) - &sw
|
||||
return indent(prevline) - s:sw()
|
||||
endif
|
||||
if (getline(prevline) =~ s:expr_case)
|
||||
return indent(prevline) + s:case_indent_after
|
||||
endif
|
||||
|
||||
if (line =~ s:ternary)
|
||||
if (getline(prevline) =~ s:ternary_q)
|
||||
" If line starts with an operator...
|
||||
if (s:Match(v:lnum, s:operator_first))
|
||||
if (s:Match(prevline, s:operator_first))
|
||||
" and so does previous line, don't indent
|
||||
return indent(prevline)
|
||||
else
|
||||
return indent(prevline) + &sw
|
||||
end
|
||||
let counts = s:LineHasOpeningBrackets(prevline)
|
||||
if counts[0] == '2'
|
||||
call cursor(prevline, 1)
|
||||
" Search for the opening tag
|
||||
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
|
||||
if mnum > 0 && s:Match(mnum, s:operator_first)
|
||||
return indent(mnum)
|
||||
end
|
||||
elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
|
||||
" otherwise, indent 1 level
|
||||
return indent(prevline) + s:sw()
|
||||
end
|
||||
" If previous line starts with an operator...
|
||||
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last) && !s:Match(prevline, '};\=' . s:line_term)
|
||||
let counts = s:LineHasOpeningBrackets(prevline)
|
||||
if counts[0] == '2' && counts[1] == '1'
|
||||
call cursor(prevline, 1)
|
||||
" Search for the opening tag
|
||||
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
|
||||
if mnum > 0 && !s:Match(mnum, s:operator_first)
|
||||
return indent(mnum) + s:sw()
|
||||
end
|
||||
elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
|
||||
return indent(prevline) - s:sw()
|
||||
end
|
||||
end
|
||||
|
||||
if getline(prevline) =~ '^\s*`$' && s:IsInTempl(v:lnum, 1)
|
||||
if line !~ '^\s*`$'
|
||||
return indent(prevline) + s:sw()
|
||||
endif
|
||||
elseif line =~ '^\s*`$' && s:IsInTempl(prevline, 1)
|
||||
return indent(prevline) - s:sw()
|
||||
endif
|
||||
|
||||
" If we are in a multi-line comment, cindent does the right thing.
|
||||
@@ -387,48 +474,71 @@ function GetJavascriptIndent()
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Set up variables for current line.
|
||||
let line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" If the previous line ended with a block opening, add a level of indent.
|
||||
if s:Match(lnum, s:block_regex)
|
||||
return indent(s:GetMSL(lnum, 0)) + &sw
|
||||
if (line =~ s:expr_case)
|
||||
return indent(s:GetMSL(lnum, 0)) + s:sw()/2
|
||||
else
|
||||
return indent(s:GetMSL(lnum, 0)) + s:sw()
|
||||
endif
|
||||
endif
|
||||
|
||||
" Set up variables for current line.
|
||||
let line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
" If the previous line contained an opening bracket, and we are still in it,
|
||||
" add indent depending on the bracket type.
|
||||
if line =~ '[[({]'
|
||||
let counts = s:LineHasOpeningBrackets(lnum)
|
||||
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
if col('.') + 1 == col('$')
|
||||
return ind + &sw
|
||||
if col('.') + 1 == col('$') || line =~ s:one_line_scope_regex
|
||||
return ind + s:sw()
|
||||
else
|
||||
return virtcol('.')
|
||||
endif
|
||||
elseif counts[1] == '1' || counts[2] == '1'
|
||||
return ind + &sw
|
||||
elseif counts[1] == '1' || counts[2] == '1' && counts[0] != '2'
|
||||
return ind + s:sw()
|
||||
else
|
||||
call cursor(v:lnum, vcol)
|
||||
end
|
||||
endif
|
||||
elseif line =~ '.\+};\=' . s:line_term
|
||||
call cursor(lnum, 1)
|
||||
" Search for the opening tag
|
||||
let mnum = searchpair('{', '', '}', 'bW', s:skip_expr)
|
||||
if mnum > 0
|
||||
return indent(s:GetMSL(mnum, 0))
|
||||
end
|
||||
elseif line =~ '.\+);\=' || line =~ s:comma_last
|
||||
let counts = s:LineHasOpeningBrackets(lnum)
|
||||
if counts[0] == '2'
|
||||
call cursor(lnum, 1)
|
||||
" Search for the opening tag
|
||||
let mnum = searchpair('(', '', ')', 'bW', s:skip_expr)
|
||||
if mnum > 0
|
||||
return indent(s:GetMSL(mnum, 0))
|
||||
end
|
||||
elseif line !~ s:var_stmt
|
||||
return indent(prevline)
|
||||
end
|
||||
end
|
||||
|
||||
" 3.4. Work on the MSL line. {{{2
|
||||
" --------------------------
|
||||
|
||||
let ind_con = ind
|
||||
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
|
||||
let ind = s:IndentWithContinuation(lnum, ind_con, s:sw())
|
||||
|
||||
" }}}2
|
||||
"
|
||||
"
|
||||
let ols = s:InOneLineScope(lnum)
|
||||
if ols > 0
|
||||
let ind = ind + &sw
|
||||
let ind = ind + s:sw()
|
||||
else
|
||||
let ols = s:ExitingOneLineScope(lnum)
|
||||
while ols > 0 && ind > 0
|
||||
let ind = ind - &sw
|
||||
let ind = ind - s:sw()
|
||||
let ols = s:InOneLineScope(ols - 1)
|
||||
endwhile
|
||||
endif
|
||||
|
||||
@@ -56,10 +56,11 @@ function! GetLiquidIndent(...)
|
||||
let line = substitute(line,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
||||
let line .= matchstr(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+')
|
||||
let cline = substitute(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
||||
let ind += &sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
|
||||
let ind -= &sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
||||
let ind -= &sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
||||
let ind -= &sw * s:count(cline,'{%\s*end\w*$')
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let ind += sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
|
||||
let ind -= sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
||||
let ind -= sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
||||
let ind -= sw * s:count(cline,'{%\s*end\w*$')
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
|
||||
358
indent/mako.vim
Normal file
358
indent/mako.vim
Normal file
@@ -0,0 +1,358 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mako') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Mako
|
||||
" Author: Scott Torborg <storborg@mit.edu>
|
||||
" Version: 0.4
|
||||
" License: Do What The Fuck You Want To Public License (WTFPL)
|
||||
"
|
||||
" ---------------------------------------------------------------------------
|
||||
"
|
||||
" DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
" Version 2, December 2004
|
||||
"
|
||||
" Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
"
|
||||
" Everyone is permitted to copy and distribute verbatim or modified
|
||||
" copies of this license document, and changing it is allowed as long
|
||||
" as the name is changed.
|
||||
"
|
||||
" DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
"
|
||||
" 0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
"
|
||||
" ---------------------------------------------------------------------------
|
||||
"
|
||||
" This script does more useful indenting for Mako HTML templates. It indents
|
||||
" inside of control blocks, defs, etc. Note that this indenting style will
|
||||
" sacrifice readability of the output text for the sake of readability of the
|
||||
" template.
|
||||
"
|
||||
" We'll use HTML indenting globally, python inside <% %> blocks. Inspired by
|
||||
" the excellent PHP + HTML indentation files such as php.vim by Pim Snel.
|
||||
"
|
||||
" Changelog:
|
||||
" 0.4 - 5 March 2010
|
||||
" - Added license information
|
||||
" 0.3 - 15 September 2009
|
||||
" - Added explicit indenting for ## comments, fixed unindenting count,
|
||||
" thanks to Mike Lewis (@MikeRLewis) for this
|
||||
" 0.2 - 15 June 2009
|
||||
" - Fixed issue where opening and closing mako tags on the same line
|
||||
" would cause incorrect indenting
|
||||
" 0.1 - 06 June 2009
|
||||
" - Initial public release of mako indent file
|
||||
|
||||
let sw=2 " default shiftwidth of 2 spaces
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal nosmartindent
|
||||
setlocal noautoindent
|
||||
setlocal nocindent
|
||||
setlocal nolisp
|
||||
|
||||
setlocal indentexpr=GetMakoIndent()
|
||||
setlocal indentkeys+=*<Return>,<>>,<bs>,end,:
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetMakoIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
if exists('g:html_indent_tags')
|
||||
unlet g:html_indent_tags
|
||||
endif
|
||||
|
||||
function IsInsidePythonBlock(startline)
|
||||
" Loop until we get a line that's either <% or %>
|
||||
let lnum = a:startline
|
||||
while getline(lnum) !~ '\(%>\|<%\)$' && lnum > 0
|
||||
let lnum = lnum - 1
|
||||
endwhile
|
||||
|
||||
" lnum points to the last control. If it's a <% then we're inside an
|
||||
" embedded python block, otherwise we're not.
|
||||
return getline(lnum) =~ '<%$'
|
||||
endfunction
|
||||
|
||||
function GetMakoIndent()
|
||||
" Find a non-empty line above the current line
|
||||
let lnum = prevnonblank(v:lnum - 1)
|
||||
|
||||
" Hit the start of the file, use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let line = getline(lnum) " last line
|
||||
let cline = getline(v:lnum) " current line
|
||||
let pline = getline(lnum - 1) " previous to last line
|
||||
let ind = indent(lnum)
|
||||
if line =~ '^\s*##'
|
||||
return indent(lnum)
|
||||
end
|
||||
|
||||
let restore_ic=&ic
|
||||
let &ic=1 " ignore case
|
||||
|
||||
let ind = <SID>HtmlIndentSum(lnum, -1)
|
||||
let ind = <SID>HtmlIndentSum(lnum, -1)
|
||||
let ind = ind + <SID>HtmlIndentSum(v:lnum, 0)
|
||||
|
||||
let &ic=restore_ic
|
||||
|
||||
let ind = indent(lnum) + (&sw * ind)
|
||||
|
||||
" Indent after %anything: or <%anything NOT ending in />
|
||||
if line =~ '^\s*%.*:\s*$'
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
|
||||
" Unindent before %end* or </%anything
|
||||
if cline =~ '^\s*%\s*end'
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
"
|
||||
" Unindent before %else, %except, and %elif
|
||||
if cline =~ '^\s*%\s*else' || cline =~ '^\s*%\s*except' || cline =~ '^\s*%\s*elif'
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
|
||||
" Indent at the beginning of a python control block
|
||||
if line =~ '<%$'
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
"
|
||||
" Unindent at the end of the python block.
|
||||
if cline =~ '^\s*%>$'
|
||||
let scanlnum = lnum
|
||||
" Scan backwards until we find the beginning of this python block.
|
||||
while getline(scanlnum) !~ '<%$' && scanlnum > 0
|
||||
let scanlnum = scanlnum - 1
|
||||
endwhile
|
||||
let ind = indent(scanlnum)
|
||||
endif
|
||||
|
||||
" If we're inside a python block and the previous line ends in a colon,
|
||||
" indent.
|
||||
if IsInsidePythonBlock(lnum - 1)
|
||||
" Indent after :
|
||||
if line =~ '\:$'
|
||||
let ind = ind + &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
|
||||
" [-- helper function to assemble tag list --]
|
||||
fun! <SID>HtmlIndentPush(tag)
|
||||
if exists('g:html_indent_tags')
|
||||
let g:html_indent_tags = g:html_indent_tags.'\|'.a:tag
|
||||
else
|
||||
let g:html_indent_tags = a:tag
|
||||
endif
|
||||
endfun
|
||||
|
||||
fun! <SID>MakoIndentPush(tag)
|
||||
if exists('g:mako_indent_tags')
|
||||
let g:mako_indent_tags = g:mako_indent_tags.'\|'.a:tag
|
||||
else
|
||||
let g:mako_indent_tags = a:tag
|
||||
endif
|
||||
endfun
|
||||
|
||||
" [-- <ELEMENT ? - - ...> --]
|
||||
call <SID>HtmlIndentPush('a')
|
||||
call <SID>HtmlIndentPush('abbr')
|
||||
call <SID>HtmlIndentPush('acronym')
|
||||
call <SID>HtmlIndentPush('address')
|
||||
call <SID>HtmlIndentPush('b')
|
||||
call <SID>HtmlIndentPush('bdo')
|
||||
call <SID>HtmlIndentPush('big')
|
||||
call <SID>HtmlIndentPush('blockquote')
|
||||
call <SID>HtmlIndentPush('button')
|
||||
call <SID>HtmlIndentPush('caption')
|
||||
call <SID>HtmlIndentPush('center')
|
||||
call <SID>HtmlIndentPush('cite')
|
||||
call <SID>HtmlIndentPush('code')
|
||||
call <SID>HtmlIndentPush('colgroup')
|
||||
call <SID>HtmlIndentPush('del')
|
||||
call <SID>HtmlIndentPush('dfn')
|
||||
call <SID>HtmlIndentPush('dir')
|
||||
call <SID>HtmlIndentPush('div')
|
||||
call <SID>HtmlIndentPush('dl')
|
||||
call <SID>HtmlIndentPush('em')
|
||||
call <SID>HtmlIndentPush('fieldset')
|
||||
call <SID>HtmlIndentPush('font')
|
||||
call <SID>HtmlIndentPush('form')
|
||||
call <SID>HtmlIndentPush('frameset')
|
||||
call <SID>HtmlIndentPush('h1')
|
||||
call <SID>HtmlIndentPush('h2')
|
||||
call <SID>HtmlIndentPush('h3')
|
||||
call <SID>HtmlIndentPush('h4')
|
||||
call <SID>HtmlIndentPush('h5')
|
||||
call <SID>HtmlIndentPush('h6')
|
||||
call <SID>HtmlIndentPush('i')
|
||||
call <SID>HtmlIndentPush('iframe')
|
||||
call <SID>HtmlIndentPush('ins')
|
||||
call <SID>HtmlIndentPush('kbd')
|
||||
call <SID>HtmlIndentPush('label')
|
||||
call <SID>HtmlIndentPush('legend')
|
||||
call <SID>HtmlIndentPush('map')
|
||||
call <SID>HtmlIndentPush('menu')
|
||||
call <SID>HtmlIndentPush('noframes')
|
||||
call <SID>HtmlIndentPush('noscript')
|
||||
call <SID>HtmlIndentPush('object')
|
||||
call <SID>HtmlIndentPush('ol')
|
||||
call <SID>HtmlIndentPush('optgroup')
|
||||
call <SID>HtmlIndentPush('pre')
|
||||
call <SID>HtmlIndentPush('q')
|
||||
call <SID>HtmlIndentPush('s')
|
||||
call <SID>HtmlIndentPush('samp')
|
||||
call <SID>HtmlIndentPush('script')
|
||||
call <SID>HtmlIndentPush('select')
|
||||
call <SID>HtmlIndentPush('small')
|
||||
call <SID>HtmlIndentPush('span')
|
||||
call <SID>HtmlIndentPush('strong')
|
||||
call <SID>HtmlIndentPush('style')
|
||||
call <SID>HtmlIndentPush('sub')
|
||||
call <SID>HtmlIndentPush('sup')
|
||||
call <SID>HtmlIndentPush('table')
|
||||
call <SID>HtmlIndentPush('textarea')
|
||||
call <SID>HtmlIndentPush('title')
|
||||
call <SID>HtmlIndentPush('tt')
|
||||
call <SID>HtmlIndentPush('u')
|
||||
call <SID>HtmlIndentPush('ul')
|
||||
call <SID>HtmlIndentPush('var')
|
||||
|
||||
" For some reason the default HTML indentation script doesn't consider these
|
||||
" elements to be worthy of indentation.
|
||||
call <SID>HtmlIndentPush('p')
|
||||
call <SID>HtmlIndentPush('dt')
|
||||
call <SID>HtmlIndentPush('dd')
|
||||
|
||||
|
||||
" [-- <ELEMENT ? O O ...> --]
|
||||
if !exists('g:html_indent_strict')
|
||||
call <SID>HtmlIndentPush('body')
|
||||
call <SID>HtmlIndentPush('head')
|
||||
call <SID>HtmlIndentPush('html')
|
||||
call <SID>HtmlIndentPush('tbody')
|
||||
endif
|
||||
|
||||
|
||||
" [-- <ELEMENT ? O - ...> --]
|
||||
if !exists('g:html_indent_strict_table')
|
||||
call <SID>HtmlIndentPush('th')
|
||||
call <SID>HtmlIndentPush('td')
|
||||
call <SID>HtmlIndentPush('tr')
|
||||
call <SID>HtmlIndentPush('tfoot')
|
||||
call <SID>HtmlIndentPush('thead')
|
||||
endif
|
||||
|
||||
" [-- <Mako Elements> --]
|
||||
call <SID>MakoIndentPush('%def')
|
||||
call <SID>MakoIndentPush('%block')
|
||||
call <SID>MakoIndentPush('%call')
|
||||
call <SID>MakoIndentPush('%doc')
|
||||
call <SID>MakoIndentPush('%text')
|
||||
call <SID>MakoIndentPush('%.\+:.\+')
|
||||
|
||||
delfun <SID>HtmlIndentPush
|
||||
delfun <SID>MakoIndentPush
|
||||
|
||||
set cpo-=C
|
||||
|
||||
" [-- get number of regex matches in a string --]
|
||||
fun! <SID>MatchCount(expr, pat)
|
||||
let mpos = 0
|
||||
let mcount = 0
|
||||
let expr = a:expr
|
||||
while (mpos > -1)
|
||||
let mend = matchend(expr, a:pat)
|
||||
if mend > -1
|
||||
let mcount = mcount + 1
|
||||
endif
|
||||
if mend == mpos
|
||||
let mpos = mpos + 1
|
||||
else
|
||||
let mpos = mend
|
||||
endif
|
||||
let expr = strpart(expr, mpos)
|
||||
endwhile
|
||||
return mcount
|
||||
endfun
|
||||
|
||||
" [-- count indent-increasing tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentOpen(lnum)
|
||||
let s = substitute('x'.getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)\('.g:html_indent_tags.'\)\>\)', "\1", 'g')
|
||||
let s = substitute(s, "[^\1].*$", '', '')
|
||||
return strlen(s)
|
||||
endfun
|
||||
|
||||
" [-- count indent-decreasing tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentClose(lnum)
|
||||
let s = substitute('x'.getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)/\('.g:html_indent_tags.'\)\>>\)', "\1", 'g')
|
||||
let s = substitute(s, "[^\1].*$", '', '')
|
||||
return strlen(s)
|
||||
endfun
|
||||
|
||||
" [-- count indent-increasing mako tags of line a:lnum --]
|
||||
fun! <SID>MakoIndentOpen(lnum)
|
||||
let s = substitute('x'.getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)\('.g:mako_indent_tags.'\)\>\)', "\1", 'g')
|
||||
let s = substitute(s, "[^\1].*$", '', '')
|
||||
return strlen(s)
|
||||
endfun
|
||||
|
||||
" [-- count indent-decreasing mako tags of line a:lnum --]
|
||||
fun! <SID>MakoIndentClose(lnum)
|
||||
let mcount = <SID>MatchCount(getline(a:lnum), '</\('.g:mako_indent_tags.'\)>')
|
||||
let mcount = mcount + <SID>MatchCount(getline(a:lnum), '<\('.g:mako_indent_tags.'\)[^>]*/>')
|
||||
return mcount
|
||||
endfun
|
||||
|
||||
" [-- count indent-increasing '{' of (java|css) line a:lnum --]
|
||||
fun! <SID>HtmlIndentOpenAlt(lnum)
|
||||
return strlen(substitute(getline(a:lnum), '[^{]\+', '', 'g'))
|
||||
endfun
|
||||
|
||||
" [-- count indent-decreasing '}' of (java|css) line a:lnum --]
|
||||
fun! <SID>HtmlIndentCloseAlt(lnum)
|
||||
return strlen(substitute(getline(a:lnum), '[^}]\+', '', 'g'))
|
||||
endfun
|
||||
|
||||
" [-- return the sum of indents respecting the syntax of a:lnum --]
|
||||
fun! <SID>HtmlIndentSum(lnum, style)
|
||||
let open = <SID>HtmlIndentOpen(a:lnum) + <SID>MakoIndentOpen(a:lnum)
|
||||
let close = <SID>HtmlIndentClose(a:lnum) + <SID>MakoIndentClose(a:lnum)
|
||||
if a:style == match(getline(a:lnum), '^\s*</')
|
||||
if a:style == match(getline(a:lnum), '^\s*</\('.g:html_indent_tags.'\|'.g:mako_indent_tags.'\)')
|
||||
if 0 != open || 0 != close
|
||||
return open - close
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if '' != &syntax &&
|
||||
\ synIDattr(synID(a:lnum, 1, 1), 'name') =~ '\(css\|java\).*' &&
|
||||
\ synIDattr(synID(a:lnum, strlen(getline(a:lnum)) - 1, 1), 'name')
|
||||
\ =~ '\(css\|java\).*'
|
||||
if a:style == match(getline(a:lnum), '^\s*}')
|
||||
return <SID>HtmlIndentOpenAlt(a:lnum) - <SID>HtmlIndentCloseAlt(a:lnum)
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfun
|
||||
|
||||
" vim: set ts=4 sw=4:
|
||||
|
||||
endif
|
||||
15
indent/nginx.vim
Normal file
15
indent/nginx.vim
Normal file
@@ -0,0 +1,15 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nginx') == -1
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=
|
||||
|
||||
" cindent actually works for nginx' simple file structure
|
||||
setlocal cindent
|
||||
" Just make sure that the comments are not reset as defs would be.
|
||||
setlocal cinkeys-=0#
|
||||
|
||||
endif
|
||||
146
indent/nim.vim
Normal file
146
indent/nim.vim
Normal file
@@ -0,0 +1,146 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
" Some preliminary settings
|
||||
setlocal nolisp " Make sure lisp indenting doesn't supersede us
|
||||
setlocal autoindent " indentexpr isn't much help otherwise
|
||||
|
||||
setlocal indentexpr=GetNimIndent(v:lnum)
|
||||
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetNimIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:FindStartLine(fromln, pattern)
|
||||
let lnum = a:fromln
|
||||
let safechoice = indent(lnum)
|
||||
while getline(lnum) !~ a:pattern
|
||||
if indent(lnum) == 0 || lnum == 1
|
||||
return safechoice
|
||||
endif
|
||||
let lnum = lnum - 1
|
||||
endwhile
|
||||
return indent(lnum)
|
||||
endfunction
|
||||
|
||||
function! GetNimIndent(lnum)
|
||||
" Search backwards for the previous non-empty line.
|
||||
let plnum = prevnonblank(a:lnum - 1)
|
||||
|
||||
if plnum == 0
|
||||
" This is the first non-empty line, use zero indent.
|
||||
return 0
|
||||
endif
|
||||
|
||||
" If the start of the line is in a string don't change the indent.
|
||||
if has('syntax_items') && synIDattr(synID(a:lnum, 1, 1), "name") =~ "String$"
|
||||
return -1
|
||||
endif
|
||||
|
||||
let pline = getline(plnum)
|
||||
let cline = getline(a:lnum)
|
||||
let pline_len = strlen(pline)
|
||||
let plindent = indent(plnum)
|
||||
let clindent = indent(a:lnum)
|
||||
|
||||
" Remove any trailing comment from previous line.
|
||||
" Use syntax highlighting attributes when possible.
|
||||
if has('syntax_items')
|
||||
" If the last character in the line is a comment, do a binary search for
|
||||
" the start of the comment. synID() is slow, a linear search would take
|
||||
" too long on a long line.
|
||||
if synIDattr(synID(plnum, pline_len, 1), "name") =~ "Comment$"
|
||||
let min = 1
|
||||
let max = pline_len
|
||||
while min < max
|
||||
let col = (min + max) / 2
|
||||
if synIDattr(synID(plnum, col, 1), "name") =~ "Comment$"
|
||||
let max = col
|
||||
else
|
||||
let min = col + 1
|
||||
endif
|
||||
endwhile
|
||||
let pline = strpart(pline, 0, min - 1)
|
||||
endif
|
||||
else
|
||||
let col = 0
|
||||
while col < pline_len
|
||||
if pline[col] == '#'
|
||||
let pline = strpart(pline, 0, col)
|
||||
break
|
||||
endif
|
||||
let col = col + 1
|
||||
endwhile
|
||||
endif
|
||||
|
||||
if cline =~ '^\s*\(if\|when\|for\|while\|case\|of\|try\)\>'
|
||||
" This is a benign line, do nothing
|
||||
return -1
|
||||
endif
|
||||
|
||||
" If the current line begins with a keyword that lines up with "try"
|
||||
if cline =~ '^\s*\(except\|finally\)\>'
|
||||
let lnum = a:lnum - 1
|
||||
while lnum >= 1
|
||||
if getline(lnum) =~ '^\s*\(try\|except\)\>'
|
||||
let ind = indent(lnum)
|
||||
if ind >= clindent
|
||||
return -1 " indent is already less than this
|
||||
endif
|
||||
return ind " line up with previous try or except
|
||||
endif
|
||||
let lnum = lnum - 1
|
||||
endwhile
|
||||
return -1 " no matching "try"!
|
||||
endif
|
||||
|
||||
" If the current line begins with a header keyword, dedent
|
||||
if cline =~ '^\s*\(elif\|else\)\>'
|
||||
return s:FindStartLine(a:lnum, '^\s*\(if\|when\|elif\|of\)')
|
||||
endif
|
||||
|
||||
if pline =~ ':\s*$'
|
||||
"return s:FindStartLine(plnum, '(^\s*\(if\|when\|else\|elif\|case\|of\|try\|except\|finally\)\>)\|\<do\>') + &sw
|
||||
return s:FindStartLine(plnum, '^\s*\(if\|when\|else\|elif\|for\|while\|case\|of\|try\|except\|finally\)\>') + &sw
|
||||
endif
|
||||
|
||||
if pline =~ '=\s*$'
|
||||
return s:FindStartLine(plnum, '^\s*\(proc\|template\|macro\|iterator\)\>') + &sw
|
||||
endif
|
||||
|
||||
" if we got here, this should be the begging of a multi-line if expression for example
|
||||
if pline =~ '^\s*\(if\|when\|proc\|iterator\|macro\|template\|for\|while\)[^:]*$'
|
||||
return plindent + &sw
|
||||
endif
|
||||
|
||||
if pline =~ '\(type\|import\|const\|var\)\s*$'
|
||||
\ || pline =~ '=\s*\(object\|enum\|tuple\|generic\)'
|
||||
return plindent + &sw
|
||||
endif
|
||||
|
||||
" If the previous line was a stop-execution statement...
|
||||
if pline =~ '^\s*\(break\|continue\|raise\|return\)\>'
|
||||
" See if the user has already dedented
|
||||
if indent(a:lnum) > plindent - &sw
|
||||
" If not, recommend one dedent
|
||||
return plindent - &sw
|
||||
endif
|
||||
" Otherwise, trust the user
|
||||
return -1
|
||||
endif
|
||||
|
||||
return -1
|
||||
|
||||
endfunction
|
||||
|
||||
" vim:sw=2
|
||||
|
||||
|
||||
endif
|
||||
@@ -1,9 +1,9 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jade') == -1
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'pug') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Jade
|
||||
" Language: Pug
|
||||
" Maintainer: Joshua Borton
|
||||
" Credits: Tim Pope (vim-jade)
|
||||
" Credits: Tim Pope (vim-pug)
|
||||
" Last Change: 2010 Sep 22
|
||||
|
||||
if exists("b:did_indent")
|
||||
@@ -14,25 +14,25 @@ unlet! b:did_indent
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetJadeIndent()
|
||||
setlocal indentexpr=GetPugIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetJadeIndent")
|
||||
if exists("*GetPugIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:attributes = '\%((.\{-\})\)'
|
||||
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
||||
|
||||
if !exists('g:jade_self_closing_tags')
|
||||
let g:jade_self_closing_tags = 'meta|link|img|hr|br|input'
|
||||
if !exists('g:pug_self_closing_tags')
|
||||
let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
|
||||
endif
|
||||
|
||||
setlocal formatoptions+=r
|
||||
setlocal comments+=n:\|
|
||||
|
||||
function! GetJadeIndent()
|
||||
function! GetPugIndent()
|
||||
let lnum = prevnonblank(v:lnum-1)
|
||||
if lnum == 0
|
||||
return 0
|
||||
@@ -60,9 +60,9 @@ function! GetJadeIndent()
|
||||
return increase
|
||||
elseif line == '-#'
|
||||
return increase
|
||||
elseif line =~? '^\v%('.g:jade_self_closing_tags.')>'
|
||||
elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
|
||||
return indent
|
||||
elseif group =~? '\v^%(jadeAttributesDelimiter|jadeClass|jadeId|htmlTagName|htmlSpecialTagName|jadeFilter|jadeTagBlockChar)$'
|
||||
elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
|
||||
return increase
|
||||
else
|
||||
return indent
|
||||
@@ -53,11 +53,7 @@ function! GetPuppetIndent()
|
||||
let pline = getline(pnum)
|
||||
let ind = indent(pnum)
|
||||
|
||||
if pline =~ '^\s*#'
|
||||
return ind
|
||||
endif
|
||||
|
||||
if pline =~ '\({\|\[\|(\|:\)$'
|
||||
if pline =~ '\({\|\[\|(\|:\)\s*\(#.*\)\?$'
|
||||
let ind += &sw
|
||||
elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
|
||||
let ind -= &sw
|
||||
|
||||
141
indent/purescript.vim
Normal file
141
indent/purescript.vim
Normal file
@@ -0,0 +1,141 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1
|
||||
|
||||
" indentation for purescript
|
||||
"
|
||||
" Based on idris indentation
|
||||
"
|
||||
" author: raichoo (raichoo@googlemail.com)
|
||||
"
|
||||
" Modify g:purescript_indent_if and g:purescript_indent_case to
|
||||
" change indentation for `if'(default 3) and `case'(default 5).
|
||||
" Example (in .vimrc):
|
||||
" > let g:purescript_indent_if = 2
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:purescript_indent_if')
|
||||
" if bool
|
||||
" >>>then ...
|
||||
" >>>else ...
|
||||
let g:purescript_indent_if = 3
|
||||
endif
|
||||
|
||||
if !exists('g:purescript_indent_case')
|
||||
" case xs of
|
||||
" >>>>>[] -> ...
|
||||
" >>>>>(y:ys) -> ...
|
||||
let g:purescript_indent_case = 5
|
||||
endif
|
||||
|
||||
if !exists('g:purescript_indent_let')
|
||||
" let x = 0 in
|
||||
" >>>>x
|
||||
let g:purescript_indent_let = 4
|
||||
endif
|
||||
|
||||
if !exists('g:purescript_indent_where')
|
||||
" where f :: Int -> Int
|
||||
" >>>>>>f x = x
|
||||
let g:purescript_indent_where = 6
|
||||
endif
|
||||
|
||||
if !exists('g:purescript_indent_do')
|
||||
" do x <- a
|
||||
" >>>y <- b
|
||||
let g:purescript_indent_do = 3
|
||||
endif
|
||||
|
||||
setlocal indentexpr=GetPurescriptIndent()
|
||||
setlocal indentkeys=!^F,o,O,},=where,=in
|
||||
|
||||
function! GetPurescriptIndent()
|
||||
let prevline = getline(v:lnum - 1)
|
||||
let line = getline(v:lnum)
|
||||
|
||||
if line =~ '^\s*\<where\>'
|
||||
let s = match(prevline, '\S')
|
||||
return s + 2
|
||||
endif
|
||||
|
||||
if line =~ '^\s*\<in\>'
|
||||
let n = v:lnum
|
||||
let s = 0
|
||||
|
||||
while s <= 0 && n > 0
|
||||
let n = n - 1
|
||||
let s = match(getline(n),'\<let\>')
|
||||
endwhile
|
||||
|
||||
return s + 1
|
||||
endif
|
||||
|
||||
if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
|
||||
let s = match(prevline, '=')
|
||||
if s > 0
|
||||
return s + 2
|
||||
endif
|
||||
|
||||
let s = match(prevline, ':')
|
||||
if s > 0
|
||||
return s + 3
|
||||
else
|
||||
return match(prevline, '\S')
|
||||
endif
|
||||
endif
|
||||
|
||||
if prevline =~ '[{([][^})\]]\+$'
|
||||
return match(prevline, '[{([]')
|
||||
endif
|
||||
|
||||
if prevline =~ '\<let\>\s\+.\+\(\<in\>\)\?\s*$'
|
||||
return match(prevline, '\<let\>') + g:purescript_indent_let
|
||||
endif
|
||||
|
||||
if prevline !~ '\<else\>'
|
||||
let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
|
||||
if s > 0
|
||||
return s
|
||||
endif
|
||||
|
||||
let s = match(prevline, '\<if\>')
|
||||
if s > 0
|
||||
return s + g:purescript_indent_if
|
||||
endif
|
||||
endif
|
||||
|
||||
if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
|
||||
return match(prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
if prevline =~ '\<where\>\s\+\S\+.*$'
|
||||
return match(prevline, '\<where\>') + g:purescript_indent_where
|
||||
endif
|
||||
|
||||
if prevline =~ '\<do\>\s\+\S\+.*$'
|
||||
return match(prevline, '\<do\>') + g:purescript_indent_do
|
||||
endif
|
||||
|
||||
if prevline =~ '^\s*\<data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
|
||||
return match(prevline, '=')
|
||||
endif
|
||||
|
||||
if prevline =~ '\<case\>\s\+.\+\<of\>\s*$'
|
||||
return match(prevline, '\<case\>') + g:purescript_indent_case
|
||||
endif
|
||||
|
||||
if prevline =~ '^\s*\<\data\>\s\+\S\+\s*$'
|
||||
return match(prevline, '\<data\>') + &shiftwidth
|
||||
endif
|
||||
|
||||
if (line =~ '^\s*}\s*' && prevline !~ '^\s*;')
|
||||
return match(prevline, '\S') - &shiftwidth
|
||||
endif
|
||||
|
||||
return match(prevline, '\S')
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -125,7 +125,7 @@ let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=
|
||||
" The reason is that the pipe matches a hanging "|" operator.
|
||||
"
|
||||
let s:block_regex =
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$'
|
||||
|
||||
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
|
||||
|
||||
|
||||
@@ -123,6 +123,13 @@ function GetRustIndent(lnum)
|
||||
let prevlinenum = prevnonblank(prevlinenum - 1)
|
||||
let prevline = s:get_line_trimmed(prevlinenum)
|
||||
endwhile
|
||||
|
||||
" Handle where clauses nicely: subsequent values should line up nicely.
|
||||
if prevline[len(prevline) - 1] == ","
|
||||
\ && prevline =~# '^\s*where\s'
|
||||
return indent(prevlinenum) + 6
|
||||
endif
|
||||
|
||||
if prevline[len(prevline) - 1] == ","
|
||||
\ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
|
||||
\ && prevline !~ '^\s*fn\s'
|
||||
|
||||
@@ -31,9 +31,7 @@ function! GetSassIndent()
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
if line !~ s:property && line !~ s:extend && cline =~ s:property
|
||||
return indent + &sw
|
||||
"elseif line =~ s:property && cline !~ s:property
|
||||
"return indent - &sw
|
||||
return indent + (exists('*shiftwidth') ? shiftwidth() : &sw)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
|
||||
@@ -119,7 +119,7 @@ function! GetStylusIndent()
|
||||
|
||||
" if group !~? 'css.*' && line =~? ')\s*$' " match user functions
|
||||
" return increase
|
||||
if group =~? '\v^%(cssTagName|cssClassName|cssIdentifier|cssSelectorOp|cssSelectorOp2|cssBraces|cssAttributeSelector|cssPseudoClass|cssPseudoClassId|stylusId|stylusClass)$'
|
||||
if group =~? '\v^%(cssTagName|cssClassName|cssIdentifier|cssSelectorOp|cssSelectorOp2|cssBraces|cssAttributeSelector|cssPseudo|stylusId|stylusClass)$'
|
||||
return increase
|
||||
elseif (group == 'stylusUserFunction') && (indent(lnum) == '0') " mixin definition
|
||||
return increase
|
||||
|
||||
241
indent/swift.vim
241
indent/swift.vim
@@ -1,19 +1,242 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'swift') == -1
|
||||
|
||||
" Language: Swift<https://developer.apple.com/swift/>
|
||||
" Maintainer: toyama satoshi <toyamarinyon@gmail.com>
|
||||
" URL: http://github.com/toyamarinyon/vim-swift
|
||||
" License: GPL
|
||||
" File: swift.vim
|
||||
" Author: Keith Smiley
|
||||
" Description: The indent file for Swift
|
||||
" Last Modified: December 05, 2014
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
" C indenting is built-in, thus this is very simple
|
||||
setlocal cindent
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let b:undo_indent = "setl cin<"
|
||||
setlocal nosmartindent
|
||||
setlocal indentkeys-=e
|
||||
setlocal indentkeys+=0]
|
||||
setlocal indentexpr=SwiftIndent()
|
||||
|
||||
function! s:NumberOfMatches(char, string, index)
|
||||
let instances = 0
|
||||
let i = 0
|
||||
while i < strlen(a:string)
|
||||
if a:string[i] == a:char && !s:IsExcludedFromIndentAtPosition(a:index, i + 1)
|
||||
let instances += 1
|
||||
endif
|
||||
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
return instances
|
||||
endfunction
|
||||
|
||||
function! s:SyntaxNameAtPosition(line, column)
|
||||
return synIDattr(synID(a:line, a:column, 0), "name")
|
||||
endfunction
|
||||
|
||||
function! s:SyntaxName()
|
||||
return s:SyntaxNameAtPosition(line("."), col("."))
|
||||
endfunction
|
||||
|
||||
function! s:IsExcludedFromIndentAtPosition(line, column)
|
||||
let name = s:SyntaxNameAtPosition(a:line, a:column)
|
||||
return name ==# "swiftComment" || name ==# "swiftString"
|
||||
endfunction
|
||||
|
||||
function! s:IsExcludedFromIndent()
|
||||
return s:SyntaxName() ==# "swiftComment" || s:SyntaxName() ==# "swiftString"
|
||||
endfunction
|
||||
|
||||
function! s:IsCommentLine(lnum)
|
||||
return synIDattr(synID(a:lnum,
|
||||
\ match(getline(a:lnum), "\S") + 1, 0), "name")
|
||||
\ ==# "swiftComment"
|
||||
endfunction
|
||||
|
||||
function! SwiftIndent(...)
|
||||
let clnum = a:0 ? a:1 : v:lnum
|
||||
|
||||
let line = getline(clnum)
|
||||
let previousNum = prevnonblank(clnum - 1)
|
||||
while s:IsCommentLine(previousNum) != 0
|
||||
let previousNum = prevnonblank(previousNum - 1)
|
||||
endwhile
|
||||
|
||||
let previous = getline(previousNum)
|
||||
let cindent = cindent(clnum)
|
||||
let previousIndent = indent(previousNum)
|
||||
|
||||
let numOpenParens = s:NumberOfMatches("(", previous, previousNum)
|
||||
let numCloseParens = s:NumberOfMatches(")", previous, previousNum)
|
||||
let numOpenBrackets = s:NumberOfMatches("{", previous, previousNum)
|
||||
let numCloseBrackets = s:NumberOfMatches("}", previous, previousNum)
|
||||
|
||||
let currentOpenBrackets = s:NumberOfMatches("{", line, clnum)
|
||||
let currentCloseBrackets = s:NumberOfMatches("}", line, clnum)
|
||||
|
||||
let numOpenSquare = s:NumberOfMatches("[", previous, previousNum)
|
||||
let numCloseSquare = s:NumberOfMatches("]", previous, previousNum)
|
||||
|
||||
let currentCloseSquare = s:NumberOfMatches("]", line, clnum)
|
||||
if numOpenSquare > numCloseSquare && currentCloseSquare < 1
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if currentCloseSquare > 0 && line !~ '\v\[.*\]'
|
||||
let column = col(".")
|
||||
call cursor(line("."), 1)
|
||||
let openingSquare = searchpair("\\[", "", "\\]", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
|
||||
if openingSquare == 0
|
||||
return -1
|
||||
endif
|
||||
|
||||
" - Line starts with closing square, indent as opening square
|
||||
if line =~ '\v^\s*]'
|
||||
return indent(openingSquare)
|
||||
endif
|
||||
|
||||
" - Line contains closing square and more, indent a level above opening
|
||||
return indent(openingSquare) + shiftwidth()
|
||||
endif
|
||||
|
||||
if line =~ ":$"
|
||||
let switch = search("switch", "bWn")
|
||||
return indent(switch)
|
||||
elseif previous =~ ":$"
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if numOpenParens == numCloseParens
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
if currentCloseBrackets > currentOpenBrackets || line =~ "\\v^\\s*}"
|
||||
let column = col(".")
|
||||
call cursor(line("."), 1)
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
if openingBracket == 0
|
||||
return -1
|
||||
else
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
endif
|
||||
|
||||
return previousIndent + shiftwidth()
|
||||
elseif previous =~ "}.*{"
|
||||
if line =~ "\\v^\\s*}"
|
||||
return previousIndent
|
||||
endif
|
||||
|
||||
return previousIndent + shiftwidth()
|
||||
elseif line =~ "}.*{"
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
return indent(openingBracket)
|
||||
elseif currentCloseBrackets > currentOpenBrackets
|
||||
let column = col(".")
|
||||
call cursor(line("."), 1)
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line("."), column)
|
||||
|
||||
let bracketLine = getline(openingBracket)
|
||||
|
||||
let numOpenParensBracketLine = s:NumberOfMatches("(", bracketLine, openingBracket)
|
||||
let numCloseParensBracketLine = s:NumberOfMatches(")", bracketLine, openingBracket)
|
||||
if numCloseParensBracketLine > numOpenParensBracketLine
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(openingParen, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
endif
|
||||
return indent(openingBracket)
|
||||
else
|
||||
" - Current line is blank, and the user presses 'o'
|
||||
return previousIndent
|
||||
endif
|
||||
endif
|
||||
|
||||
if numCloseParens > 0
|
||||
if currentOpenBrackets > 0 || currentCloseBrackets > 0
|
||||
if currentOpenBrackets > 0
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
if line =~ "}.*{"
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
|
||||
if numCloseParens > numOpenParens
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(line - 1, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen)
|
||||
endif
|
||||
|
||||
return previousIndent
|
||||
endif
|
||||
|
||||
if currentCloseBrackets > 0
|
||||
let openingBracket = searchpair("{", "", "}", "bWn", "s:IsExcludedFromIndent()")
|
||||
return indent(openingBracket)
|
||||
endif
|
||||
|
||||
return cindent
|
||||
endif
|
||||
|
||||
if numCloseParens < numOpenParens
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let previousParen = match(previous, "(")
|
||||
return indent(previousParen) + shiftwidth()
|
||||
endif
|
||||
|
||||
if numOpenBrackets > numCloseBrackets
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
return indent(openingParen) + shiftwidth()
|
||||
endif
|
||||
|
||||
" - Previous line has close then open braces, indent previous + 1 'sw'
|
||||
if previous =~ "}.*{"
|
||||
return previousIndent + shiftwidth()
|
||||
endif
|
||||
|
||||
let line = line(".")
|
||||
let column = col(".")
|
||||
call cursor(previousNum, column)
|
||||
let openingParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call cursor(line, column)
|
||||
|
||||
return indent(openingParen)
|
||||
endif
|
||||
|
||||
" - Line above has (unmatched) open paren, next line needs indent
|
||||
if numOpenParens > 0
|
||||
let savePosition = getcurpos()
|
||||
" Must be at EOL because open paren has to be above (left of) the cursor
|
||||
call cursor(previousNum, col("$"))
|
||||
let previousParen = searchpair("(", "", ")", "bWn", "s:IsExcludedFromIndent()")
|
||||
call setpos(".", savePosition)
|
||||
return indent(previousParen) + shiftwidth()
|
||||
endif
|
||||
|
||||
return cindent
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,105 +1,505 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'typescript') == -1
|
||||
|
||||
" Vim indent file, taken from indent/java.vim
|
||||
" Language: Typescript
|
||||
" Maintainer: None! Wanna improve this?
|
||||
" Last Change: 2015 Mar 07
|
||||
" Vim indent file
|
||||
" Language: Typescript
|
||||
" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org
|
||||
|
||||
if get(g:, 'typescript_indent_disable')
|
||||
finish
|
||||
endif
|
||||
" 0. Initialization {{{1
|
||||
" =================
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
" Use javascript cindent options
|
||||
setlocal cindent cinoptions& cinoptions+=j1,J1
|
||||
setlocal indentkeys&
|
||||
setlocal nosmartindent
|
||||
|
||||
" Load typescript indent function
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetTypescriptIndent()
|
||||
setlocal formatexpr=Fixedgq(v:lnum,v:count)
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
|
||||
let b:undo_indent = "setl cin< cino< indentkeys< indentexpr<"
|
||||
|
||||
" Only define the function once
|
||||
" Only define the function once.
|
||||
if exists("*GetTypescriptIndent")
|
||||
finish
|
||||
finish
|
||||
endif
|
||||
|
||||
" Make sure we have vim capabilities
|
||||
let s:keepcpo = &cpo
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! TypescriptPrevNonBlankOrComment(lnum)
|
||||
let pnum = prevnonblank(a:lnum)
|
||||
" skip any comments (either `//`, `/*` or `*`)
|
||||
while getline(pnum) =~ '^\s*\(\/\/\|\/\*\|\*\)'
|
||||
let pnum = prevnonblank(pnum-1)
|
||||
endwhile
|
||||
return pnum
|
||||
" 1. Variables {{{1
|
||||
" ============
|
||||
|
||||
let s:ts_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
|
||||
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:syng_strcom = 'string\|regex\|comment\c'
|
||||
|
||||
" Regex of syntax group names that are strings.
|
||||
let s:syng_string = 'regex\c'
|
||||
|
||||
" Regex of syntax group names that are strings or documentation.
|
||||
let s:syng_multiline = 'comment\c'
|
||||
|
||||
" Regex of syntax group names that are line comment.
|
||||
let s:syng_linecom = 'linecomment\c'
|
||||
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
|
||||
|
||||
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
|
||||
|
||||
" Regex that defines continuation lines, not including (, {, or [.
|
||||
let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term
|
||||
|
||||
" Regex that defines continuation lines.
|
||||
" TODO: this needs to deal with if ...: and so on
|
||||
let s:msl_regex = s:continuation_regex
|
||||
|
||||
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
|
||||
|
||||
" Regex that defines blocks.
|
||||
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
||||
|
||||
let s:var_stmt = '^\s*var'
|
||||
|
||||
let s:comma_first = '^\s*,'
|
||||
let s:comma_last = ',\s*$'
|
||||
|
||||
let s:ternary = '^\s\+[?|:]'
|
||||
let s:ternary_q = '^\s\+?'
|
||||
|
||||
" 2. Auxiliary Functions {{{1
|
||||
" ======================
|
||||
|
||||
" Check if the character at lnum:col is inside a string, comment, or is ascii.
|
||||
function s:IsInStringOrComment(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string.
|
||||
function s:IsInString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a multi-line comment.
|
||||
function s:IsInMultilineComment(lnum, col)
|
||||
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is a line comment.
|
||||
function s:IsLineComment(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
||||
function s:PrevNonBlankNonString(lnum)
|
||||
let in_block = 0
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
while lnum > 0
|
||||
" Go in and out of blocks comments as necessary.
|
||||
" If the line isn't empty (with opt. comment) or in a string, end search.
|
||||
let line = getline(lnum)
|
||||
if line =~ '/\*'
|
||||
if in_block
|
||||
let in_block = 0
|
||||
else
|
||||
break
|
||||
endif
|
||||
elseif !in_block && line =~ '\*/'
|
||||
let in_block = 1
|
||||
elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
|
||||
function s:GetMSL(lnum, in_one_line_scope)
|
||||
" Start on the line we're at and use its indent.
|
||||
let msl = a:lnum
|
||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
while lnum > 0
|
||||
" If we have a continuation line, or we're in a string, use line as MSL.
|
||||
" Otherwise, terminate search as we have found our MSL already.
|
||||
let line = getline(lnum)
|
||||
let col = match(line, s:msl_regex) + 1
|
||||
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
|
||||
let msl = lnum
|
||||
else
|
||||
" Don't use lines that are part of a one line scope as msl unless the
|
||||
" flag in_one_line_scope is set to 1
|
||||
"
|
||||
if a:in_one_line_scope
|
||||
break
|
||||
end
|
||||
let msl_one_line = s:Match(lnum, s:one_line_scope_regex)
|
||||
if msl_one_line == 0
|
||||
break
|
||||
endif
|
||||
endif
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
return msl
|
||||
endfunction
|
||||
|
||||
function s:RemoveTrailingComments(content)
|
||||
let single = '\/\/\(.*\)\s*$'
|
||||
let multi = '\/\*\(.*\)\*\/\s*$'
|
||||
return substitute(substitute(a:content, single, '', ''), multi, '', '')
|
||||
endfunction
|
||||
|
||||
" Find if the string is inside var statement (but not the first string)
|
||||
function s:InMultiVarStatement(lnum)
|
||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
|
||||
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
|
||||
|
||||
" loop through previous expressions to find a var statement
|
||||
while lnum > 0
|
||||
let line = getline(lnum)
|
||||
|
||||
" if the line is a ts keyword
|
||||
if (line =~ s:ts_keywords)
|
||||
" check if the line is a var stmt
|
||||
" if the line has a comma first or comma last then we can assume that we
|
||||
" are in a multiple var statement
|
||||
if (line =~ s:var_stmt)
|
||||
return lnum
|
||||
endif
|
||||
|
||||
" other ts keywords, not a var
|
||||
return 0
|
||||
endif
|
||||
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
|
||||
" beginning of program, not a var
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Find line above with beginning of the var statement or returns 0 if it's not
|
||||
" this statement
|
||||
function s:GetVarIndent(lnum)
|
||||
let lvar = s:InMultiVarStatement(a:lnum)
|
||||
let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
|
||||
if lvar
|
||||
let line = s:RemoveTrailingComments(getline(prev_lnum))
|
||||
|
||||
" if the previous line doesn't end in a comma, return to regular indent
|
||||
if (line !~ s:comma_last)
|
||||
return indent(prev_lnum) - &sw
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
|
||||
" Check if line 'lnum' has more opening brackets than closing ones.
|
||||
function s:LineHasOpeningBrackets(lnum)
|
||||
let open_0 = 0
|
||||
let open_2 = 0
|
||||
let open_4 = 0
|
||||
let line = getline(a:lnum)
|
||||
let pos = match(line, '[][(){}]', 0)
|
||||
while pos != -1
|
||||
if !s:IsInStringOrComment(a:lnum, pos + 1)
|
||||
let idx = stridx('(){}[]', line[pos])
|
||||
if idx % 2 == 0
|
||||
let open_{idx} = open_{idx} + 1
|
||||
else
|
||||
let open_{idx - 1} = open_{idx - 1} - 1
|
||||
endif
|
||||
endif
|
||||
let pos = match(line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
|
||||
endfunction
|
||||
|
||||
function s:Match(lnum, regex)
|
||||
let col = match(getline(a:lnum), a:regex) + 1
|
||||
return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
|
||||
endfunction
|
||||
|
||||
function s:IndentWithContinuation(lnum, ind, width)
|
||||
" Set up variables to use and search for MSL to the previous line.
|
||||
let p_lnum = a:lnum
|
||||
let lnum = s:GetMSL(a:lnum, 1)
|
||||
let line = getline(lnum)
|
||||
|
||||
" If the previous line wasn't a MSL and is continuation return its indent.
|
||||
" TODO: the || s:IsInString() thing worries me a bit.
|
||||
if p_lnum != lnum
|
||||
if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
|
||||
return a:ind
|
||||
endif
|
||||
endif
|
||||
|
||||
" Set up more variables now that we know we aren't continuation bound.
|
||||
let msl_ind = indent(lnum)
|
||||
|
||||
" If the previous line ended with [*+/.-=], start a continuation that
|
||||
" indents an extra level.
|
||||
if s:Match(lnum, s:continuation_regex)
|
||||
if lnum == p_lnum
|
||||
return msl_ind + a:width
|
||||
else
|
||||
return msl_ind
|
||||
endif
|
||||
endif
|
||||
|
||||
return a:ind
|
||||
endfunction
|
||||
|
||||
function s:InOneLineScope(lnum)
|
||||
let msl = s:GetMSL(a:lnum, 1)
|
||||
if msl > 0 && s:Match(msl, s:one_line_scope_regex)
|
||||
return msl
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function s:ExitingOneLineScope(lnum)
|
||||
let msl = s:GetMSL(a:lnum, 1)
|
||||
if msl > 0
|
||||
" if the current line is in a one line scope ..
|
||||
if s:Match(msl, s:one_line_scope_regex)
|
||||
return 0
|
||||
else
|
||||
let prev_msl = s:GetMSL(msl - 1, 1)
|
||||
if s:Match(prev_msl, s:one_line_scope_regex)
|
||||
return prev_msl
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" 3. GetTypescriptIndent Function {{{1
|
||||
" =========================
|
||||
|
||||
function GetTypescriptIndent()
|
||||
" 3.1. Setup {{{2
|
||||
" ----------
|
||||
|
||||
" default value: trust cindent
|
||||
let ind = cindent(v:lnum)
|
||||
" Set up variables for restoring position in file. Could use v:lnum here.
|
||||
let vcol = col('.')
|
||||
|
||||
if getline(v:lnum) =~ '^\s*[{}\*]'
|
||||
return ind
|
||||
endif
|
||||
" 3.2. Work on the current line {{{2
|
||||
" -----------------------------
|
||||
|
||||
" The last non-empty line
|
||||
let prev = TypescriptPrevNonBlankOrComment(v:lnum-1)
|
||||
let ind = -1
|
||||
" Get the current line.
|
||||
let line = getline(v:lnum)
|
||||
" previous nonblank line number
|
||||
let prevline = prevnonblank(v:lnum - 1)
|
||||
|
||||
" Check if the previous line consists of a single `<variable> : <type>;`
|
||||
" declaration (e.g. in interface definitions)
|
||||
if getline(prev) =~ '^\s*\w\+\s*:[^{]\+;\s*$'
|
||||
return indent(prev)
|
||||
endif
|
||||
" If we got a closing bracket on an empty line, find its match and indent
|
||||
" according to it. For parentheses we indent to its column - 1, for the
|
||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||
let col = matchend(line, '^\s*[],})]')
|
||||
if col > 0 && !s:IsInStringOrComment(v:lnum, col)
|
||||
call cursor(v:lnum, col)
|
||||
|
||||
" If the previous line starts with '@', we should have the same indent as
|
||||
" the previous one
|
||||
if getline(prev) =~ '^\s*@\S\+\s*$'
|
||||
return indent(prev)
|
||||
endif
|
||||
let lvar = s:InMultiVarStatement(v:lnum)
|
||||
if lvar
|
||||
let prevline_contents = s:RemoveTrailingComments(getline(prevline))
|
||||
|
||||
" If a var, let, or const was declared and the semicolon omitted, do not
|
||||
" indent the next line
|
||||
if getline(prev) =~ '^\s*\(var\|let\|const\)\s\+\w\+'
|
||||
return indent(prev)
|
||||
endif
|
||||
|
||||
" If the line ended with a ',', we should have the same indent as
|
||||
" the previous one
|
||||
if getline(prev) =~ ',\s*$'
|
||||
return indent(prev)
|
||||
endif
|
||||
|
||||
" Try to find out whether the last `}` ended a `<variable> : {` block
|
||||
if getline(prev) =~ '};\s*$'
|
||||
" jump to matching `{` bracket
|
||||
call cursor(prev, 1)
|
||||
silent normal %
|
||||
|
||||
" See if current line is type annotation without closing ';' but open
|
||||
" `{` bracket
|
||||
let lnum = line('.')
|
||||
if getline(lnum) =~ '^\s*\w\+\s*:[^;]\+{'
|
||||
let ind = indent(lnum)
|
||||
" check for comma first
|
||||
if (line[col - 1] =~ ',')
|
||||
" if the previous line ends in comma or semicolon don't indent
|
||||
if (prevline_contents =~ '[;,]\s*$')
|
||||
return indent(s:GetMSL(line('.'), 0))
|
||||
" get previous line indent, if it's comma first return prevline indent
|
||||
elseif (prevline_contents =~ s:comma_first)
|
||||
return indent(prevline)
|
||||
" otherwise we indent 1 level
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
|
||||
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
|
||||
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
||||
if line[col-1]==')' && col('.') != col('$') - 1
|
||||
let ind = virtcol('.')-1
|
||||
else
|
||||
let ind = indent(s:GetMSL(line('.'), 0))
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If the line is comma first, dedent 1 level
|
||||
if (getline(prevline) =~ s:comma_first)
|
||||
return indent(prevline) - &sw
|
||||
endif
|
||||
|
||||
if (line =~ s:ternary)
|
||||
if (getline(prevline) =~ s:ternary_q)
|
||||
return indent(prevline)
|
||||
else
|
||||
return indent(prevline) + &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
" If we are in a multi-line comment, cindent does the right thing.
|
||||
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
|
||||
return cindent(v:lnum)
|
||||
endif
|
||||
|
||||
" Check for multiple var assignments
|
||||
" let var_indent = s:GetVarIndent(v:lnum)
|
||||
" if var_indent >= 0
|
||||
" return var_indent
|
||||
" endif
|
||||
|
||||
" 3.3. Work on the previous line. {{{2
|
||||
" -------------------------------
|
||||
|
||||
" If the line is empty and the previous nonblank line was a multi-line
|
||||
" comment, use that comment's indent. Deduct one char to account for the
|
||||
" space in ' */'.
|
||||
if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1)
|
||||
return indent(prevline) - 1
|
||||
endif
|
||||
|
||||
" Find a non-blank, non-multi-line string line above the current line.
|
||||
let lnum = s:PrevNonBlankNonString(v:lnum - 1)
|
||||
|
||||
" If the line is empty and inside a string, use the previous line.
|
||||
if line =~ '^\s*$' && lnum != prevline
|
||||
return indent(prevnonblank(v:lnum))
|
||||
endif
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Set up variables for current line.
|
||||
let line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" If the previous line ended with a block opening, add a level of indent.
|
||||
if s:Match(lnum, s:block_regex)
|
||||
return indent(s:GetMSL(lnum, 0)) + &sw
|
||||
endif
|
||||
|
||||
" If the previous line contained an opening bracket, and we are still in it,
|
||||
" add indent depending on the bracket type.
|
||||
if line =~ '[[({]'
|
||||
let counts = s:LineHasOpeningBrackets(lnum)
|
||||
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
if col('.') + 1 == col('$')
|
||||
return ind + &sw
|
||||
else
|
||||
return virtcol('.')
|
||||
endif
|
||||
elseif counts[1] == '1' || counts[2] == '1'
|
||||
return ind + &sw
|
||||
else
|
||||
call cursor(v:lnum, vcol)
|
||||
end
|
||||
endif
|
||||
|
||||
" 3.4. Work on the MSL line. {{{2
|
||||
" --------------------------
|
||||
|
||||
let ind_con = ind
|
||||
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
|
||||
|
||||
" }}}2
|
||||
"
|
||||
"
|
||||
let ols = s:InOneLineScope(lnum)
|
||||
if ols > 0
|
||||
let ind = ind + &sw
|
||||
else
|
||||
let ols = s:ExitingOneLineScope(lnum)
|
||||
while ols > 0 && ind > 0
|
||||
let ind = ind - &sw
|
||||
let ols = s:InOneLineScope(ols - 1)
|
||||
endwhile
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" Restore compatibility mode
|
||||
let &cpo = s:keepcpo
|
||||
unlet s:keepcpo
|
||||
" }}}1
|
||||
|
||||
" vim: et
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
function! Fixedgq(lnum, count)
|
||||
let l:tw = &tw ? &tw : 80;
|
||||
|
||||
let l:count = a:count
|
||||
let l:first_char = indent(a:lnum) + 1
|
||||
|
||||
if mode() == 'i' " gq was not pressed, but tw was set
|
||||
return 1
|
||||
endif
|
||||
|
||||
" This gq is only meant to do code with strings, not comments
|
||||
if s:IsLineComment(a:lnum, l:first_char) || s:IsInMultilineComment(a:lnum, l:first_char)
|
||||
return 1
|
||||
endif
|
||||
|
||||
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Put all the lines on one line and do normal spliting after that
|
||||
if l:count > 1
|
||||
while l:count > 1
|
||||
let l:count -= 1
|
||||
normal J
|
||||
endwhile
|
||||
endif
|
||||
|
||||
let l:winview = winsaveview()
|
||||
|
||||
call cursor(a:lnum, l:tw + 1)
|
||||
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
|
||||
call cursor(a:lnum, l:tw + 1)
|
||||
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
|
||||
|
||||
" No need for special treatment, normal gq handles edgecases better
|
||||
if breakpoint[1] == orig_breakpoint[1]
|
||||
call winrestview(l:winview)
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Try breaking after string
|
||||
if breakpoint[1] <= indent(a:lnum)
|
||||
call cursor(a:lnum, l:tw + 1)
|
||||
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
|
||||
endif
|
||||
|
||||
|
||||
if breakpoint[1] != 0
|
||||
call feedkeys("r\<CR>")
|
||||
else
|
||||
let l:count = l:count - 1
|
||||
endif
|
||||
|
||||
" run gq on new lines
|
||||
if l:count == 1
|
||||
call feedkeys("gqq")
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
96
syntax/ansible.vim
Normal file
96
syntax/ansible.vim
Normal file
@@ -0,0 +1,96 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
" Vim syntax file
|
||||
" Language: Ansible YAML/Jinja templates
|
||||
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
|
||||
" Last Change: 2015.09.06
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists("main_syntax")
|
||||
let main_syntax = 'yaml'
|
||||
endif
|
||||
|
||||
let b:current_syntax = ''
|
||||
unlet b:current_syntax
|
||||
runtime! syntax/yaml.vim
|
||||
|
||||
let b:current_syntax = ''
|
||||
unlet b:current_syntax
|
||||
syntax include @Yaml syntax/yaml.vim
|
||||
|
||||
let b:current_syntax = ''
|
||||
unlet b:current_syntax
|
||||
syntax include @Jinja syntax/jinja2.vim
|
||||
|
||||
" Jinja
|
||||
" ================================
|
||||
|
||||
syn cluster jinjaSLSBlocks add=jinjaTagBlock,jinjaVarBlock,jinjaComment
|
||||
" https://github.com/mitsuhiko/jinja2/blob/6b7c0c23/ext/Vim/jinja.vim
|
||||
syn region jinjaTagBlock matchgroup=jinjaTagDelim start=/{%-\?/ end=/-\?%}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks
|
||||
syn region jinjaVarBlock matchgroup=jinjaVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaRaw,jinjaString,jinjaNested,jinjaComment,@jinjaSLSBlocks
|
||||
syn region jinjaComment matchgroup=jinjaCommentDelim start="{#" end="#}" containedin=ALLBUT,jinjaTagBlock,jinjaVarBlock,jinjaString,@jinjaSLSBlocks
|
||||
highlight link jinjaVariable Constant
|
||||
highlight link jinjaVarDelim Delimiter
|
||||
|
||||
" YAML
|
||||
" ================================
|
||||
|
||||
" Reset some YAML to plain styling
|
||||
" the number 80 in Ansible isn't any more important than the word root
|
||||
highlight link yamlInteger NONE
|
||||
highlight link yamlBool NONE
|
||||
highlight link yamlFlowString NONE
|
||||
" but it does make sense we visualize quotes easily
|
||||
highlight link yamlFlowStringDelimiter Delimiter
|
||||
|
||||
fun! s:attribute_highlight(attributes)
|
||||
if a:attributes =~ 'a'
|
||||
syn match ansible_attributes "\v\w+\=" containedin=yamlPlainScalar
|
||||
else
|
||||
syn match ansible_attributes "\v^\s*\w+\=" containedin=yamlPlainScalar
|
||||
endif
|
||||
if a:attributes =~ 'n'
|
||||
highlight link ansible_attributes NONE
|
||||
elseif a:attributes =~ 'd'
|
||||
highlight link ansible_attributes Comment
|
||||
else
|
||||
highlight link ansible_attributes Structure
|
||||
endif
|
||||
endfun
|
||||
|
||||
if exists("g:ansible_attribute_highlight")
|
||||
call s:attribute_highlight(g:ansible_attribute_highlight)
|
||||
else
|
||||
call s:attribute_highlight('ad')
|
||||
endif
|
||||
|
||||
if exists("g:ansible_name_highlight")
|
||||
syn keyword ansible_name name containedin=yamlBlockMappingKey contained
|
||||
if g:ansible_name_highlight =~ 'd'
|
||||
highlight link ansible_name Comment
|
||||
else
|
||||
highlight link ansible_name Underlined
|
||||
endif
|
||||
endif
|
||||
|
||||
syn keyword ansible_debug_keywords debug containedin=yamlBlockMappingKey contained
|
||||
highlight link ansible_debug_keywords Debug
|
||||
|
||||
if exists("g:ansible_extra_keywords_highlight")
|
||||
syn keyword ansible_extra_special_keywords register always_run changed_when failed_when no_log args vars delegate_to ignore_errors containedin=yamlBlockMappingKey contained
|
||||
highlight link ansible_extra_special_keywords Statement
|
||||
endif
|
||||
|
||||
syn keyword ansible_special_keywords include until retries delay when only_if become become_user block rescue always notify containedin=yamlBlockMappingKey contained
|
||||
highlight link ansible_special_keywords Statement
|
||||
|
||||
syn match ansible_with_keywords "\vwith_.+" containedin=yamlBlockMappingKey contained
|
||||
highlight link ansible_with_keywords Statement
|
||||
|
||||
let b:current_syntax = "ansible"
|
||||
|
||||
endif
|
||||
35
syntax/ansible_hosts.vim
Normal file
35
syntax/ansible_hosts.vim
Normal file
@@ -0,0 +1,35 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
||||
|
||||
" Vim syntax file
|
||||
" Language: Ansible hosts files
|
||||
" Maintainer: Dave Honneffer <pearofducks@gmail.com>
|
||||
" Last Change: 2015.09.23
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn case ignore
|
||||
syn match hostsFirstWord "\v^\S+"
|
||||
syn match hostsAttributes "\v\S*\="
|
||||
syn region hostsHeader start="\v^\s*\[" end="\v\]"
|
||||
syn keyword hostsHeaderSpecials children vars containedin=hostsHeader contained
|
||||
syn match hostsComment "\v^[#;].*$"
|
||||
|
||||
highlight link hostsFirstWord Label
|
||||
highlight link hostsHeader Define
|
||||
highlight link hostsComment Comment
|
||||
highlight link hostsHeaderSpecials Identifier
|
||||
highlight link hostsAttributes Structure
|
||||
|
||||
if exists("g:ansible_attribute_highlight")
|
||||
if g:ansible_attribute_highlight =~ 'n'
|
||||
highlight link hostsAttributes NONE
|
||||
elseif g:ansible_attribute_highlight =~ 'd'
|
||||
highlight link hostsAttributes Comment
|
||||
endif
|
||||
endif
|
||||
|
||||
let b:current_syntax = "ansible_hosts"
|
||||
|
||||
endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user