mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-09 12:03:53 -05:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11f34624aa | ||
|
|
1422f7a75c | ||
|
|
b17b5d4d9f | ||
|
|
bd824d9407 | ||
|
|
c3233deb70 | ||
|
|
bf188c4a51 | ||
|
|
a5857b81c2 | ||
|
|
7a32eec6d1 | ||
|
|
c69562f864 | ||
|
|
40c54bc12b | ||
|
|
44b3d860cb | ||
|
|
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 |
63
README.md
63
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
|
[travis-url]: https://travis-ci.org/sheerun/vim-polyglot
|
||||||
|
|
||||||
A collection of language packs for Vim.
|
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.
|
> 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 **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.
|
- Solid syntax and indentation support. Only the best language packs.
|
||||||
- All unnecessary files are ignored (like enormous documentation from php support).
|
- All unnecessary files are ignored (like enormous documentation from php support).
|
||||||
- No support for esoteric languages, only most popular ones (modern too, like `slim`).
|
- No support for esoteric languages, only most popular ones (modern too, like `slim`).
|
||||||
@@ -25,22 +25,27 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
|||||||
|
|
||||||
## Language packs
|
## Language packs
|
||||||
|
|
||||||
|
- [ansible](https://github.com/pearofducks/ansible-vim) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent, ftdetect)
|
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent, ftdetect)
|
||||||
- [blade](https://github.com/jwalton512/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++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
|
||||||
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
||||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
|
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
|
||||||
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect)
|
- [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)
|
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||||
|
- [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)
|
- [css](https://github.com/JulesWang/css.vim) (syntax)
|
||||||
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)
|
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||||
- [dart](https://github.com/dart-lang/dart-vim-plugin) (syntax, indent, 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)
|
- [dockerfile](https://github.com/honza/dockerfile.vim) (syntax, ftdetect)
|
||||||
- [elm](https://github.com/lambdatoast/elm.vim) (syntax, indent, autoload, ftplugin, ftdetect)
|
|
||||||
- [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, ftplugin, ftdetect)
|
- [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||||
- [emberscript](https://github.com/heartsentwined/vim-ember-script) (syntax, indent, ftplugin, ftdetect)
|
- [elm](https://github.com/lambdatoast/elm.vim) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||||
- [emblem](https://github.com/heartsentwined/vim-emblem) (syntax, indent, ftplugin, ftdetect)
|
- [emberscript](https://github.com/yalesov/vim-ember-script) (syntax, indent, ftplugin, ftdetect)
|
||||||
|
- [emblem](https://github.com/yalesov/vim-emblem) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [erlang](https://github.com/vim-erlang/vim-erlang-runtime) (syntax, indent, ftdetect)
|
- [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)
|
- [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent, ftdetect)
|
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent, ftdetect)
|
||||||
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent, ftdetect)
|
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent, ftdetect)
|
||||||
@@ -50,10 +55,8 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
|||||||
- [haskell](https://github.com/neovimhaskell/haskell-vim) (syntax, indent, ftplugin, ftdetect)
|
- [haskell](https://github.com/neovimhaskell/haskell-vim) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [haxe](https://github.com/yaymukund/vim-haxe) (syntax, ftdetect)
|
- [haxe](https://github.com/yaymukund/vim-haxe) (syntax, ftdetect)
|
||||||
- [html5](https://github.com/othree/html5.vim) (syntax, indent, autoload, ftplugin)
|
- [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)
|
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect)
|
||||||
- [javascript](https://github.com/sheerun/yajs.vim) (syntax, indent)
|
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [jinja](https://github.com/Glench/Vim-Jinja2-Syntax) (syntax, indent, ftdetect)
|
|
||||||
- [json](https://github.com/sheerun/vim-json) (syntax, indent, ftdetect)
|
- [json](https://github.com/sheerun/vim-json) (syntax, indent, ftdetect)
|
||||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
||||||
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
||||||
@@ -62,48 +65,62 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
|||||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
||||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [markdown](https://github.com/tpope/vim-markdown) (syntax, ftplugin, ftdetect)
|
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [nginx](https://github.com/nginx/nginx) (syntax, indent, ftdetect)
|
- [markdown](https://github.com/plasticboy/vim-markdown) (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)
|
- [objc](https://github.com/b4winckler/vim-objc) (ftplugin, syntax, indent)
|
||||||
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
|
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
|
||||||
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
|
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
|
||||||
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect)
|
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [perl](https://github.com/vim-perl/vim-perl) (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)
|
- [php](https://github.com/StanAngeloff/php.vim) (syntax)
|
||||||
|
- [plantuml](https://github.com/aklt/plantuml-syntax) (syntax, ftplugin, ftdetect)
|
||||||
- [powershell](https://github.com/Persistent13/vim-ps1) (syntax, indent, ftplugin, ftdetect)
|
- [powershell](https://github.com/Persistent13/vim-ps1) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, ftdetect)
|
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, indent, ftdetect)
|
||||||
- [puppet](https://github.com/rodjek/vim-puppet) (syntax, indent, ftplugin, 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)
|
- [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent)
|
||||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin, ftdetect)
|
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [ragel](https://github.com/jneen/ragel.vim) (syntax)
|
|
||||||
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
- [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)
|
- [rspec](https://github.com/sheerun/rspec.vim) (syntax, ftdetect)
|
||||||
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||||
- [rust](https://github.com/rust-lang/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)
|
- [sbt](https://github.com/derekwyatt/vim-sbt) (syntax, ftdetect)
|
||||||
- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin, ftdetect)
|
- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||||
- [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftdetect)
|
- [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [solidity](https://github.com/ethereum/vim-solidity) (syntax, indent, ftdetect)
|
- [solidity](https://github.com/ethereum/vim-solidity) (syntax, indent, ftdetect)
|
||||||
- [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin, ftdetect)
|
- [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin, ftdetect)
|
||||||
- [swift](https://github.com/keith/swift.vim) (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)
|
- [systemd](https://github.com/kurayama/systemd-vim-syntax) (syntax, ftdetect)
|
||||||
- [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin, ftdetect)
|
- [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin, ftdetect)
|
||||||
- [thrift](https://github.com/solarnz/thrift.vim) (syntax, ftdetect)
|
- [thrift](https://github.com/solarnz/thrift.vim) (syntax, ftdetect)
|
||||||
- [tmux](https://github.com/tejr/vim-tmux) (syntax, ftdetect)
|
- [tmux](https://github.com/keith/tmux.vim) (syntax, ftplugin, ftdetect)
|
||||||
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
|
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
|
||||||
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect)
|
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect)
|
||||||
- [twig](https://github.com/beyondwords/vim-twig) (syntax, ftplugin, ftdetect)
|
- [twig](https://github.com/evidens/vim-twig) (syntax, ftplugin)
|
||||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||||
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
|
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
|
||||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||||
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect)
|
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect)
|
||||||
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent, ftdetect)
|
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent, ftdetect)
|
||||||
- [xls](https://github.com/vim-scripts/XSLT-syntax) (syntax)
|
- [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)
|
- [yard](https://github.com/sheerun/vim-yardoc) (syntax)
|
||||||
|
|
||||||
## Disabling a language pack
|
## Updating
|
||||||
|
|
||||||
Individual language packs can be disabled by setting `g:polyglot_disabled`.
|
You can either wait for new patch release with updates or run the `./build` script by yourself.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
Please make sure you have `syntax on` in your `.vimrc`, otherwise syntax files are not loaded at all.
|
||||||
|
|
||||||
|
Individual language packs can be disabled by setting `g:polyglot_disabled` as follows:
|
||||||
|
|
||||||
```viml
|
```viml
|
||||||
" ~/.vimrc
|
" ~/.vimrc
|
||||||
@@ -112,10 +129,6 @@ let g:polyglot_disabled = ['css']
|
|||||||
|
|
||||||
Note that disabiling languages won't make in general your vim startup any faster / slower (only for specific file type). Vim-polyglot is selection of language plugins that are loaded only on demand.
|
Note that disabiling languages won't make in general your vim startup any faster / slower (only for specific file type). Vim-polyglot is selection of language plugins that are loaded only on demand.
|
||||||
|
|
||||||
## Updating
|
|
||||||
|
|
||||||
You can either wait for new patch release with updates or run the `./build` script by yourself.
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Language packs are periodically updated using automated `build` script.
|
Language packs are periodically updated using automated `build` script.
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||||
|
|
||||||
setlocal comments=s1fl:{-,mb:-,ex:-},:--
|
setlocal comments=s1fl:{-,mb:-,ex:-},:--
|
||||||
setlocal formatoptions-=cro formatoptions+=j
|
|
||||||
setlocal iskeyword+=-,.,*
|
setlocal iskeyword+=-,.,*
|
||||||
setlocal commentstring=--\ %s
|
setlocal commentstring=--\ %s
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||||
|
|
||||||
setlocal comments=s1fl:{-,mb:-,ex:-},:--
|
setlocal comments=s1fl:{-,mb:\ \ ,ex:-},:--
|
||||||
setlocal formatoptions-=cro formatoptions+=j
|
|
||||||
setlocal iskeyword+='
|
setlocal iskeyword+='
|
||||||
|
|
||||||
endif
|
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
|
||||||
@@ -26,8 +26,8 @@ setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
|||||||
" XML indentkeys
|
" XML indentkeys
|
||||||
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||||
|
|
||||||
" Self-closing tag regex.
|
" Multiline end tag regex (line beginning with '>' or '/>')
|
||||||
let s:sctag = '^\s*\/>\s*;\='
|
let s:endtag = '^\s*\/\?>\s*;\='
|
||||||
|
|
||||||
" Get all syntax types at the beginning of a given line.
|
" Get all syntax types at the beginning of a given line.
|
||||||
fu! SynSOL(lnum)
|
fu! SynSOL(lnum)
|
||||||
@@ -76,13 +76,13 @@ fu! GetJsxIndent()
|
|||||||
if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
|
if (SynXMLish(prevsyn) || SynJSXBlockEnd(prevsyn)) && SynXMLishAny(cursyn)
|
||||||
let ind = XmlIndentGet(v:lnum, 0)
|
let ind = XmlIndentGet(v:lnum, 0)
|
||||||
|
|
||||||
" Align '/>' with '<' for multiline self-closing tags.
|
" Align '/>' and '>' with '<' for multiline tags.
|
||||||
if getline(v:lnum) =~? s:sctag
|
if getline(v:lnum) =~? s:endtag
|
||||||
let ind = ind - &sw
|
let ind = ind - &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Then correct the indentation of any JSX following '/>'.
|
" Then correct the indentation of any JSX following '/>' or '>'.
|
||||||
if getline(v:lnum - 1) =~? s:sctag
|
if getline(v:lnum - 1) =~? s:endtag
|
||||||
let ind = ind + &sw
|
let ind = ind + &sw
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -36,22 +36,56 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
|||||||
|
|
||||||
" Functions
|
" Functions
|
||||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
||||||
syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen
|
syn match cCustomFunc "\w\+\s*(\@="
|
||||||
hi def link cCustomFunc Function
|
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
|
" Class and namespace scope
|
||||||
if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight
|
if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight
|
||||||
syn match cCustomScope "::"
|
syn match cCustomScope "::"
|
||||||
syn match cCustomClass "\w\+\s*::" contains=cCustomScope
|
syn match cCustomClass "\w\+\s*::"
|
||||||
hi def link cCustomClass Function " disabled for now
|
\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
|
endif
|
||||||
|
|
||||||
" Alternative syntax that is used in:
|
" Alternative syntax that is used in:
|
||||||
@@ -136,7 +170,6 @@ syntax keyword cppSTLfunctional binary_negate
|
|||||||
syntax keyword cppSTLfunctional bit_and
|
syntax keyword cppSTLfunctional bit_and
|
||||||
syntax keyword cppSTLfunctional bit_not
|
syntax keyword cppSTLfunctional bit_not
|
||||||
syntax keyword cppSTLfunctional bit_or
|
syntax keyword cppSTLfunctional bit_or
|
||||||
syntax keyword cppSTLfunctional bit_xor
|
|
||||||
syntax keyword cppSTLfunctional divides
|
syntax keyword cppSTLfunctional divides
|
||||||
syntax keyword cppSTLfunctional equal_to
|
syntax keyword cppSTLfunctional equal_to
|
||||||
syntax keyword cppSTLfunctional greater
|
syntax keyword cppSTLfunctional greater
|
||||||
@@ -591,6 +624,7 @@ syntax keyword cppSTLtype const_mem_fun_ref_t
|
|||||||
syntax keyword cppSTLtype const_mem_fun_t
|
syntax keyword cppSTLtype const_mem_fun_t
|
||||||
syntax keyword cppSTLtype const_pointer
|
syntax keyword cppSTLtype const_pointer
|
||||||
syntax keyword cppSTLtype const_reference
|
syntax keyword cppSTLtype const_reference
|
||||||
|
syntax keyword cppSTLtype container_type
|
||||||
syntax keyword cppSTLtype deque
|
syntax keyword cppSTLtype deque
|
||||||
syntax keyword cppSTLtype difference_type
|
syntax keyword cppSTLtype difference_type
|
||||||
syntax keyword cppSTLtype div_t
|
syntax keyword cppSTLtype div_t
|
||||||
|
|||||||
@@ -32,12 +32,23 @@ endif
|
|||||||
" - othree/yajs.vim: javascriptNoReserved
|
" - 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.
|
" Highlight JSX regions as XML; recursively match.
|
||||||
"
|
"
|
||||||
" Note that we prohibit JSX tags from having a < or word character immediately
|
" Note that we prohibit JSX tags from having a < or word character immediately
|
||||||
" preceding it, to avoid conflicts with, respectively, the left shift operator
|
" preceding it, to avoid conflicts with, respectively, the left shift operator
|
||||||
" and generic Flow type annotations (http://flowtype.org/).
|
" and generic Flow type annotations (http://flowtype.org/).
|
||||||
syn region jsxRegion contains=@XMLSyntax,jsxRegion,jsBlock,javascriptBlock
|
syn region jsxRegion
|
||||||
|
\ contains=@XMLSyntax,jsxRegion,jsxChild,jsBlock,javascriptBlock
|
||||||
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
\ start=+\%(<\|\w\)\@<!<\z([a-zA-Z][a-zA-Z0-9:\-.]*\)+
|
||||||
\ skip=+<!--\_.\{-}-->+
|
\ skip=+<!--\_.\{-}-->+
|
||||||
\ end=+</\z1\_\s\{-}>+
|
\ end=+</\z1\_\s\{-}>+
|
||||||
@@ -45,10 +56,6 @@ syn region jsxRegion contains=@XMLSyntax,jsxRegion,jsBlock,javascriptBlock
|
|||||||
\ keepend
|
\ keepend
|
||||||
\ extend
|
\ 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.
|
" Add jsxRegion to the lowest-level JS syntax cluster.
|
||||||
syn cluster jsExpression add=jsxRegion
|
syn cluster jsExpression add=jsxRegion
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ endif
|
|||||||
|
|
||||||
hi link rustNiceOperator Operator
|
hi link rustNiceOperator Operator
|
||||||
|
|
||||||
if !exists('g:rust_conceal_mod_path') && g:rust_conceal_mod_path != 0
|
if !(exists('g:rust_conceal_mod_path') && g:rust_conceal_mod_path != 0)
|
||||||
hi! link Conceal Operator
|
hi! link Conceal Operator
|
||||||
|
|
||||||
|
" And keep it after a colorscheme change
|
||||||
|
au ColorScheme <buffer> hi! link Conceal Operator
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endif
|
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
|
||||||
File diff suppressed because one or more lines are too long
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
|
||||||
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
|
||||||
@@ -348,7 +348,7 @@ function! s:RmDir(path)
|
|||||||
echoerr 'Attempted to delete protected path: ' . a:path
|
echoerr 'Attempted to delete protected path: ' . a:path
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
silent exe "!rm -rf " . shellescape(a:path)
|
return system("rm -rf " . shellescape(a:path))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Executes {cmd} with the cwd set to {pwd}, without changing Vim's cwd.
|
" Executes {cmd} with the cwd set to {pwd}, without changing Vim's cwd.
|
||||||
|
|||||||
@@ -29,9 +29,13 @@ function! rustfmt#Format()
|
|||||||
|
|
||||||
let command = g:rustfmt_command . " --write-mode=overwrite "
|
let command = g:rustfmt_command . " --write-mode=overwrite "
|
||||||
|
|
||||||
let out = systemlist(command . g:rustfmt_options . " " . shellescape(l:tmpname))
|
if exists("*systemlist")
|
||||||
|
let out = systemlist(command . g:rustfmt_options . " " . shellescape(l:tmpname))
|
||||||
|
else
|
||||||
|
let out = split(system(command . g:rustfmt_options . " " . shellescape(l:tmpname)), '\r\?\n')
|
||||||
|
endif
|
||||||
|
|
||||||
if v:shell_error == 0
|
if v:shell_error == 0 || v:shell_error == 3
|
||||||
" remove undo point caused via BufWritePre
|
" remove undo point caused via BufWritePre
|
||||||
try | silent undojoin | catch | endtry
|
try | silent undojoin | catch | endtry
|
||||||
|
|
||||||
|
|||||||
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
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
||||||
|
|
||||||
" Vim completion for HTML5 data file
|
" Vim completion for HTML5 data file
|
||||||
" Language: HTML5
|
" Language: HTML (version 5.1 Draft 2016 Jan 13)
|
||||||
" Maintainer: othree <othree@gmail.com>
|
" Maintainer: Kao, Wei-Ko(othree) ( othree AT gmail DOT com )
|
||||||
" Last Change: 2011 Apr 9
|
" Last Change: 2016 Jan 20
|
||||||
|
|
||||||
|
|
||||||
" Lang Tag: {{{
|
" Lang Tag: {{{
|
||||||
@@ -598,9 +598,13 @@ let g:xmldata_html5 = {
|
|||||||
\ global_attributes
|
\ global_attributes
|
||||||
\ ],
|
\ ],
|
||||||
\ 'menu': [
|
\ 'menu': [
|
||||||
\ flow_elements + ['li'],
|
\ flow_elements + ['menuitem'],
|
||||||
\ extend(copy(global_attributes), {'type': ['toolbar', 'context'], 'label': []})
|
\ 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': [
|
\ '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})
|
\ 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})
|
||||||
|
|||||||
38
build
38
build
@@ -5,6 +5,7 @@ set -E
|
|||||||
DIRS="syntax indent compiler autoload ftplugin ftdetect after/syntax after/indent after/ftplugin after/ftdetect"
|
DIRS="syntax indent compiler autoload ftplugin ftdetect after/syntax after/indent after/ftplugin after/ftdetect"
|
||||||
DIRS_BASIC="syntax compiler 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"
|
DIRS_ALL="syntax indent compiler autoload ftplugin ftdetect after"
|
||||||
|
DIRS_SYNTAX="syntax ftdetect after/syntax after/ftdetect"
|
||||||
|
|
||||||
OUTPUT=""
|
OUTPUT=""
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ copy_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
concat_ftdetect() {
|
concat_ftdetect() {
|
||||||
cat ftdetect/* | grep -E '^[^"]' > tmp/polyglot.vim
|
for f in ftdetect/*; do (echo '" '"$f"; cat "${f}"; echo) >> tmp/polyglot.vim; done
|
||||||
rm -f ftdetect/*
|
rm -f ftdetect/*
|
||||||
mv tmp/polyglot.vim ftdetect/
|
mv tmp/polyglot.vim ftdetect/
|
||||||
}
|
}
|
||||||
@@ -96,6 +97,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
PACKS="
|
PACKS="
|
||||||
|
ansible:pearofducks/ansible-vim
|
||||||
arduino:sudar/vim-arduino-syntax
|
arduino:sudar/vim-arduino-syntax
|
||||||
blade:jwalton512/vim-blade
|
blade:jwalton512/vim-blade
|
||||||
c++11:octol/vim-cpp-enhanced-highlight
|
c++11:octol/vim-cpp-enhanced-highlight
|
||||||
@@ -103,15 +105,19 @@ PACKS="
|
|||||||
cjsx:mtscout6/vim-cjsx
|
cjsx:mtscout6/vim-cjsx
|
||||||
clojure:guns/vim-clojure-static
|
clojure:guns/vim-clojure-static
|
||||||
coffee-script:kchmck/vim-coffee-script
|
coffee-script:kchmck/vim-coffee-script
|
||||||
|
cryptol:victoredwardocallaghan/cryptol.vim
|
||||||
|
crystal:rhysd/vim-crystal
|
||||||
|
cql:elubow/cql-vim
|
||||||
css:JulesWang/css.vim
|
css:JulesWang/css.vim
|
||||||
cucumber:tpope/vim-cucumber
|
cucumber:tpope/vim-cucumber
|
||||||
dart:dart-lang/dart-vim-plugin
|
dart:dart-lang/dart-vim-plugin
|
||||||
dockerfile:honza/dockerfile.vim
|
dockerfile:honza/dockerfile.vim
|
||||||
elm:lambdatoast/elm.vim
|
|
||||||
elixir:elixir-lang/vim-elixir
|
elixir:elixir-lang/vim-elixir
|
||||||
emberscript:heartsentwined/vim-ember-script
|
elm:lambdatoast/elm.vim
|
||||||
emblem:heartsentwined/vim-emblem
|
emberscript:yalesov/vim-ember-script
|
||||||
|
emblem:yalesov/vim-emblem
|
||||||
erlang:vim-erlang/vim-erlang-runtime
|
erlang:vim-erlang/vim-erlang-runtime
|
||||||
|
fish:dag/vim-fish
|
||||||
git:tpope/vim-git
|
git:tpope/vim-git
|
||||||
glsl:tikhomirov/vim-glsl
|
glsl:tikhomirov/vim-glsl
|
||||||
go:fatih/vim-go:_BASIC
|
go:fatih/vim-go:_BASIC
|
||||||
@@ -121,10 +127,8 @@ PACKS="
|
|||||||
haskell:neovimhaskell/haskell-vim
|
haskell:neovimhaskell/haskell-vim
|
||||||
haxe:yaymukund/vim-haxe
|
haxe:yaymukund/vim-haxe
|
||||||
html5:othree/html5.vim
|
html5:othree/html5.vim
|
||||||
jade:digitaltoad/vim-jade
|
|
||||||
jasmine:glanotte/vim-jasmine
|
jasmine:glanotte/vim-jasmine
|
||||||
javascript:sheerun/yajs.vim
|
javascript:pangloss/vim-javascript
|
||||||
jinja:Glench/Vim-Jinja2-Syntax
|
|
||||||
json:sheerun/vim-json
|
json:sheerun/vim-json
|
||||||
jst:briancollins/vim-jst
|
jst:briancollins/vim-jst
|
||||||
jsx:mxw/vim-jsx:_ALL
|
jsx:mxw/vim-jsx:_ALL
|
||||||
@@ -133,21 +137,28 @@ PACKS="
|
|||||||
latex:LaTeX-Box-Team/LaTeX-Box
|
latex:LaTeX-Box-Team/LaTeX-Box
|
||||||
less:groenewege/vim-less
|
less:groenewege/vim-less
|
||||||
liquid:tpope/vim-liquid
|
liquid:tpope/vim-liquid
|
||||||
markdown:tpope/vim-markdown
|
mako:sophacles/vim-bundle-mako
|
||||||
nginx:nginx/nginx::/contrib/vim/
|
markdown:plasticboy/vim-markdown:_SYNTAX
|
||||||
|
nginx:othree/nginx-contrib-vim
|
||||||
|
nim:zah/nim.vim:_BASIC
|
||||||
|
nix:spwhitt/vim-nix
|
||||||
objc:b4winckler/vim-objc
|
objc:b4winckler/vim-objc
|
||||||
ocaml:jrk/vim-ocaml
|
ocaml:jrk/vim-ocaml
|
||||||
octave:vim-scripts/octave.vim--
|
octave:vim-scripts/octave.vim--
|
||||||
opencl:petRUShka/vim-opencl
|
opencl:petRUShka/vim-opencl
|
||||||
perl:vim-perl/vim-perl
|
perl:vim-perl/vim-perl
|
||||||
|
pgsql:exu/pgsql.vim
|
||||||
php:StanAngeloff/php.vim
|
php:StanAngeloff/php.vim
|
||||||
|
plantuml:aklt/plantuml-syntax
|
||||||
powershell:Persistent13/vim-ps1
|
powershell:Persistent13/vim-ps1
|
||||||
protobuf:uarun/vim-protobuf
|
protobuf:uarun/vim-protobuf
|
||||||
puppet:rodjek/vim-puppet
|
pug:digitaltoad/vim-pug
|
||||||
|
puppet:voxpupuli/vim-puppet
|
||||||
|
purescript:raichoo/purescript-vim
|
||||||
python:mitsuhiko/vim-python-combined
|
python:mitsuhiko/vim-python-combined
|
||||||
qml:peterhoeg/vim-qml
|
qml:peterhoeg/vim-qml
|
||||||
ragel:jneen/ragel.vim
|
|
||||||
r-lang:vim-scripts/R.vim
|
r-lang:vim-scripts/R.vim
|
||||||
|
ragel:jneen/ragel.vim
|
||||||
rspec:sheerun/rspec.vim
|
rspec:sheerun/rspec.vim
|
||||||
ruby:vim-ruby/vim-ruby
|
ruby:vim-ruby/vim-ruby
|
||||||
rust:rust-lang/rust.vim
|
rust:rust-lang/rust.vim
|
||||||
@@ -160,16 +171,17 @@ PACKS="
|
|||||||
systemd:kurayama/systemd-vim-syntax
|
systemd:kurayama/systemd-vim-syntax
|
||||||
textile:timcharper/textile.vim
|
textile:timcharper/textile.vim
|
||||||
thrift:solarnz/thrift.vim
|
thrift:solarnz/thrift.vim
|
||||||
tmux:tejr/vim-tmux
|
tmux:keith/tmux.vim
|
||||||
tomdoc:wellbredgrapefruit/tomdoc.vim
|
tomdoc:wellbredgrapefruit/tomdoc.vim
|
||||||
toml:cespare/vim-toml
|
toml:cespare/vim-toml
|
||||||
twig:beyondwords/vim-twig
|
twig:evidens/vim-twig
|
||||||
typescript:leafgarland/typescript-vim
|
typescript:leafgarland/typescript-vim
|
||||||
vala:tkztmk/vim-vala
|
vala:tkztmk/vim-vala
|
||||||
vbnet:vim-scripts/vbnet.vim
|
vbnet:vim-scripts/vbnet.vim
|
||||||
vcl:smerrill/vcl-vim-plugin
|
vcl:smerrill/vcl-vim-plugin
|
||||||
vm:lepture/vim-velocity
|
vm:lepture/vim-velocity
|
||||||
xls:vim-scripts/XSLT-syntax
|
xls:vim-scripts/XSLT-syntax
|
||||||
|
yaml:stephpy/vim-yaml
|
||||||
yard:sheerun/vim-yardoc
|
yard:sheerun/vim-yardoc
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|||||||
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
|
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")
|
if exists("current_compiler")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
@@ -16,9 +11,15 @@ endif
|
|||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo-=C
|
set cpo-=C
|
||||||
|
|
||||||
CompilerSet makeprg=mix\ test
|
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
|
let &cpo = s:cpo_save
|
||||||
unlet 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
|
||||||
@@ -18,9 +18,9 @@ endif
|
|||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo-=C
|
set cpo-=C
|
||||||
if filereadable("makefile") || filereadable("Makefile")
|
if filereadable("makefile") || filereadable("Makefile")
|
||||||
CompilerSet makeprg=make
|
CompilerSet makeprg=make
|
||||||
else
|
else
|
||||||
CompilerSet makeprg=go\ build
|
CompilerSet makeprg=go\ build
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Define the patterns that will be recognized by QuickFix when parsing the
|
" Define the patterns that will be recognized by QuickFix when parsing the
|
||||||
@@ -40,6 +40,6 @@ CompilerSet errorformat+=%-G%.%# " All lines not matching a
|
|||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
" vim:ts=4:sw=4:et
|
" vim: sw=2 ts=2 et
|
||||||
|
|
||||||
endif
|
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\ --verbosity:0\ $*\ %:p
|
||||||
|
|
||||||
|
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
|
||||||
@@ -27,6 +27,7 @@ CompilerSet errorformat=
|
|||||||
\%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#,
|
\%-Z\ \ \ \ \ %\\+\#\ %f:%l:%.%#,
|
||||||
\%E\ \ %\\d%\\+)%.%#,
|
\%E\ \ %\\d%\\+)%.%#,
|
||||||
\%C\ \ \ \ \ %m,
|
\%C\ \ \ \ \ %m,
|
||||||
|
\%C%\\s%#,
|
||||||
\%-G%.%#
|
\%-G%.%#
|
||||||
|
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
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
|
||||||
36
ftplugin/blade.vim
Normal file
36
ftplugin/blade.vim
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 suffixesadd=.blade.php,.php
|
||||||
|
setlocal includeexpr=substitute(v:fname,'\\.','/','g')
|
||||||
|
setlocal path+=resources/views;
|
||||||
|
setlocal include=\\w\\@<!@\\%(include\\\|extends\\)
|
||||||
|
setlocal define=\\w\\@<!@\\%(yield\\\|stack\\)
|
||||||
|
|
||||||
|
setlocal commentstring={{--%s--}}
|
||||||
|
setlocal comments+=s:{{--,m:\ \ \ \ ,e:--}}
|
||||||
|
|
||||||
|
if exists('loaded_matchit') && exists('b:match_words')
|
||||||
|
" Append to html matchit words
|
||||||
|
let b:match_words .= ',' .
|
||||||
|
\ '@\%(section\|if\|unless\|foreach\|forelse\|for\|while\|push\|can\|cannot\|hasSection\|php\|verbatim\)\>' .
|
||||||
|
\ ':' .
|
||||||
|
\ '@\%(else\|elseif\|empty\|break\|continue\|elsecan\|elsecannot\)\>' .
|
||||||
|
\ ':' .
|
||||||
|
\ '@\%(end\w\+\|stop\|show\|append\|overwrite\)' .
|
||||||
|
\ ',{:},\[:\],(:)'
|
||||||
|
let b:match_skip = 'synIDattr(synID(line("."), col("."), 0), "name") !=# "bladeKeyword"'
|
||||||
|
let b:match_ignorecase = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -6,64 +6,4 @@ endif
|
|||||||
|
|
||||||
let g:loaded_haskellvim_cabal = 1
|
let g:loaded_haskellvim_cabal = 1
|
||||||
|
|
||||||
function! s:makeSection(content)
|
|
||||||
return "\n" . join(a:content, "\n")
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:exeTmpl(name, src)
|
|
||||||
let l:exetmpl = [ 'executable ' . a:name,
|
|
||||||
\ '-- ghc-options:',
|
|
||||||
\ 'main-is: ' . a:src,
|
|
||||||
\ '-- other-modules:',
|
|
||||||
\ '-- other-extensions:',
|
|
||||||
\ 'build-depends: base',
|
|
||||||
\ '-- hs-source-dirs:',
|
|
||||||
\ 'default-language: Haskell2010'
|
|
||||||
\ ]
|
|
||||||
|
|
||||||
return s:makeSection(l:exetmpl)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:libTmpl()
|
|
||||||
let l:libtmpl = [ 'library',
|
|
||||||
\ '-- ghc-options:',
|
|
||||||
\ '-- other-modules:',
|
|
||||||
\ '-- other-extensions:',
|
|
||||||
\ 'build-depends: base',
|
|
||||||
\ '-- hs-source-dirs:',
|
|
||||||
\ 'default-language: Haskell2010'
|
|
||||||
\ ]
|
|
||||||
|
|
||||||
return s:makeSection(l:libtmpl)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:flagTmpl(name)
|
|
||||||
let l:flagtmpl = [ 'flag ' . a:name,
|
|
||||||
\ 'description:',
|
|
||||||
\ 'default: False',
|
|
||||||
\ 'manual: True',
|
|
||||||
\ ]
|
|
||||||
|
|
||||||
return s:makeSection(l:flagtmpl)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! cabal#addExecutable()
|
|
||||||
let l:name = input("Enter executable name: ")
|
|
||||||
let l:src = input("Enter source file: ")
|
|
||||||
exe "normal Go" . s:exeTmpl(l:name, l:src)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! cabal#addLibrary()
|
|
||||||
exe "normal Go" . s:libTmpl()
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! cabal#addFlag()
|
|
||||||
let l:name = input("Enter flag name: ")
|
|
||||||
exe "normal Go" . s:flagTmpl(l:name)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
command! -buffer CabalAddExecutable call cabal#addExecutable()
|
|
||||||
command! -buffer CabalAddLibrary call cabal#addLibrary()
|
|
||||||
command! -buffer CabalAddFlag call cabal#addFlag()
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'clojure') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'clojure') == -1
|
||||||
|
|
||||||
" Vim filetype plugin file
|
" Vim filetype plugin file
|
||||||
" Language: Clojure
|
" Language: Clojure
|
||||||
" Author: Meikel Brandmeyer <mb@kotka.de>
|
" Author: Meikel Brandmeyer <mb@kotka.de>
|
||||||
"
|
"
|
||||||
" Maintainer: Sung Pae <self@sungpae.com>
|
" Maintainer: Sung Pae <self@sungpae.com>
|
||||||
" URL: https://github.com/guns/vim-clojure-static
|
" URL: https://github.com/guns/vim-clojure-static
|
||||||
" License: Same as Vim
|
" License: Same as Vim
|
||||||
" Last Change: %%RELEASE_DATE%%
|
" Last Change: %%RELEASE_DATE%%
|
||||||
|
|
||||||
if exists("b:did_ftplugin")
|
if exists("b:did_ftplugin")
|
||||||
finish
|
finish
|
||||||
@@ -84,9 +84,9 @@ endif
|
|||||||
" Win32 can filter files in the browse dialog
|
" Win32 can filter files in the browse dialog
|
||||||
if has("gui_win32") && !exists("b:browsefilter")
|
if has("gui_win32") && !exists("b:browsefilter")
|
||||||
let b:browsefilter = "Clojure Source Files (*.clj)\t*.clj\n" .
|
let b:browsefilter = "Clojure Source Files (*.clj)\t*.clj\n" .
|
||||||
\ "ClojureScript Source Files (*.cljs)\t*.cljs\n" .
|
\ "ClojureScript Source Files (*.cljs)\t*.cljs\n" .
|
||||||
\ "Java Source Files (*.java)\t*.java\n" .
|
\ "Java Source Files (*.java)\t*.java\n" .
|
||||||
\ "All Files (*.*)\t*.*\n"
|
\ "All Files (*.*)\t*.*\n"
|
||||||
let b:undo_ftplugin .= ' | unlet! b:browsefilter'
|
let b:undo_ftplugin .= ' | unlet! b:browsefilter'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ call coffee#CoffeeSetUpVariables()
|
|||||||
setlocal formatoptions-=t formatoptions+=croql
|
setlocal formatoptions-=t formatoptions+=croql
|
||||||
setlocal comments=:# commentstring=#\ %s
|
setlocal comments=:# commentstring=#\ %s
|
||||||
setlocal omnifunc=javascriptcomplete#CompleteJS
|
setlocal omnifunc=javascriptcomplete#CompleteJS
|
||||||
setlocal suffixesadd+=coffee
|
setlocal suffixesadd+=.coffee
|
||||||
|
|
||||||
" Create custom augroups.
|
" Create custom augroups.
|
||||||
augroup CoffeeBufUpdate | augroup END
|
augroup CoffeeBufUpdate | augroup END
|
||||||
|
|||||||
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
|
||||||
84
ftplugin/crystal.vim
Normal file
84
ftplugin/crystal.vim
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
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%.%#
|
||||||
|
|
||||||
|
let g:crystal_compiler_command = get(g:, 'crystal_compiler_command', 'crystal')
|
||||||
|
let g:crystal_auto_format = get(g:, 'crystal_auto_format', 0)
|
||||||
|
|
||||||
|
command! -buffer -nargs=* CrystalImpl echo crystal_lang#impl(expand('%'), getpos('.'), <q-args>).output
|
||||||
|
command! -buffer -nargs=0 CrystalDef call crystal_lang#jump_to_definition(expand('%'), getpos('.'))
|
||||||
|
command! -buffer -nargs=* CrystalContext echo crystal_lang#context(expand('%'), getpos('.'), <q-args>).output
|
||||||
|
command! -buffer -nargs=* CrystalHierarchy echo crystal_lang#type_hierarchy(expand('%'), <q-args>)
|
||||||
|
command! -buffer -nargs=? CrystalSpecSwitch call crystal_lang#switch_spec_file(<f-args>)
|
||||||
|
command! -buffer -nargs=? CrystalSpecRunAll call crystal_lang#run_all_spec(<f-args>)
|
||||||
|
command! -buffer -nargs=? CrystalSpecRunCurrent call crystal_lang#run_current_spec(<f-args>)
|
||||||
|
command! -buffer -nargs=* -bar CrystalFormat call crystal_lang#format(<q-args>)
|
||||||
|
|
||||||
|
nnoremap <Plug>(crystal-jump-to-definition) :<C-u>CrystalDef<CR>
|
||||||
|
nnoremap <Plug>(crystal-show-context) :<C-u>CrystalContext<CR>
|
||||||
|
nnoremap <Plug>(crystal-spec-switch) :<C-u>CrystalSpecSwitch<CR>
|
||||||
|
nnoremap <Plug>(crystal-spec-run-all) :<C-u>CrystalSpecRunAll<CR>
|
||||||
|
nnoremap <Plug>(crystal-spec-run-current) :<C-u>CrystalSpecRunCurrent<CR>
|
||||||
|
nnoremap <Plug>(crystal-format) :<C-u>CrystalFormat<CR>
|
||||||
|
|
||||||
|
augroup plugin-ft-crystal
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePre <buffer> if g:crystal_auto_format | CrystalFormat | endif
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
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")
|
if exists("b:did_ftplugin")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
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"))
|
if (exists("b:did_ftplugin"))
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_ftplugin = 1
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
|
|
||||||
" Matchit support
|
" Matchit support
|
||||||
if exists("loaded_matchit") && !exists("b:match_words")
|
if exists("loaded_matchit") && !exists("b:match_words")
|
||||||
let b:match_ignorecase = 0
|
let b:match_ignorecase = 0
|
||||||
|
|
||||||
let b:match_words = '\<\%(do\|fn\)\:\@!\>' .
|
let b:match_words = '\:\@<!\<\%(do\|fn\)\:\@!\>' .
|
||||||
\ ':' .
|
\ ':' .
|
||||||
\ '\<\%(else\|elsif\|catch\|after\|rescue\)\:\@!\>' .
|
\ '\<\%(else\|elsif\|catch\|after\|rescue\)\:\@!\>' .
|
||||||
\ ':' .
|
\ ':' .
|
||||||
@@ -26,4 +20,42 @@ endif
|
|||||||
setlocal comments=:#
|
setlocal comments=:#
|
||||||
setlocal commentstring=#\ %s
|
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
|
||||||
|
|
||||||
|
silent! setlocal formatoptions-=t formatoptions+=croqlj
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emberscript') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emberscript') == -1
|
||||||
|
|
||||||
" Language: ember-script
|
" Language: ember-script
|
||||||
" Maintainer: heartsentwined <heartsentwined@cogito-lab.com>
|
" Maintainer: Yulij Andreevich Lesov <yalesov@gmail.com>>
|
||||||
" URL: http://github.com/heartsentwined/vim-ember-script
|
" URL: http://github.com/yalesov/vim-ember-script
|
||||||
" Version: 1.0.1
|
" Version: 1.0.4
|
||||||
" Last Change: 2013 Apr 17
|
" Last Change: 2016 Jul 6
|
||||||
" License: GPL-3.0
|
" License: ISC
|
||||||
|
|
||||||
setlocal tabstop=2
|
setlocal tabstop=2
|
||||||
setlocal softtabstop=2
|
setlocal softtabstop=2
|
||||||
@@ -14,7 +14,11 @@ setlocal smarttab
|
|||||||
setlocal expandtab
|
setlocal expandtab
|
||||||
setlocal smartindent
|
setlocal smartindent
|
||||||
|
|
||||||
setlocal formatoptions-=t formatoptions+=croqlj
|
if v:version < 703
|
||||||
|
setlocal formatoptions-=t formatoptions+=croql
|
||||||
|
else
|
||||||
|
setlocal formatoptions-=t formatoptions+=croqlj
|
||||||
|
endif
|
||||||
setlocal comments=:#
|
setlocal comments=:#
|
||||||
setlocal commentstring=#\ %s
|
setlocal commentstring=#\ %s
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emblem') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emblem') == -1
|
||||||
|
|
||||||
" Language: emblem
|
" Language: emblem
|
||||||
" Maintainer: heartsentwined <heartsentwined@cogito-lab.com>
|
" Maintainer: Yulij Andreevich Lesov <yalesov@gmail.com>
|
||||||
" URL: http://github.com/heartsentwined/vim-emblem
|
" URL: http://github.com/yalesov/vim-emblem
|
||||||
" Version: 1.2.0
|
" Version: 2.0.1
|
||||||
" Last Change: 2013 Apr 22
|
" Last Change: 2016 Jul 6
|
||||||
" License: GPL-3.0
|
" License: ISC
|
||||||
|
|
||||||
setlocal tabstop=2
|
setlocal tabstop=2
|
||||||
setlocal softtabstop=2
|
setlocal softtabstop=2
|
||||||
|
|||||||
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
|
" Vim filetype plugin
|
||||||
" Language: generic git output
|
" Language: generic git output
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||||
|
" Last Change: 2013 May 30
|
||||||
|
|
||||||
" Only do this when not done yet for this buffer
|
" Only do this when not done yet for this buffer
|
||||||
if (exists("b:did_ftplugin"))
|
if (exists("b:did_ftplugin"))
|
||||||
@@ -13,6 +14,8 @@ let b:did_ftplugin = 1
|
|||||||
if !exists('b:git_dir')
|
if !exists('b:git_dir')
|
||||||
if expand('%:p') =~# '[\/]\.git[\/]modules[\/]'
|
if expand('%:p') =~# '[\/]\.git[\/]modules[\/]'
|
||||||
" Stay out of the way
|
" Stay out of the way
|
||||||
|
elseif expand('%:p') =~# '[\/]\.git[\/]worktrees'
|
||||||
|
let b:git_dir = matchstr(expand('%:p'),'.*\.git[\/]worktrees[\/][^\/]\+\>')
|
||||||
elseif expand('%:p') =~# '\.git\>'
|
elseif expand('%:p') =~# '\.git\>'
|
||||||
let b:git_dir = matchstr(expand('%:p'),'.*\.git\>')
|
let b:git_dir = matchstr(expand('%:p'),'.*\.git\>')
|
||||||
elseif $GIT_DIR != ''
|
elseif $GIT_DIR != ''
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
|
|||||||
" Vim filetype plugin
|
" Vim filetype plugin
|
||||||
" Language: git commit file
|
" Language: git commit file
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
" 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
|
" Only do this when not done yet for this buffer
|
||||||
if (exists("b:did_ftplugin"))
|
if (exists("b:did_ftplugin"))
|
||||||
@@ -13,8 +13,10 @@ endif
|
|||||||
runtime! ftplugin/git.vim
|
runtime! ftplugin/git.vim
|
||||||
let b:did_ftplugin = 1
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
setlocal nomodeline tabstop=8 formatoptions-=croq formatoptions+=tl textwidth=72
|
setlocal comments=:# commentstring=#\ %s
|
||||||
let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw<'
|
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
|
if exists("g:no_gitcommit_commands") || v:version < 700
|
||||||
finish
|
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>)
|
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)
|
function! s:diffcomplete(A,L,P)
|
||||||
let args = ""
|
let args = ""
|
||||||
if a:P <= match(a:L." -- "," -- ")+3
|
if a:P <= match(a:L." -- "," -- ")+3
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ runtime! ftplugin/git.vim
|
|||||||
let b:did_ftplugin = 1
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
setlocal comments=:# commentstring=#\ %s formatoptions-=t
|
setlocal comments=:# commentstring=#\ %s formatoptions-=t
|
||||||
|
setlocal nomodeline
|
||||||
if !exists("b:undo_ftplugin")
|
if !exists("b:undo_ftplugin")
|
||||||
let b:undo_ftplugin = ""
|
let b:undo_ftplugin = ""
|
||||||
endif
|
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)
|
function! s:choose(word)
|
||||||
s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e
|
s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e
|
||||||
|
|||||||
@@ -6,20 +6,15 @@ endif
|
|||||||
|
|
||||||
let g:loaded_haskellvim_haskell = 1
|
let g:loaded_haskellvim_haskell = 1
|
||||||
|
|
||||||
function! haskell#makeModuleCommentBlock()
|
function! haskell#sortImports(line1, line2)
|
||||||
let l:commenttmpl = [ '{-|',
|
exe a:line1 . "," . a:line2 . "sort /import\\s\\+\\(qualified\\s\\+\\)\\?/"
|
||||||
\ 'Module : ',
|
|
||||||
\ 'Description : ',
|
|
||||||
\ 'Copyright : ',
|
|
||||||
\ 'License : ',
|
|
||||||
\ 'Maintainer : ',
|
|
||||||
\ 'Stability : ',
|
|
||||||
\ 'Portability : ',
|
|
||||||
\ '-}']
|
|
||||||
|
|
||||||
exe "normal ggO" . join(l:commenttmpl, "\n")
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -buffer -nargs=0 HaskellAddModuleComment call haskell#makeModuleCommentBlock()
|
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
|
endif
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
|||||||
|
|
||||||
" setlocal iskeyword+=-
|
" setlocal iskeyword+=-
|
||||||
|
|
||||||
|
setlocal commentstring=<!--%s-->
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
8
ftplugin/javascript.vim
Normal file
8
ftplugin/javascript.vim
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
|
||||||
|
|
||||||
|
setlocal suffixesadd+=.js
|
||||||
|
if (v:version < 704 || (v:version == 704 && !has('patch002'))) && exists('®expengine')
|
||||||
|
set re=1
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'markdown') == -1
|
|
||||||
|
|
||||||
" Vim filetype plugin
|
|
||||||
" Language: Markdown
|
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
|
||||||
" Last Change: 2013 May 30
|
|
||||||
|
|
||||||
if exists("b:did_ftplugin")
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
|
||||||
|
|
||||||
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s
|
|
||||||
setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
|
|
||||||
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:
|
|
||||||
|
|
||||||
if exists('b:undo_ftplugin')
|
|
||||||
let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
|
|
||||||
else
|
|
||||||
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! MarkdownFold()
|
|
||||||
let line = getline(v:lnum)
|
|
||||||
|
|
||||||
" Regular headers
|
|
||||||
let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=')
|
|
||||||
if depth > 0
|
|
||||||
return ">" . depth
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Setext style headings
|
|
||||||
let nextline = getline(v:lnum + 1)
|
|
||||||
if (line =~ '^.\+$') && (nextline =~ '^=\+$')
|
|
||||||
return ">1"
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (line =~ '^.\+$') && (nextline =~ '^-\+$')
|
|
||||||
return ">2"
|
|
||||||
endif
|
|
||||||
|
|
||||||
return "="
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if has("folding") && exists("g:markdown_folding")
|
|
||||||
setlocal foldexpr=MarkdownFold()
|
|
||||||
setlocal foldmethod=expr
|
|
||||||
let b:undo_ftplugin .= " foldexpr< foldmethod<"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" vim:set sw=2:
|
|
||||||
|
|
||||||
endif
|
|
||||||
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
|
||||||
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
|
" Vim filetype plugin
|
||||||
" Language: Jade
|
" Language: Pug
|
||||||
" Maintainer: Joshua Borton
|
" Maintainer: Joshua Borton
|
||||||
" Credits: Tim Pope
|
" Credits: Tim Pope
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ endif
|
|||||||
|
|
||||||
" Change the browse dialog on Win32 to show mainly Haml-related files
|
" Change the browse dialog on Win32 to show mainly Haml-related files
|
||||||
if has("gui_win32")
|
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
|
endif
|
||||||
|
|
||||||
" Load the combined list of match_words for matchit.vim
|
" Load the combined list of match_words for matchit.vim
|
||||||
@@ -49,7 +49,7 @@ endif
|
|||||||
|
|
||||||
setlocal comments=://-,:// commentstring=//\ %s
|
setlocal comments=://-,:// commentstring=//\ %s
|
||||||
|
|
||||||
setlocal suffixesadd+=.jade
|
setlocal suffixesadd+=.pug
|
||||||
|
|
||||||
let b:undo_ftplugin = "setl cms< com< "
|
let b:undo_ftplugin = "setl cms< com< "
|
||||||
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
||||||
@@ -6,5 +6,6 @@ setl sw=2
|
|||||||
setl et
|
setl et
|
||||||
setl keywordprg=puppet\ describe\ --providers
|
setl keywordprg=puppet\ describe\ --providers
|
||||||
setl iskeyword=-,:,@,48-57,_,192-255
|
setl iskeyword=-,:,@,48-57,_,192-255
|
||||||
|
setl cms=#\ %s
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -77,20 +77,20 @@ function! s:query_path(root) abort
|
|||||||
let prefix = ''
|
let prefix = ''
|
||||||
endif
|
endif
|
||||||
if &shellxquote == "'"
|
if &shellxquote == "'"
|
||||||
let path_check = prefix.'ruby -e "' . code . '"'
|
let path_check = prefix.'ruby -e --disable-gems"' . code . '"'
|
||||||
else
|
else
|
||||||
let path_check = prefix."ruby -e '" . code . "'"
|
let path_check = prefix."ruby -e --disable-gems'" . code . "'"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cd = haslocaldir() ? 'lcd' : 'cd'
|
let cd = haslocaldir() ? 'lcd' : 'cd'
|
||||||
let cwd = getcwd()
|
let cwd = fnameescape(getcwd())
|
||||||
try
|
try
|
||||||
exe cd fnameescape(a:root)
|
exe cd fnameescape(a:root)
|
||||||
let path = split(system(path_check),',')
|
let path = split(system(path_check),',')
|
||||||
exe cd fnameescape(cwd)
|
exe cd cwd
|
||||||
return path
|
return path
|
||||||
finally
|
finally
|
||||||
exe cd fnameescape(cwd)
|
exe cd cwd
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
|
|||||||
\."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
|
\."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
|
||||||
\."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
|
\."| sil! exe 'unmap <buffer> [m' | sil! exe 'unmap <buffer> ]m' | sil! exe 'unmap <buffer> [M' | sil! exe 'unmap <buffer> ]M'"
|
||||||
|
|
||||||
if maparg('im','n') == ''
|
if maparg('im','x') == '' && maparg('im','o') == '' && maparg('am','x') == '' && maparg('am','o') == ''
|
||||||
onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
onoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
||||||
onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
|
onoremap <silent> <buffer> am :<C-U>call <SID>wrap_a('[m',']M')<CR>
|
||||||
xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
xnoremap <silent> <buffer> im :<C-U>call <SID>wrap_i('[m',']M')<CR>
|
||||||
@@ -196,7 +196,7 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
|
|||||||
\."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'"
|
\."| sil! exe 'xunmap <buffer> im' | sil! exe 'xunmap <buffer> am'"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if maparg('iM','n') == ''
|
if maparg('iM','x') == '' && maparg('iM','o') == '' && maparg('aM','x') == '' && maparg('aM','o') == ''
|
||||||
onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
onoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
||||||
onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
|
onoremap <silent> <buffer> aM :<C-U>call <SID>wrap_a('[[','][')<CR>
|
||||||
xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
xnoremap <silent> <buffer> iM :<C-U>call <SID>wrap_i('[[','][')<CR>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
|||||||
" Description: Vim syntax file for Rust
|
" Description: Vim syntax file for Rust
|
||||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||||
" Maintainer: Kevin Ballard <kevin@sb.org>
|
" Maintainer: Kevin Ballard <kevin@sb.org>
|
||||||
" Last Change: January 29, 2015
|
" Last Change: June 08, 2016
|
||||||
|
|
||||||
if exists("b:did_ftplugin")
|
if exists("b:did_ftplugin")
|
||||||
finish
|
finish
|
||||||
@@ -14,6 +14,9 @@ let b:did_ftplugin = 1
|
|||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
augroup rust.vim
|
||||||
|
autocmd!
|
||||||
|
|
||||||
" Variables {{{1
|
" Variables {{{1
|
||||||
|
|
||||||
" The rust source code at present seems to typically omit a leader on /*!
|
" The rust source code at present seems to typically omit a leader on /*!
|
||||||
@@ -56,7 +59,33 @@ if exists("g:loaded_delimitMate")
|
|||||||
if exists("b:delimitMate_excluded_regions")
|
if exists("b:delimitMate_excluded_regions")
|
||||||
let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
|
let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
|
||||||
endif
|
endif
|
||||||
let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
|
|
||||||
|
let s:delimitMate_extra_excluded_regions = ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
|
||||||
|
|
||||||
|
" For this buffer, when delimitMate issues the `User delimitMate_map`
|
||||||
|
" event in the autocommand system, add the above-defined extra excluded
|
||||||
|
" regions to delimitMate's state, if they have not already been added.
|
||||||
|
autocmd User <buffer>
|
||||||
|
\ if expand('<afile>') ==# 'delimitMate_map' && match(
|
||||||
|
\ delimitMate#Get("excluded_regions"),
|
||||||
|
\ s:delimitMate_extra_excluded_regions) == -1
|
||||||
|
\| let b:delimitMate_excluded_regions =
|
||||||
|
\ delimitMate#Get("excluded_regions")
|
||||||
|
\ . s:delimitMate_extra_excluded_regions
|
||||||
|
\|endif
|
||||||
|
|
||||||
|
" For this buffer, when delimitMate issues the `User delimitMate_unmap`
|
||||||
|
" event in the autocommand system, delete the above-defined extra excluded
|
||||||
|
" regions from delimitMate's state (the deletion being idempotent and
|
||||||
|
" having no effect if the extra excluded regions are not present in the
|
||||||
|
" targeted part of delimitMate's state).
|
||||||
|
autocmd User <buffer>
|
||||||
|
\ if expand('<afile>') ==# 'delimitMate_unmap'
|
||||||
|
\| let b:delimitMate_excluded_regions = substitute(
|
||||||
|
\ delimitMate#Get("excluded_regions"),
|
||||||
|
\ '\C\V' . s:delimitMate_extra_excluded_regions,
|
||||||
|
\ '', 'g')
|
||||||
|
\|endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if has("folding") && exists('g:rust_fold') && g:rust_fold != 0
|
if has("folding") && exists('g:rust_fold') && g:rust_fold != 0
|
||||||
@@ -161,10 +190,13 @@ let b:undo_ftplugin = "
|
|||||||
\|ounmap <buffer> ]]
|
\|ounmap <buffer> ]]
|
||||||
\|set matchpairs-=<:>
|
\|set matchpairs-=<:>
|
||||||
\|unlet b:match_skip
|
\|unlet b:match_skip
|
||||||
|
\|augroup! rust.vim
|
||||||
\"
|
\"
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
|
augroup END
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
|||||||
13
ftplugin/slim.vim
Normal file
13
ftplugin/slim.vim
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'slim') == -1
|
||||||
|
|
||||||
|
if exists("b:did_ftplugin")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
|
let b:undo_ftplugin = "setl isk<"
|
||||||
|
|
||||||
|
setlocal iskeyword+=-
|
||||||
|
setlocal commentstring=/%s
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'tmux') == -1
|
||||||
|
|
||||||
|
setlocal commentstring=#\ %s
|
||||||
|
|
||||||
endif
|
endif
|
||||||
@@ -8,14 +8,15 @@ if exists("b:did_ftplugin")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
runtime! ftplugin/html.vim ftplugin/html*.vim ftplugin/html/*.vim
|
|
||||||
unlet! b:did_ftplugin
|
|
||||||
|
|
||||||
setlocal comments=s:{#,ex:#}
|
setlocal comments=s:{#,ex:#}
|
||||||
setlocal formatoptions+=tcqln
|
setlocal formatoptions+=tcqln
|
||||||
" setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
|
" 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:
|
" vim:set sw=2:
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ setlocal commentstring=//\ %s
|
|||||||
" " and insert the comment leader when hitting <CR> or using "o".
|
" " and insert the comment leader when hitting <CR> or using "o".
|
||||||
setlocal formatoptions-=t formatoptions+=croql
|
setlocal formatoptions-=t formatoptions+=croql
|
||||||
|
|
||||||
|
setlocal suffixesadd+=.ts
|
||||||
|
|
||||||
let b:undo_ftplugin = "setl fo< ofu< com< cms<"
|
let b:undo_ftplugin = "setl fo< ofu< com< cms<"
|
||||||
|
|
||||||
let &cpo = s:cpo_save
|
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|role):\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
|
||||||
125
indent/blade.vim
125
indent/blade.vim
@@ -1,66 +1,83 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||||
|
|
||||||
" Language: Blade
|
" Vim indent file
|
||||||
" Author: Barry Deeney <sitemaster16@gmail.com>
|
" Language: Blade (Laravel)
|
||||||
" Version: 0.1
|
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
||||||
" Description: BLADE indent file based on HTML indentation...
|
|
||||||
|
|
||||||
" Check if this file has already been loaded
|
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Include HTML
|
|
||||||
runtime! indent/html.vim
|
runtime! indent/html.vim
|
||||||
|
let s:htmlindent = &indentexpr
|
||||||
|
unlet! b:did_indent
|
||||||
|
|
||||||
runtime! indent/php.vim
|
runtime! indent/php.vim
|
||||||
silent! unlet b:did_indent
|
let s:phpindent = &indentexpr
|
||||||
|
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!
|
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
" Doesn't include 'foreach' and 'forelse' because these already get matched by 'for'.
|
||||||
|
let s:directives_start = 'if\|else\|unless\|for\|while\|empty\|push\|section\|can\|hasSection\|verbatim'
|
||||||
|
let s:directives_end = 'else\|end\|empty\|show\|stop\|append\|overwrite'
|
||||||
|
|
||||||
|
if exists('g:blade_custom_directives_pairs')
|
||||||
|
let s:directives_start .= '\|' . join(keys(g:blade_custom_directives_pairs), '\|')
|
||||||
|
let s:directives_end .= '\|' . join(values(g:blade_custom_directives_pairs), '\|')
|
||||||
|
endif
|
||||||
|
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal indentexpr=GetBladeIndent()
|
||||||
|
exe "setlocal indentkeys=o,O,<>>,!^F,0=}},0=!!},=@" . substitute(s:directives_end, '\\|', ',=@', 'g')
|
||||||
|
|
||||||
|
" 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)
|
||||||
|
if cline =~# '@\%(' . s:directives_end . '\)' ||
|
||||||
|
\ cline =~# '\%(<?.*\)\@<!?>\|\%({{.*\)\@<!}}\|\%({!!.*\)\@<!!!}'
|
||||||
|
let indent = indent - &sw
|
||||||
|
elseif line =~# '<?\%(.*?>\)\@!\|@php\%(\s*(\)\@!'
|
||||||
|
let indent = indent + &sw
|
||||||
|
else
|
||||||
|
if exists("*GetBladeIndentCustom")
|
||||||
|
let hindent = GetBladeIndentCustom()
|
||||||
|
" Don't use PHP indentation if line is a comment
|
||||||
|
elseif line !~# '^\s*\%(#\|//\)\|\*/\s*$' && (
|
||||||
|
\ searchpair('@include\%(If\)\?\s*(', '', ')', 'bWr') ||
|
||||||
|
\ searchpair('{!!', '', '!!}', 'bWr') ||
|
||||||
|
\ searchpair('{{', '', '}}', 'bWr') ||
|
||||||
|
\ searchpair('<?', '', '?>', 'bWr') ||
|
||||||
|
\ searchpair('@php\%(\s*(\)\@!', '', '@endphp', 'bWr') )
|
||||||
|
execute 'let hindent = ' . s:phpindent
|
||||||
|
else
|
||||||
|
execute 'let hindent = ' . s:htmlindent
|
||||||
|
endif
|
||||||
|
if hindent > -1
|
||||||
|
let indent = hindent
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
let increase = indent + &sw
|
||||||
|
|
||||||
|
if line =~# '@\%(section\)\%(.*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
|
||||||
|
return indent
|
||||||
|
elseif line =~# '@\%(' . s:directives_start . '\)\%(.*@end\|.*@stop\)\@!' ||
|
||||||
|
\ line =~# '{{\%(.*}}\)\@!' || line =~# '{!!\%(.*!!}\)\@!'
|
||||||
|
return increase
|
||||||
|
else
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'clojure') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'clojure') == -1
|
||||||
|
|
||||||
" Vim indent file
|
" Vim indent file
|
||||||
" Language: Clojure
|
" Language: Clojure
|
||||||
" Author: Meikel Brandmeyer <mb@kotka.de>
|
" Author: Meikel Brandmeyer <mb@kotka.de>
|
||||||
" URL: http://kotka.de/projects/clojure/vimclojure.html
|
" URL: http://kotka.de/projects/clojure/vimclojure.html
|
||||||
"
|
"
|
||||||
" Maintainer: Sung Pae <self@sungpae.com>
|
" Maintainer: Sung Pae <self@sungpae.com>
|
||||||
" URL: https://github.com/guns/vim-clojure-static
|
" URL: https://github.com/guns/vim-clojure-static
|
||||||
" License: Same as Vim
|
" License: Same as Vim
|
||||||
" Last Change: %%RELEASE_DATE%%
|
" Last Change: %%RELEASE_DATE%%
|
||||||
|
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
@@ -79,8 +79,8 @@ if exists("*searchpairpos")
|
|||||||
" patterns.
|
" patterns.
|
||||||
function! s:match_one(patterns, string)
|
function! s:match_one(patterns, string)
|
||||||
let list = type(a:patterns) == type([])
|
let list = type(a:patterns) == type([])
|
||||||
\ ? a:patterns
|
\ ? a:patterns
|
||||||
\ : map(split(a:patterns, ','), '"^" . v:val . "$"')
|
\ : map(split(a:patterns, ','), '"^" . v:val . "$"')
|
||||||
for pat in list
|
for pat in list
|
||||||
if a:string =~# pat | return 1 | endif
|
if a:string =~# pat | return 1 | endif
|
||||||
endfor
|
endfor
|
||||||
@@ -189,6 +189,16 @@ if exists("*searchpairpos")
|
|||||||
return val
|
return val
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Check if form is a reader conditional, that is, it is prefixed by #?
|
||||||
|
" or @#?
|
||||||
|
function! s:is_reader_conditional_special_case(position)
|
||||||
|
if getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?"
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Returns 1 for opening brackets, -1 for _anything else_.
|
" Returns 1 for opening brackets, -1 for _anything else_.
|
||||||
function! s:bracket_type(char)
|
function! s:bracket_type(char)
|
||||||
return stridx('([{', a:char) > -1 ? 1 : -1
|
return stridx('([{', a:char) > -1 ? 1 : -1
|
||||||
@@ -256,6 +266,10 @@ if exists("*searchpairpos")
|
|||||||
return [paren[0], paren[1] + &shiftwidth - 1]
|
return [paren[0], paren[1] + &shiftwidth - 1]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if s:is_reader_conditional_special_case(paren)
|
||||||
|
return paren
|
||||||
|
endif
|
||||||
|
|
||||||
" In case we are at the last character, we use the paren position.
|
" In case we are at the last character, we use the paren position.
|
||||||
if col("$") - 1 == paren[1]
|
if col("$") - 1 == paren[1]
|
||||||
return paren
|
return paren
|
||||||
|
|||||||
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 line = getline(prevnonblank(v:lnum-1))
|
||||||
let cline = getline(v:lnum)
|
let cline = getline(v:lnum)
|
||||||
let nline = getline(nextnonblank(v:lnum+1))
|
let nline = getline(nextnonblank(v:lnum+1))
|
||||||
|
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||||
let syn = s:syn(prevnonblank(v:lnum-1))
|
let syn = s:syn(prevnonblank(v:lnum-1))
|
||||||
let csyn = s:syn(v:lnum)
|
let csyn = s:syn(v:lnum)
|
||||||
let nsyn = s:syn(nextnonblank(v:lnum+1))
|
let nsyn = s:syn(nextnonblank(v:lnum+1))
|
||||||
@@ -37,38 +38,38 @@ function! GetCucumberIndent()
|
|||||||
return 0
|
return 0
|
||||||
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
|
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
|
||||||
" examples heading
|
" examples heading
|
||||||
return 2 * &sw
|
return 2 * sw
|
||||||
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||||
" background, scenario or outline heading
|
" background, scenario or outline heading
|
||||||
return &sw
|
return sw
|
||||||
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
|
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
|
||||||
" line after feature heading
|
" line after feature heading
|
||||||
return &sw
|
return sw
|
||||||
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
|
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
|
||||||
" line after examples heading
|
" line after examples heading
|
||||||
return 3 * &sw
|
return 3 * sw
|
||||||
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||||
" line after background, scenario or outline heading
|
" 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)
|
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
|
||||||
" tag or comment before a feature heading
|
" tag or comment before a feature heading
|
||||||
return 0
|
return 0
|
||||||
elseif cline =~# '^\s*@'
|
elseif cline =~# '^\s*@'
|
||||||
" other tags
|
" other tags
|
||||||
return &sw
|
return sw
|
||||||
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
|
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
|
||||||
" mid-table
|
" mid-table
|
||||||
" preserve indent
|
" preserve indent
|
||||||
return indent(prevnonblank(v:lnum-1))
|
return indent(prevnonblank(v:lnum-1))
|
||||||
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
|
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
|
||||||
" first line of a table, relative indent
|
" 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*|'
|
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
|
||||||
" line after a table, relative unindent
|
" 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\):')
|
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
|
||||||
" comments on scenarios
|
" comments on scenarios
|
||||||
return &sw
|
return sw
|
||||||
endif
|
endif
|
||||||
return indent(prevnonblank(v:lnum-1))
|
return indent(prevnonblank(v:lnum-1))
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
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")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
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")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
@@ -13,7 +8,7 @@ let b:did_indent = 1
|
|||||||
setlocal nosmartindent
|
setlocal nosmartindent
|
||||||
|
|
||||||
setlocal indentexpr=GetElixirIndent()
|
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")
|
if exists("*GetElixirIndent")
|
||||||
finish
|
finish
|
||||||
@@ -22,27 +17,41 @@ endif
|
|||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
let s:no_colon_before = ':\@<!'
|
||||||
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" . s:skip_syntax . "'"
|
let s:no_colon_after = ':\@!'
|
||||||
let s:block_start = 'do\|fn'
|
let s:symbols_end = '\]\|}\|)'
|
||||||
let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
|
let s:symbols_start = '\[\|{\|('
|
||||||
let s:block_end = 'end'
|
let s:arrow = '^.*->$'
|
||||||
let s:symbols_end = '\]\|}'
|
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||||
let s:arrow = '^.*->$'
|
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:skip_syntax."'"
|
||||||
let s:pipeline = '^\s*|>.*$'
|
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: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: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()
|
function! GetElixirIndent()
|
||||||
let lnum = prevnonblank(v:lnum - 1)
|
let lnum = prevnonblank(v:lnum - 1)
|
||||||
let ind = indent(lnum)
|
|
||||||
|
|
||||||
" At the start of the file use zero indent.
|
" At the start of the file use zero indent.
|
||||||
if lnum == 0
|
if lnum == 0
|
||||||
return 0
|
return 0
|
||||||
endif
|
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
|
" TODO: Remove these 2 lines
|
||||||
" I don't know why, but for the test on spec/indent/lists_spec.rb:24.
|
" 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
|
" Vim is making some mess on parsing the syntax of 'end', it is being
|
||||||
@@ -52,58 +61,71 @@ function! GetElixirIndent()
|
|||||||
syntax sync fromstart
|
syntax sync fromstart
|
||||||
|
|
||||||
if synIDattr(synID(v:lnum, 1, 1), "name") !~ s:skip_syntax
|
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')
|
if last_line !~ s:arrow
|
||||||
let opened_symbol = 0
|
let split_line = split(last_line, '\zs')
|
||||||
let opened_symbol += count(splited_line, '[') - count(splited_line, ']')
|
let opened_symbol += count(split_line, '(') - count(split_line, ')')
|
||||||
let opened_symbol += count(splited_line, '{') - count(splited_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
|
let ind += &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if current_line =~ '^\s*\(' . s:symbols_end . '\)'
|
if current_line =~ '^\s*\('.s:symbols_end.'\)'
|
||||||
let ind -= &sw
|
let ind -= &sw
|
||||||
endif
|
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
|
let ind += &sw
|
||||||
endif
|
end
|
||||||
|
|
||||||
" if line starts with pipeline
|
" if line starts with pipeline
|
||||||
" and last line contains pipeline(s)
|
" and last line ends with a pipeline,
|
||||||
" align them
|
" align them
|
||||||
if last_line =~ '|>.*$' &&
|
if last_line =~ '|>.*$' &&
|
||||||
\ current_line =~ s:pipeline
|
\ current_line =~ s:starts_with_pipeline
|
||||||
let ind = float2nr(match(last_line, '|>') / &sw) * &sw
|
let ind = float2nr(match(last_line, '|>') / &sw) * &sw
|
||||||
|
|
||||||
" if line starts with pipeline
|
" if line starts with pipeline
|
||||||
" and last line is an attribution
|
" and last line is an attribution
|
||||||
" indents pipeline in same level as attribution
|
" indents pipeline in same level as attribution
|
||||||
elseif current_line =~ s:pipeline &&
|
elseif current_line =~ s:starts_with_pipeline &&
|
||||||
\ last_line =~ '^[^=]\+=.\+$'
|
\ 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
|
let ind = float2nr(matchend(last_line, '=\s*[^ ]') / &sw) * &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" if last line starts with pipeline
|
" if last line starts with pipeline
|
||||||
" and current line doesn't start with pipeline
|
" and current line doesn't start with pipeline
|
||||||
" returns the indentation before the pipeline
|
" returns the indentation before the pipeline
|
||||||
if last_line =~ s:pipeline &&
|
if last_line =~ s:starts_with_pipeline &&
|
||||||
\ current_line !~ s:pipeline
|
\ current_line !~ s:starts_with_pipeline
|
||||||
let ind = b:old_ind
|
let ind = b:old_ind
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if current_line =~ s:deindent_keywords
|
if current_line =~ s:deindent_keywords
|
||||||
let bslnum = searchpair( '\<\%(' . s:block_start . '\):\@!\>',
|
let bslnum = searchpair(
|
||||||
\ '\<\%(' . s:block_middle . '\):\@!\>\zs',
|
\ s:pair_start,
|
||||||
\ '\<:\@<!' . s:block_end . '\>\zs',
|
\ s:pair_middle,
|
||||||
|
\ s:pair_end,
|
||||||
\ 'nbW',
|
\ 'nbW',
|
||||||
\ s:block_skip )
|
\ s:block_skip
|
||||||
|
\ )
|
||||||
|
|
||||||
let ind = indent(bslnum)
|
let ind = indent(bslnum)
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emberscript') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emberscript') == -1
|
||||||
|
|
||||||
" Language: ember-script
|
" Language: ember-script
|
||||||
" Maintainer: heartsentwined <heartsentwined@cogito-lab.com>
|
" Maintainer: Yulij Andreevich Lesov <yalesov@gmail.com>>
|
||||||
" URL: http://github.com/heartsentwined/vim-ember-script
|
" URL: http://github.com/yalesov/vim-ember-script
|
||||||
" Version: 1.0.1
|
" Version: 1.0.4
|
||||||
" Last Change: 2013 Apr 17
|
" Last Change: 2016 Jul 6
|
||||||
" License: GPL-3.0
|
" License: ISC
|
||||||
|
|
||||||
if exists('b:did_indent')
|
if exists('b:did_indent')
|
||||||
finish
|
finish
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emblem') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'emblem') == -1
|
||||||
|
|
||||||
" Language: emblem
|
" Language: emblem
|
||||||
" Maintainer: heartsentwined <heartsentwined@cogito-lab.com>
|
" Maintainer: Yulij Andreevich Lesov <yalesov@gmail.com>
|
||||||
" URL: http://github.com/heartsentwined/vim-emblem
|
" URL: http://github.com/yalesov/vim-emblem
|
||||||
" Version: 1.2.0
|
" Version: 2.0.1
|
||||||
" Last Change: 2013 Apr 22
|
" Last Change: 2016 Jul 6
|
||||||
" License: GPL-3.0
|
" License: ISC
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ function! GetErubyIndent(...)
|
|||||||
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
||||||
let ind = ind + sw
|
let ind = ind + sw
|
||||||
endif
|
endif
|
||||||
if line !~# '^\s*<%' && line =~# '%>\s*$'
|
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
||||||
let ind = ind - sw
|
let ind = ind - sw
|
||||||
endif
|
endif
|
||||||
if cline =~# '^\s*[-=]\=%>\s*$'
|
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
|
" Vim indent file
|
||||||
" Language: git config file
|
" Language: git config file
|
||||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||||
" Last Change: 2012 April 7
|
" Last Change: 2013 May 30
|
||||||
|
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
@@ -22,17 +22,18 @@ if exists("*GetGitconfigIndent")
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
function! GetGitconfigIndent()
|
function! GetGitconfigIndent()
|
||||||
|
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||||
let line = getline(prevnonblank(v:lnum-1))
|
let line = getline(prevnonblank(v:lnum-1))
|
||||||
let cline = getline(v:lnum)
|
let cline = getline(v:lnum)
|
||||||
if line =~ '\\\@<!\%(\\\\\)*\\$'
|
if line =~ '\\\@<!\%(\\\\\)*\\$'
|
||||||
" odd number of slashes, in a line continuation
|
" odd number of slashes, in a line continuation
|
||||||
return 2 * &sw
|
return 2 * sw
|
||||||
elseif cline =~ '^\s*\['
|
elseif cline =~ '^\s*\['
|
||||||
return 0
|
return 0
|
||||||
elseif cline =~ '^\s*\a'
|
elseif cline =~ '^\s*\a'
|
||||||
return &sw
|
return sw
|
||||||
elseif cline == '' && line =~ '^\['
|
elseif cline == '' && line =~ '^\['
|
||||||
return &sw
|
return sw
|
||||||
else
|
else
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
|
|||||||
" - general line splits (line ends in an operator)
|
" - general line splits (line ends in an operator)
|
||||||
|
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
@@ -23,60 +23,60 @@ setlocal indentexpr=GoIndent(v:lnum)
|
|||||||
setlocal indentkeys+=<:>,0=},0=)
|
setlocal indentkeys+=<:>,0=},0=)
|
||||||
|
|
||||||
if exists("*GoIndent")
|
if exists("*GoIndent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" use shiftwidth function only if it's available
|
" use shiftwidth function only if it's available
|
||||||
if exists('*shiftwidth')
|
if exists('*shiftwidth')
|
||||||
func s:sw()
|
func s:sw()
|
||||||
return shiftwidth()
|
return shiftwidth()
|
||||||
endfunc
|
endfunc
|
||||||
else
|
else
|
||||||
func s:sw()
|
func s:sw()
|
||||||
return &sw
|
return &sw
|
||||||
endfunc
|
endfunc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! GoIndent(lnum)
|
function! GoIndent(lnum)
|
||||||
let prevlnum = prevnonblank(a:lnum-1)
|
let prevlnum = prevnonblank(a:lnum-1)
|
||||||
if prevlnum == 0
|
if prevlnum == 0
|
||||||
" top of file
|
" top of file
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" grab the previous and current line, stripping comments.
|
" grab the previous and current line, stripping comments.
|
||||||
let prevl = substitute(getline(prevlnum), '//.*$', '', '')
|
let prevl = substitute(getline(prevlnum), '//.*$', '', '')
|
||||||
let thisl = substitute(getline(a:lnum), '//.*$', '', '')
|
let thisl = substitute(getline(a:lnum), '//.*$', '', '')
|
||||||
let previ = indent(prevlnum)
|
let previ = indent(prevlnum)
|
||||||
|
|
||||||
let ind = previ
|
let ind = previ
|
||||||
|
|
||||||
if prevl =~ '[({]\s*$'
|
if prevl =~ '[({]\s*$'
|
||||||
" previous line opened a block
|
" previous line opened a block
|
||||||
let ind += s:sw()
|
let ind += s:sw()
|
||||||
endif
|
endif
|
||||||
if prevl =~# '^\s*\(case .*\|default\):$'
|
if prevl =~# '^\s*\(case .*\|default\):$'
|
||||||
" previous line is part of a switch statement
|
" previous line is part of a switch statement
|
||||||
let ind += s:sw()
|
let ind += s:sw()
|
||||||
endif
|
endif
|
||||||
" TODO: handle if the previous line is a label.
|
" TODO: handle if the previous line is a label.
|
||||||
|
|
||||||
if thisl =~ '^\s*[)}]'
|
if thisl =~ '^\s*[)}]'
|
||||||
" this line closed a block
|
" this line closed a block
|
||||||
let ind -= s:sw()
|
let ind -= s:sw()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Colons are tricky.
|
" Colons are tricky.
|
||||||
" We want to outdent if it's part of a switch ("case foo:" or "default:").
|
" We want to outdent if it's part of a switch ("case foo:" or "default:").
|
||||||
" We ignore trying to deal with jump labels because (a) they're rare, and
|
" We ignore trying to deal with jump labels because (a) they're rare, and
|
||||||
" (b) they're hard to disambiguate from a composite literal key.
|
" (b) they're hard to disambiguate from a composite literal key.
|
||||||
if thisl =~# '^\s*\(case .*\|default\):$'
|
if thisl =~# '^\s*\(case .*\|default\):$'
|
||||||
let ind -= s:sw()
|
let ind -= s:sw()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" vim:ts=4:sw=4:et
|
" vim: sw=2 ts=2 et
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -6,4 +6,45 @@ endif
|
|||||||
|
|
||||||
runtime! indent/html.vim
|
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
|
||||||
|
|
||||||
|
" vim: sw=2 ts=2 et
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -39,10 +39,11 @@ function! GetHamlIndent()
|
|||||||
let line = substitute(line,'^\s\+','','')
|
let line = substitute(line,'^\s\+','','')
|
||||||
let indent = indent(lnum)
|
let indent = indent(lnum)
|
||||||
let cindent = indent(v:lnum)
|
let cindent = indent(v:lnum)
|
||||||
|
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||||
if cline =~# '\v^-\s*%(elsif|else|when)>'
|
if cline =~# '\v^-\s*%(elsif|else|when)>'
|
||||||
let indent = cindent < indent ? cindent : indent - &sw
|
let indent = cindent < indent ? cindent : indent - sw
|
||||||
endif
|
endif
|
||||||
let increase = indent + &sw
|
let increase = indent + sw
|
||||||
if indent == indent(lnum)
|
if indent == indent(lnum)
|
||||||
let indent = cindent <= indent ? -1 : increase
|
let indent = cindent <= indent ? -1 : increase
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
|||||||
|
|
||||||
" indentation for haskell
|
" indentation for haskell
|
||||||
"
|
"
|
||||||
" Based on idris indentation
|
|
||||||
"
|
|
||||||
" author: raichoo (raichoo@googlemail.com)
|
" author: raichoo (raichoo@googlemail.com)
|
||||||
"
|
"
|
||||||
" Modify g:haskell_indent_if and g:haskell_indent_case to
|
" Modify g:haskell_indent_if and g:haskell_indent_case to
|
||||||
@@ -18,7 +16,7 @@ endif
|
|||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
if !exists('g:haskell_indent_if')
|
if !exists('g:haskell_indent_if')
|
||||||
" if bool
|
" if x
|
||||||
" >>>then ...
|
" >>>then ...
|
||||||
" >>>else ...
|
" >>>else ...
|
||||||
let g:haskell_indent_if = 3
|
let g:haskell_indent_if = 3
|
||||||
@@ -55,96 +53,128 @@ if !exists('g:haskell_indent_in')
|
|||||||
let g:haskell_indent_in = 1
|
let g:haskell_indent_in = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !exists('g:haskell_indent_guard')
|
||||||
|
" f x y
|
||||||
|
" >>|
|
||||||
|
let g:haskell_indent_guard = 2
|
||||||
|
endif
|
||||||
|
|
||||||
setlocal indentexpr=GetHaskellIndent()
|
setlocal indentexpr=GetHaskellIndent()
|
||||||
setlocal indentkeys=!^F,o,O,0\|,0=where,0=in,0=let,0=deriving,0=->,0=\=>,<CR>,0}
|
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()
|
function! GetHaskellIndent()
|
||||||
let l:prevline = getline(v:lnum - 1)
|
let l:hlstack = s:getHLStack()
|
||||||
|
|
||||||
|
" do not indent in strings and quasiquotes
|
||||||
|
if index(l:hlstack, 'haskellQuasiQuote') > -1 || index(l:hlstack, 'haskellBlockComment') > -1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:prevline = getline(v:lnum - 1)
|
||||||
|
let l:line = getline(v:lnum)
|
||||||
|
|
||||||
|
" indent multiline strings
|
||||||
|
if index(l:hlstack, 'haskellString') > -1
|
||||||
|
if l:line =~ '^\s*\\'
|
||||||
|
return match(l:prevline, '["\\]')
|
||||||
|
else
|
||||||
|
return - 1
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" reset
|
||||||
|
if l:prevline =~ '^\s*$' && l:line !~ '^\s*\S'
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
" comment indentation
|
||||||
if l:prevline =~ '^\s*--'
|
if l:prevline =~ '^\s*--'
|
||||||
return match(l:prevline, '\S')
|
return match(l:prevline, '\S')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if synIDattr(synID(line("."), col("."), 1), "name") == 'haskellBlockComment'
|
" operator at end of previous line
|
||||||
for l:c in range(v:lnum - 1, 0, -1)
|
if l:prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
|
||||||
let l:bline = getline(l:c)
|
return match(l:prevline, '\S') + &shiftwidth
|
||||||
if l:bline =~ '{-'
|
|
||||||
return 1 + match(l:bline, '{-')
|
|
||||||
endfor
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:prevline =~ '^\s*$'
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:line = getline(v:lnum)
|
|
||||||
|
|
||||||
if l:line =~ '\C^\s*\<where\>'
|
|
||||||
let l:s = match(l:prevline, '\S')
|
|
||||||
return l:s + &shiftwidth
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:line =~ '\C^\s*\<deriving\>'
|
|
||||||
let l:s = match(l:prevline, '\C\<\(newtype\|data\)\>')
|
|
||||||
if l:s >= 0
|
|
||||||
return l:s + &shiftwidth
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:line =~ '\C^\s*\<let\>'
|
|
||||||
let l:s = match(l:prevline, '\C\<let\>')
|
|
||||||
if l:s != 0
|
|
||||||
return l:s
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:line =~ '\C^\s*\<in\>'
|
|
||||||
let l:s = match(l:prevline, '\C\<let\>')
|
|
||||||
if l:s >= 0
|
|
||||||
return l:s + g:haskell_indent_in
|
|
||||||
elseif match(l:prevline, '=') > 0
|
|
||||||
let l:s = match(l:prevline, '\S')
|
|
||||||
return l:s - (4 - g:haskell_indent_in)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:line =~ '^\s*|'
|
|
||||||
if match(l:prevline, '^\s*data') < 0
|
|
||||||
if match(l:prevline, '^\s*|\s') >= 0
|
|
||||||
return match(l:prevline, '|')
|
|
||||||
else
|
|
||||||
return &shiftwidth
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:line =~ '^\s*[=-]>'
|
|
||||||
let l:s = match(l:prevline, ' :: ')
|
|
||||||
if l:s >= 0
|
|
||||||
return l:s + 1
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:prevline =~ '\s\+[!#$%&*+./<>?@\\^|~-]\+\s*$'
|
|
||||||
let l:s = match(l:prevline, '\S')
|
|
||||||
if l:s > 0
|
|
||||||
return l:s + &shiftwidth
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:prevline =~ '[{([][^})\]]\+$'
|
|
||||||
return match(l:prevline, '[{([]')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" let foo =
|
||||||
|
" >>>>>>bar
|
||||||
if l:prevline =~ '\C\<let\>\s\+[^=]\+=\s*$'
|
if l:prevline =~ '\C\<let\>\s\+[^=]\+=\s*$'
|
||||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let + &shiftwidth
|
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let + &shiftwidth
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:prevline =~ '\C\<let\>\s\+.\+\(\<in\>\)\?\s*$'
|
" 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
|
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let
|
||||||
endif
|
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\>'
|
if l:prevline !~ '\C\<else\>'
|
||||||
let l:s = match(l:prevline, '\C\<if\>.*\&.*\zs\<then\>')
|
let l:s = match(l:prevline, '\C\<if\>.*\&.*\zs\<then\>')
|
||||||
if l:s > 0
|
if l:s > 0
|
||||||
@@ -157,30 +187,255 @@ function! GetHaskellIndent()
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
|
" where
|
||||||
|
" >>foo
|
||||||
|
"
|
||||||
|
" do
|
||||||
|
" >>foo
|
||||||
|
"
|
||||||
|
" foo =
|
||||||
|
" >>bar
|
||||||
|
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\)\s*$'
|
||||||
return match(l:prevline, '\S') + &shiftwidth
|
return match(l:prevline, '\S') + &shiftwidth
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"" where foo
|
||||||
|
"" >>>>>>bar
|
||||||
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
||||||
return match(l:prevline, '\C\<where\>') + g:haskell_indent_where
|
if l:line =~ '^\s*[=-]>\s' && l:prevline =~ ' :: '
|
||||||
|
return match(l:prevline, ':: ')
|
||||||
|
else
|
||||||
|
return match(l:prevline, '\C\<where\>') + g:haskell_indent_where
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" do foo
|
||||||
|
" >>>bar
|
||||||
if l:prevline =~ '\C\<do\>\s\+\S\+.*$'
|
if l:prevline =~ '\C\<do\>\s\+\S\+.*$'
|
||||||
return match(l:prevline, '\C\<do\>') + g:haskell_indent_do
|
return match(l:prevline, '\C\<do\>') + g:haskell_indent_do
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:prevline =~ '\C^\s*\<data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
|
" case foo of
|
||||||
if l:line =~ '^\s*|'
|
" >>bar -> quux
|
||||||
return match(l:prevline, '=')
|
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if l:prevline =~ '\C\<case\>\s\+.\+\<of\>\s*$'
|
|
||||||
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
|
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:prevline =~ '\C^\s*\<\data\>\s\+\S\+\s*$'
|
" newtype Foo = Foo
|
||||||
return match(l:prevline, '\C\<data\>') + &shiftwidth
|
" >>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
|
endif
|
||||||
|
|
||||||
return match(l:prevline, '\S')
|
return match(l:prevline, '\S')
|
||||||
|
|||||||
@@ -177,7 +177,24 @@ call add(s:tags, 'tr')
|
|||||||
call add(s:tags, 'th')
|
call add(s:tags, 'th')
|
||||||
call add(s:tags, 'td')
|
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 = [
|
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'],
|
\ ['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'],
|
\ ['th', 'td'],
|
||||||
\]
|
\]
|
||||||
|
|
||||||
|
|
||||||
|
let s:html_noindent_tags = join(s:no_tags, '\|')
|
||||||
|
|
||||||
if exists('g:html_exclude_tags')
|
if exists('g:html_exclude_tags')
|
||||||
for tag in g:html_exclude_tags
|
for tag in g:html_exclude_tags
|
||||||
call remove(s:tags, index(s:tags, tag))
|
call remove(s:tags, index(s:tags, tag))
|
||||||
endfor
|
endfor
|
||||||
|
let s:html_noindent_tags = s:html_noindent_tags.'\|'.join(g:html_exclude_tags, '\|')
|
||||||
endif
|
endif
|
||||||
let s:html_indent_tags = join(s:tags, '\|')
|
|
||||||
let s:html_indent_tags = s:html_indent_tags.'\|\w\+\(-\w\+\)\+'
|
" let s:html_indent_tags = join(s:tags, '\|')
|
||||||
if exists('g:html_indent_tags')
|
let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
|
||||||
let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
" if exists('g:html_indent_tags')
|
||||||
endif
|
" let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
||||||
|
" endif
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo-=C
|
set cpo-=C
|
||||||
@@ -231,8 +253,8 @@ endfun
|
|||||||
fun! <SID>HtmlIndentSum(lnum, style)
|
fun! <SID>HtmlIndentSum(lnum, style)
|
||||||
if a:style == match(getline(a:lnum), '^\s*</')
|
if a:style == match(getline(a:lnum), '^\s*</')
|
||||||
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
|
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
|
||||||
let open = <SID>HtmlIndentOpen(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)
|
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
|
||||||
if 0 != open || 0 != close
|
if 0 != open || 0 != close
|
||||||
return open - close
|
return open - close
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ setlocal nosmartindent
|
|||||||
" Now, set up our indentation expression and keys that trigger it.
|
" Now, set up our indentation expression and keys that trigger it.
|
||||||
setlocal indentexpr=GetJavascriptIndent()
|
setlocal indentexpr=GetJavascriptIndent()
|
||||||
setlocal formatexpr=Fixedgq(v:lnum,v:count)
|
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\,*<Return>,:,!^F,o,O,e
|
||||||
|
setlocal cinoptions+=j1,J1,c1
|
||||||
|
|
||||||
" Only define the function once.
|
" Only define the function once.
|
||||||
if exists("*GetJavascriptIndent")
|
if exists("*GetJavascriptIndent")
|
||||||
@@ -28,47 +29,75 @@ endif
|
|||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
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
|
" 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:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*'
|
||||||
|
let s:js_keywords = s:line_pre . '\%(break\|import\|export\|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\)\>\C'
|
||||||
|
let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C'
|
||||||
" Regex of syntax group names that are or delimit string or are comments.
|
" 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 = '\%(string\|regex\|special\|doc\|comment\|template\)\c'
|
||||||
|
|
||||||
" Regex of syntax group names that are strings.
|
" Regex of syntax group names that are strings.
|
||||||
let s:syng_string = 'regex\c'
|
let s:syng_string = 'regex\c'
|
||||||
|
|
||||||
" Regex of syntax group names that are strings or documentation.
|
" Regex of syntax group names that are strings or documentation.
|
||||||
let s:syng_multiline = 'comment\c'
|
let s:syng_comment = '\%(comment\|doc\)\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().
|
" 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:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
|
||||||
|
|
||||||
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
|
func s:lookForParens(start,end,flags,stop)
|
||||||
|
try
|
||||||
|
return searchpair(a:start,'',a:end,a:flags,s:skip_expr,a:stop,300)
|
||||||
|
catch /E118/
|
||||||
|
return searchpair(a:start,'',a:end,a:flags,0,a:stop)
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
let s:line_term = '\s*\%(\%(\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$'
|
||||||
|
|
||||||
" Regex that defines continuation lines, not including (, {, or [.
|
" Regex that defines continuation lines, not including (, {, or [.
|
||||||
let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]=[^=].*,\)' . s:line_term
|
let s:continuation_regex = '\%([*.?:]\|+\@<!+\|-\@<!-\|\*\@<!\/\|=\|||\|&&\)' . s:line_term
|
||||||
|
|
||||||
" Regex that defines continuation lines.
|
let s:one_line_scope_regex = '\%(\<else\>\|=>\)\C' . s:line_term
|
||||||
" 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
|
function s:Onescope(lnum)
|
||||||
|
if getline(a:lnum) =~ s:one_line_scope_regex
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
let mypos = col('.')
|
||||||
|
call cursor(a:lnum, 1)
|
||||||
|
if search('.*\zs\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 &&
|
||||||
|
\ s:lookForParens('(', ')', 'W', a:lnum) > 0 &&
|
||||||
|
\ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum)))
|
||||||
|
call cursor(a:lnum, mypos)
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
call cursor(a:lnum, mypos)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Regex that defines blocks.
|
" Regex that defines blocks.
|
||||||
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
let s:block_regex = '[{([]' . s:line_term
|
||||||
|
|
||||||
let s:var_stmt = '^\s*var'
|
let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
|
||||||
|
|
||||||
let s:comma_first = '^\s*,'
|
let s:var_stmt = s:line_pre . '\%(const\|let\|var\)\s\+\C'
|
||||||
let s:comma_last = ',\s*$'
|
|
||||||
|
|
||||||
let s:ternary = '^\s\+[?|:]'
|
let s:comma_last = ',' . s:line_term
|
||||||
let s:ternary_q = '^\s\+?'
|
|
||||||
|
|
||||||
" 2. Auxiliary Functions {{{1
|
" 2. Auxiliary Functions {{{1
|
||||||
" ======================
|
" ======================
|
||||||
@@ -84,32 +113,23 @@ function s:IsInString(lnum, col)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Check if the character at lnum:col is inside a multi-line comment.
|
" Check if the character at lnum:col is inside a multi-line comment.
|
||||||
function s:IsInMultilineComment(lnum, col)
|
function s:IsInComment(lnum, col)
|
||||||
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
|
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment
|
||||||
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
|
endfunction
|
||||||
|
|
||||||
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
||||||
function s:PrevNonBlankNonString(lnum)
|
function s:PrevNonBlankNonString(lnum)
|
||||||
let in_block = 0
|
|
||||||
let lnum = prevnonblank(a:lnum)
|
let lnum = prevnonblank(a:lnum)
|
||||||
while lnum > 0
|
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)
|
let line = getline(lnum)
|
||||||
if line =~ '/\*'
|
let com = match(line, '\%(\/\*.*\)\@<!\*\/') + 1
|
||||||
if in_block
|
if s:IsInComment(lnum, com)
|
||||||
let in_block = 0
|
call cursor(lnum, com)
|
||||||
else
|
let parlnum = search('\%(\/\/.*\)\@<!\/\*', 'nbW')
|
||||||
break
|
if parlnum > 0
|
||||||
endif
|
let lnum = parlnum
|
||||||
elseif !in_block && line =~ '\*/'
|
end
|
||||||
let in_block = 1
|
elseif line !~ '^' . s:line_term && !s:IsInStringOrComment(lnum,1)
|
||||||
elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
|
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
let lnum = prevnonblank(lnum - 1)
|
let lnum = prevnonblank(lnum - 1)
|
||||||
@@ -122,87 +142,89 @@ function s:GetMSL(lnum, in_one_line_scope)
|
|||||||
" Start on the line we're at and use its indent.
|
" Start on the line we're at and use its indent.
|
||||||
let msl = a:lnum
|
let msl = a:lnum
|
||||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||||
while lnum > 0
|
while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]')
|
||||||
" If we have a continuation line, or we're in a string, use line as MSL.
|
" 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.
|
" Otherwise, terminate search as we have found our MSL already.
|
||||||
let line = getline(lnum)
|
let line = getline(lnum)
|
||||||
let col = match(line, s:msl_regex) + 1
|
let line2 = getline(msl)
|
||||||
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
|
if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) &&
|
||||||
|
\ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line))
|
||||||
let msl = lnum
|
let msl = lnum
|
||||||
|
if s:Match(lnum, s:line_pre . '[]})]') && !a:in_one_line_scope
|
||||||
|
call cursor(lnum,1)
|
||||||
|
let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
|
||||||
|
if parlnum > 0
|
||||||
|
let lnum = parlnum
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
" Don't use lines that are part of a one line scope as msl unless the
|
" 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
|
" flag in_one_line_scope is set to 1
|
||||||
"
|
"
|
||||||
if a:in_one_line_scope
|
if a:in_one_line_scope
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
let msl_one_line = s:Match(lnum, s:one_line_scope_regex)
|
let msl_one_line = s:Onescope(lnum)
|
||||||
if msl_one_line == 0
|
if msl_one_line == 0
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endif
|
end
|
||||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||||
endwhile
|
endwhile
|
||||||
return msl
|
return msl
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function s:RemoveTrailingComments(content)
|
function s:RemoveTrailingComments(content)
|
||||||
let single = '\/\/\(.*\)\s*$'
|
let single = '\/\/\%(.*\)\s*$'
|
||||||
let multi = '\/\*\(.*\)\*\/\s*$'
|
let multi = '\/\*\%(.*\)\*\/\s*$'
|
||||||
return substitute(substitute(a:content, single, '', ''), multi, '', '')
|
return substitute(substitute(substitute(a:content, single, '', ''), multi, '', ''), '\s\+$', '', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Find if the string is inside var statement (but not the first string)
|
" Find if the string is inside var statement (but not the first string)
|
||||||
function s:InMultiVarStatement(lnum)
|
function s:InMultiVarStatement(lnum, cont, prev)
|
||||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||||
|
let cont = a:cont
|
||||||
|
let prev = a:prev
|
||||||
|
|
||||||
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
|
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
|
||||||
|
|
||||||
" loop through previous expressions to find a var statement
|
" loop through previous expressions to find a var statement
|
||||||
while lnum > 0
|
while lnum > 0 && (s:Match(lnum, s:comma_last) ||(cont && getline(lnum) =~ s:line_pre . '[]})]') ||
|
||||||
let line = getline(lnum)
|
\ s:Match(lnum,s:continuation_regex)) || (prev && (s:Match(prev, s:comma_last) ||
|
||||||
|
\ s:Match(prev,s:continuation_regex)))
|
||||||
" if the line is a js keyword
|
" if the line is a js keyword
|
||||||
if (line =~ s:js_keywords)
|
if cont
|
||||||
|
let cont = 0
|
||||||
|
call cursor(lnum,1)
|
||||||
|
let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
|
||||||
|
if parlnum > 0
|
||||||
|
let lnum = parlnum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if s:Match(lnum, s:js_keywords)
|
||||||
" check if the line is a var stmt
|
" check if the line is a var stmt
|
||||||
" if the line has a comma first or comma last then we can assume that we
|
" if the line has a comma first or comma last then we can assume that we
|
||||||
" are in a multiple var statement
|
" are in a multiple var statement
|
||||||
if (line =~ s:var_stmt)
|
if s:Match(lnum, s:var_stmt) && (s:Match(lnum, s:comma_last)||s:Match(lnum,s:continuation_regex))
|
||||||
return lnum
|
return lnum
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" other js keywords, not a var
|
" other js keywords, not a var
|
||||||
return 0
|
if !s:Match(lnum, s:comma_last)||!s:Match(lnum,s:continuation_regex)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||||
|
let prev = prev && lnum > 0 ? prev : 0
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
" beginning of program, not a var
|
" beginning of program, not a var
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
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.
|
" Check if line 'lnum' has more opening brackets than closing ones.
|
||||||
function s:LineHasOpeningBrackets(lnum)
|
function s:LineHasOpeningBrackets(lnum)
|
||||||
let open_0 = 0
|
let open_0 = 0
|
||||||
@@ -221,7 +243,7 @@ function s:LineHasOpeningBrackets(lnum)
|
|||||||
endif
|
endif
|
||||||
let pos = match(line, '[][(){}]', pos + 1)
|
let pos = match(line, '[][(){}]', pos + 1)
|
||||||
endwhile
|
endwhile
|
||||||
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
|
return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function s:Match(lnum, regex)
|
function s:Match(lnum, regex)
|
||||||
@@ -253,7 +275,9 @@ function s:IndentWithContinuation(lnum, ind, width)
|
|||||||
return msl_ind + a:width
|
return msl_ind + a:width
|
||||||
else
|
else
|
||||||
return msl_ind
|
return msl_ind
|
||||||
endif
|
end
|
||||||
|
elseif s:InMultiVarStatement(p_lnum, 0, s:PrevNonBlankNonString(p_lnum - 1))
|
||||||
|
return indent(p_lnum) - s:sw()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return a:ind
|
return a:ind
|
||||||
@@ -261,7 +285,7 @@ endfunction
|
|||||||
|
|
||||||
function s:InOneLineScope(lnum)
|
function s:InOneLineScope(lnum)
|
||||||
let msl = s:GetMSL(a:lnum, 1)
|
let msl = s:GetMSL(a:lnum, 1)
|
||||||
if msl > 0 && s:Match(msl, s:one_line_scope_regex)
|
if msl > 0 && s:Onescope(msl)
|
||||||
return msl
|
return msl
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
@@ -271,11 +295,11 @@ function s:ExitingOneLineScope(lnum)
|
|||||||
let msl = s:GetMSL(a:lnum, 1)
|
let msl = s:GetMSL(a:lnum, 1)
|
||||||
if msl > 0
|
if msl > 0
|
||||||
" if the current line is in a one line scope ..
|
" if the current line is in a one line scope ..
|
||||||
if s:Match(msl, s:one_line_scope_regex)
|
if s:Onescope(msl)
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
let prev_msl = s:GetMSL(msl - 1, 1)
|
let prev_msl = s:GetMSL(msl - 1, 1)
|
||||||
if s:Match(prev_msl, s:one_line_scope_regex)
|
if s:Onescope(prev_msl)
|
||||||
return prev_msl
|
return prev_msl
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -287,13 +311,13 @@ endfunction
|
|||||||
" =========================
|
" =========================
|
||||||
|
|
||||||
function GetJavascriptIndent()
|
function GetJavascriptIndent()
|
||||||
" 3.1. Setup {{{2
|
" 3.1. Setup {{{1
|
||||||
" ----------
|
" ----------
|
||||||
|
|
||||||
" Set up variables for restoring position in file. Could use v:lnum here.
|
" Set up variables for restoring position in file. Could use v:lnum here.
|
||||||
|
" Avoid use of line('.')/col('.') type functions as the curpos can change
|
||||||
let vcol = col('.')
|
let vcol = col('.')
|
||||||
|
|
||||||
" 3.2. Work on the current line {{{2
|
" 3.2. Work on the current line {{{1
|
||||||
" -----------------------------
|
" -----------------------------
|
||||||
|
|
||||||
let ind = -1
|
let ind = -1
|
||||||
@@ -301,81 +325,108 @@ function GetJavascriptIndent()
|
|||||||
let line = getline(v:lnum)
|
let line = getline(v:lnum)
|
||||||
" previous nonblank line number
|
" previous nonblank line number
|
||||||
let prevline = prevnonblank(v:lnum - 1)
|
let prevline = prevnonblank(v:lnum - 1)
|
||||||
|
" previous line of code
|
||||||
|
let lnum = s:PrevNonBlankNonString(v:lnum - 1)
|
||||||
|
|
||||||
" If we got a closing bracket on an empty line, find its match and indent
|
" to not change multiline string values
|
||||||
" according to it. For parentheses we indent to its column - 1, for the
|
if line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template'
|
||||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
return -1
|
||||||
let col = matchend(line, '^\s*[],})]')
|
|
||||||
if col > 0 && !s:IsInStringOrComment(v:lnum, col)
|
|
||||||
call cursor(v:lnum, col)
|
|
||||||
|
|
||||||
let lvar = s:InMultiVarStatement(v:lnum)
|
|
||||||
if lvar
|
|
||||||
let prevline_contents = s:RemoveTrailingComments(getline(prevline))
|
|
||||||
|
|
||||||
" 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
|
|
||||||
|
|
||||||
|
|
||||||
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
|
endif
|
||||||
|
|
||||||
" If we are in a multi-line comment, cindent does the right thing.
|
" If we are in a multi-line comment, cindent does the right thing.
|
||||||
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
|
if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)
|
||||||
return cindent(v:lnum)
|
return cindent(v:lnum)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Check for multiple var assignments
|
" single opening bracket will assume you want a c style of indenting
|
||||||
" let var_indent = s:GetVarIndent(v:lnum)
|
if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) &&
|
||||||
" if var_indent >= 0
|
\ !s:Match(lnum,s:comma_last)
|
||||||
" return var_indent
|
return cindent(v:lnum)
|
||||||
" endif
|
endif
|
||||||
|
|
||||||
" 3.3. Work on the previous line. {{{2
|
" cindent each line which has a switch label
|
||||||
|
if (line =~ s:expr_case)
|
||||||
|
let s:cpo_switch = &cpo
|
||||||
|
set cpo+=%
|
||||||
|
let ind = cindent(v:lnum)
|
||||||
|
let &cpo = s:cpo_switch
|
||||||
|
return ind
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If we got a closing bracket on an empty line, find its match and indent
|
||||||
|
" according to it.
|
||||||
|
let col = line =~ s:line_pre . '[]})]'
|
||||||
|
if col > 0
|
||||||
|
let parlnum = v:lnum
|
||||||
|
while col
|
||||||
|
call cursor(parlnum, 1)
|
||||||
|
let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
|
||||||
|
let col = s:Match(parlnum, s:line_pre . '[]})]')
|
||||||
|
if col
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
if parlnum > 0
|
||||||
|
let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ?
|
||||||
|
\ indent(parlnum) : indent(s:GetMSL(parlnum, 0))
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
return ind
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
" If line starts with an operator...
|
||||||
|
if (line =~ s:operator_first)
|
||||||
|
if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') &&
|
||||||
|
\ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term))))
|
||||||
|
" and so does previous line, don't indent
|
||||||
|
return indent(lnum)
|
||||||
|
end
|
||||||
|
let counts = s:LineHasOpeningBrackets(lnum)
|
||||||
|
if counts =~ '2'
|
||||||
|
call cursor(lnum, 1)
|
||||||
|
" Search for the opening tag
|
||||||
|
let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
|
||||||
|
if parlnum > 0
|
||||||
|
return !s:Match(parlnum, s:operator_first) &&
|
||||||
|
\ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' ?
|
||||||
|
\ indent(lnum) + s:sw() : indent(parlnum)
|
||||||
|
end
|
||||||
|
elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject'
|
||||||
|
" otherwise, if not in an key/val;array item;param, indent 1 level
|
||||||
|
return indent(lnum) + s:sw()
|
||||||
|
end
|
||||||
|
|
||||||
|
" If previous line starts with an operator...
|
||||||
|
elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) ||
|
||||||
|
\ getline(lnum) =~ '[]})];\=' . s:line_term
|
||||||
|
let counts = s:LineHasOpeningBrackets(lnum)
|
||||||
|
if counts =~ '2' && !s:Match(lnum, s:operator_first)
|
||||||
|
call cursor(lnum, 1)
|
||||||
|
" Search for the opening tag
|
||||||
|
let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
|
||||||
|
if mnum > 0 && (s:Match(mnum, s:operator_first) ||
|
||||||
|
\ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{'))
|
||||||
|
return indent(mnum) - s:sw()
|
||||||
|
end
|
||||||
|
elseif s:Match(lnum, s:operator_first)
|
||||||
|
if counts !~ '1'
|
||||||
|
return indent(lnum) - s:sw()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
" 3.3. Work on the previous line. {{{1
|
||||||
" -------------------------------
|
" -------------------------------
|
||||||
|
|
||||||
" If the line is empty and the previous nonblank line was a multi-line
|
" 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
|
" comment, use that comment's indent. Deduct one char to account for the
|
||||||
" space in ' */'.
|
" space in ' */'.
|
||||||
if line =~ '^\s*$' && s:IsInMultilineComment(prevline, 1)
|
if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
|
||||||
|
\ s:IsInComment(prevline, 1)
|
||||||
return indent(prevline) - 1
|
return indent(prevline) - 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Find a non-blank, non-multi-line string line above the current line.
|
" 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 the line is empty and inside a string, use the previous line.
|
||||||
if line =~ '^\s*$' && lnum != prevline
|
if line =~ '^\s*$' && lnum != prevline
|
||||||
@@ -387,48 +438,56 @@ function GetJavascriptIndent()
|
|||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" If the previous line ended with a block opening, add a level of indent.
|
||||||
|
if s:Match(lnum, s:block_regex)
|
||||||
|
return s:InMultiVarStatement(lnum, 0, 0) || s:LineHasOpeningBrackets(lnum) !~ '2' ?
|
||||||
|
\ indent(lnum) + s:sw() : indent(s:GetMSL(lnum, 0)) + s:sw()
|
||||||
|
endif
|
||||||
|
|
||||||
" Set up variables for current line.
|
" Set up variables for current line.
|
||||||
let line = getline(lnum)
|
let line = getline(lnum)
|
||||||
let ind = indent(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,
|
" If the previous line contained an opening bracket, and we are still in it,
|
||||||
" add indent depending on the bracket type.
|
" add indent depending on the bracket type.
|
||||||
if line =~ '[[({]'
|
if s:Match(lnum, '[[({})\]]')
|
||||||
let counts = s:LineHasOpeningBrackets(lnum)
|
let counts = s:LineHasOpeningBrackets(lnum)
|
||||||
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
if counts =~ '2'
|
||||||
if col('.') + 1 == col('$')
|
call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.*\zs[])}]'))
|
||||||
return ind + &sw
|
while s:lookForParens('(\|{\|\[', ')\|}\|\]', 'bW', 0) == lnum
|
||||||
else
|
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
|
||||||
return virtcol('.')
|
endwhile
|
||||||
endif
|
let cur = line('.')
|
||||||
elseif counts[1] == '1' || counts[2] == '1'
|
if cur < lnum && !s:InMultiVarStatement(cur,0,0)
|
||||||
return ind + &sw
|
return indent(s:GetMSL(cur, 0))
|
||||||
else
|
end
|
||||||
call cursor(v:lnum, vcol)
|
elseif counts =~ '1' || s:Onescope(lnum)
|
||||||
|
return ind + s:sw()
|
||||||
end
|
end
|
||||||
endif
|
end
|
||||||
|
|
||||||
" 3.4. Work on the MSL line. {{{2
|
" 3.4. Work on the MSL line. {{{1
|
||||||
" --------------------------
|
" --------------------------
|
||||||
|
if s:Match(lnum, s:comma_last) && !s:Match(lnum, s:continuation_regex)
|
||||||
|
return s:Match(lnum, s:var_stmt) ? indent(lnum) + s:sw() : indent(lnum)
|
||||||
|
|
||||||
|
elseif s:Match(s:PrevNonBlankNonString(lnum - 1), s:comma_last)
|
||||||
|
if !s:Match(lnum, s:comma_last) && s:InMultiVarStatement(lnum,1,0)
|
||||||
|
return indent(lnum) - s:sw()
|
||||||
|
end
|
||||||
|
end
|
||||||
let ind_con = ind
|
let ind_con = ind
|
||||||
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
|
let ind = s:IndentWithContinuation(lnum, ind_con, s:sw())
|
||||||
|
|
||||||
" }}}2
|
" }}}2
|
||||||
"
|
"
|
||||||
"
|
"
|
||||||
let ols = s:InOneLineScope(lnum)
|
let ols = s:InOneLineScope(lnum)
|
||||||
if ols > 0
|
if ols > 0
|
||||||
let ind = ind + &sw
|
let ind = ind + s:sw()
|
||||||
else
|
else
|
||||||
let ols = s:ExitingOneLineScope(lnum)
|
let ols = s:ExitingOneLineScope(lnum)
|
||||||
while ols > 0 && ind > 0
|
while ols > 0 && ind > 0
|
||||||
let ind = ind - &sw
|
let ind = ind - s:sw()
|
||||||
let ols = s:InOneLineScope(ols - 1)
|
let ols = s:InOneLineScope(ols - 1)
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
@@ -440,66 +499,68 @@ endfunction
|
|||||||
|
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
unlet s:cpo_save
|
unlet s:cpo_save
|
||||||
|
" gq{{{2
|
||||||
function! Fixedgq(lnum, count)
|
function! Fixedgq(lnum, count)
|
||||||
let l:tw = &tw ? &tw : 80;
|
let l:tw = &tw ? &tw : 80;
|
||||||
|
|
||||||
let l:count = a:count
|
let l:count = a:count
|
||||||
let l:first_char = indent(a:lnum) + 1
|
let l:first_char = indent(a:lnum) + 1
|
||||||
|
|
||||||
if mode() == 'i' " gq was not pressed, but tw was set
|
if mode() == 'i' " gq was not pressed, but tw was set
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" This gq is only meant to do code with strings, not comments
|
" 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)
|
if s:IsInComment(a:lnum, l:first_char)
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
|
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Put all the lines on one line and do normal spliting after that
|
" Put all the lines on one line and do normal spliting after that
|
||||||
if l:count > 1
|
if l:count > 1
|
||||||
while l:count > 1
|
while l:count > 1
|
||||||
let l:count -= 1
|
let l:count -= 1
|
||||||
normal J
|
normal J
|
||||||
endwhile
|
endwhile
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:winview = winsaveview()
|
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)
|
call cursor(a:lnum, l:tw + 1)
|
||||||
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
|
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
|
||||||
call cursor(a:lnum, l:tw + 1)
|
endif
|
||||||
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
|
if breakpoint[1] != 0
|
||||||
call feedkeys("r\<CR>")
|
call feedkeys("r\<CR>")
|
||||||
else
|
else
|
||||||
let l:count = l:count - 1
|
let l:count = l:count - 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" run gq on new lines
|
" run gq on new lines
|
||||||
if l:count == 1
|
if l:count == 1
|
||||||
call feedkeys("gqq")
|
call feedkeys("gqq")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
"}}}
|
||||||
|
" vim: foldmethod=marker:foldlevel=1
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jinja') == -1
|
|
||||||
|
|
||||||
" Vim indent file
|
|
||||||
" Language: Jinja HTML template
|
|
||||||
" Maintainer: Evan Hammer <evan@evanhammer.com>
|
|
||||||
" Last Change: 2013 Jan 26
|
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
|
||||||
if exists("b:did_indent")
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Use HTML formatting rules.
|
|
||||||
runtime! indent/html.vim
|
|
||||||
|
|
||||||
endif
|
|
||||||
@@ -56,10 +56,11 @@ function! GetLiquidIndent(...)
|
|||||||
let line = substitute(line,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
let line = substitute(line,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
||||||
let line .= matchstr(cline,'\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 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 sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||||
let ind -= &sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
let ind += sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
|
||||||
let ind -= &sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
let ind -= sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
||||||
let ind -= &sw * s:count(cline,'{%\s*end\w*$')
|
let ind -= sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
||||||
|
let ind -= sw * s:count(cline,'{%\s*end\w*$')
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
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
|
||||||
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\|concept\)'
|
||||||
|
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
|
||||||
21
indent/proto.vim
Normal file
21
indent/proto.vim
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'protobuf') == -1
|
||||||
|
|
||||||
|
" Vim indent file
|
||||||
|
" Language: Protobuf
|
||||||
|
" Maintainer: Johannes Zellner <johannes@zellner.org>
|
||||||
|
" Last Change: Fri, 15 Mar 2002 07:53:54 CET
|
||||||
|
|
||||||
|
" Only load this indent file when no other was loaded.
|
||||||
|
if exists("b:did_indent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
" Protobuf is like indenting C
|
||||||
|
setlocal cindent
|
||||||
|
setlocal expandtab
|
||||||
|
setlocal shiftwidth=2
|
||||||
|
|
||||||
|
let b:undo_indent = "setl cin<"
|
||||||
|
|
||||||
|
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
|
" Vim indent file
|
||||||
" Language: Jade
|
" Language: Pug
|
||||||
" Maintainer: Joshua Borton
|
" Maintainer: Joshua Borton
|
||||||
" Credits: Tim Pope (vim-jade)
|
" Credits: Tim Pope (vim-pug)
|
||||||
" Last Change: 2010 Sep 22
|
" Last Change: 2010 Sep 22
|
||||||
|
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
@@ -14,25 +14,25 @@ unlet! b:did_indent
|
|||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
setlocal autoindent
|
setlocal autoindent
|
||||||
setlocal indentexpr=GetJadeIndent()
|
setlocal indentexpr=GetPugIndent()
|
||||||
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
||||||
|
|
||||||
" Only define the function once.
|
" Only define the function once.
|
||||||
if exists("*GetJadeIndent")
|
if exists("*GetPugIndent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:attributes = '\%((.\{-\})\)'
|
let s:attributes = '\%((.\{-\})\)'
|
||||||
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
||||||
|
|
||||||
if !exists('g:jade_self_closing_tags')
|
if !exists('g:pug_self_closing_tags')
|
||||||
let g:jade_self_closing_tags = 'meta|link|img|hr|br|input'
|
let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
setlocal formatoptions+=r
|
setlocal formatoptions+=r
|
||||||
setlocal comments+=n:\|
|
setlocal comments+=n:\|
|
||||||
|
|
||||||
function! GetJadeIndent()
|
function! GetPugIndent()
|
||||||
let lnum = prevnonblank(v:lnum-1)
|
let lnum = prevnonblank(v:lnum-1)
|
||||||
if lnum == 0
|
if lnum == 0
|
||||||
return 0
|
return 0
|
||||||
@@ -60,9 +60,9 @@ function! GetJadeIndent()
|
|||||||
return increase
|
return increase
|
||||||
elseif line == '-#'
|
elseif line == '-#'
|
||||||
return increase
|
return increase
|
||||||
elseif line =~? '^\v%('.g:jade_self_closing_tags.')>'
|
elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
|
||||||
return indent
|
return indent
|
||||||
elseif group =~? '\v^%(jadeAttributesDelimiter|jadeClass|jadeId|htmlTagName|htmlSpecialTagName|jadeFilter|jadeTagBlockChar)$'
|
elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
|
||||||
return increase
|
return increase
|
||||||
else
|
else
|
||||||
return indent
|
return indent
|
||||||
@@ -53,11 +53,7 @@ function! GetPuppetIndent()
|
|||||||
let pline = getline(pnum)
|
let pline = getline(pnum)
|
||||||
let ind = indent(pnum)
|
let ind = indent(pnum)
|
||||||
|
|
||||||
if pline =~ '^\s*#'
|
if pline =~ '\({\|\[\|(\|:\)\s*\(#.*\)\?$'
|
||||||
return ind
|
|
||||||
endif
|
|
||||||
|
|
||||||
if pline =~ '\({\|\[\|(\|:\)$'
|
|
||||||
let ind += &sw
|
let ind += &sw
|
||||||
elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
|
elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
|
||||||
let ind -= &sw
|
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
|
||||||
@@ -20,6 +20,11 @@ if !exists('g:ruby_indent_access_modifier_style')
|
|||||||
let g:ruby_indent_access_modifier_style = 'normal'
|
let g:ruby_indent_access_modifier_style = 'normal'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !exists('g:ruby_indent_block_style')
|
||||||
|
" Possible values: "expression", "do"
|
||||||
|
let g:ruby_indent_block_style = 'expression'
|
||||||
|
endif
|
||||||
|
|
||||||
setlocal nosmartindent
|
setlocal nosmartindent
|
||||||
|
|
||||||
" Now, set up our indentation expression and keys that trigger it.
|
" Now, set up our indentation expression and keys that trigger it.
|
||||||
@@ -125,7 +130,7 @@ let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=
|
|||||||
" The reason is that the pipe matches a hanging "|" operator.
|
" The reason is that the pipe matches a hanging "|" operator.
|
||||||
"
|
"
|
||||||
let s:block_regex =
|
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
|
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
|
||||||
|
|
||||||
@@ -219,15 +224,15 @@ function s:GetMSL(lnum)
|
|||||||
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
elseif s:Match(lnum, s:non_bracket_continuation_regex) &&
|
||||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_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
|
" If the current line is a bracket continuation or a block-starter, but
|
||||||
" the previous is a non-bracket one, respect the previous' indentation,
|
" the previous is a non-bracket one, keep going to see if the previous
|
||||||
" and stop here.
|
" line is a part of another continuation.
|
||||||
"
|
"
|
||||||
" Example:
|
" Example:
|
||||||
" method_call one,
|
" method_call one,
|
||||||
" two {
|
" two {
|
||||||
" three
|
" three
|
||||||
"
|
"
|
||||||
return lnum
|
let msl = lnum
|
||||||
elseif s:Match(lnum, s:bracket_continuation_regex) &&
|
elseif s:Match(lnum, s:bracket_continuation_regex) &&
|
||||||
\ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_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
|
" If both lines are bracket continuations (the current may also be a
|
||||||
@@ -419,7 +424,9 @@ function GetRubyIndent(...)
|
|||||||
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
||||||
if line[col-1]==')' && col('.') != col('$') - 1
|
if line[col-1]==')' && col('.') != col('$') - 1
|
||||||
let ind = virtcol('.') - 1
|
let ind = virtcol('.') - 1
|
||||||
else
|
elseif g:ruby_indent_block_style == 'do'
|
||||||
|
let ind = indent(line('.'))
|
||||||
|
else " g:ruby_indent_block_style == 'expression'
|
||||||
let ind = indent(s:GetMSL(line('.')))
|
let ind = indent(s:GetMSL(line('.')))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -444,12 +451,15 @@ function GetRubyIndent(...)
|
|||||||
\ strpart(line, col('.') - 1, 2) !~ 'do'
|
\ strpart(line, col('.') - 1, 2) !~ 'do'
|
||||||
" assignment to case/begin/etc, on the same line, hanging indent
|
" assignment to case/begin/etc, on the same line, hanging indent
|
||||||
let ind = virtcol('.') - 1
|
let ind = virtcol('.') - 1
|
||||||
|
elseif g:ruby_indent_block_style == 'do'
|
||||||
|
" align to line of the "do", not to the MSL
|
||||||
|
let ind = indent(line('.'))
|
||||||
elseif getline(msl) =~ '=\s*\(#.*\)\=$'
|
elseif getline(msl) =~ '=\s*\(#.*\)\=$'
|
||||||
" in the case of assignment to the msl, align to the starting line,
|
" in the case of assignment to the MSL, align to the starting line,
|
||||||
" not to the msl
|
" not to the MSL
|
||||||
let ind = indent(line('.'))
|
let ind = indent(line('.'))
|
||||||
else
|
else
|
||||||
" align to the msl
|
" align to the MSL
|
||||||
let ind = indent(msl)
|
let ind = indent(msl)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -516,7 +526,10 @@ function GetRubyIndent(...)
|
|||||||
if s:Match(lnum, s:block_regex)
|
if s:Match(lnum, s:block_regex)
|
||||||
let msl = s:GetMSL(lnum)
|
let msl = s:GetMSL(lnum)
|
||||||
|
|
||||||
if getline(msl) =~ '=\s*\(#.*\)\=$'
|
if g:ruby_indent_block_style == 'do'
|
||||||
|
" don't align to the msl, align to the "do"
|
||||||
|
let ind = indent(lnum) + sw
|
||||||
|
elseif getline(msl) =~ '=\s*\(#.*\)\=$'
|
||||||
" in the case of assignment to the msl, align to the starting line,
|
" in the case of assignment to the msl, align to the starting line,
|
||||||
" not to the msl
|
" not to the msl
|
||||||
let ind = indent(lnum) + sw
|
let ind = indent(lnum) + sw
|
||||||
@@ -564,7 +577,7 @@ function GetRubyIndent(...)
|
|||||||
if s:Match(line('.'), s:ruby_indent_keywords)
|
if s:Match(line('.'), s:ruby_indent_keywords)
|
||||||
return indent('.') + sw
|
return indent('.') + sw
|
||||||
else
|
else
|
||||||
return indent('.')
|
return indent(s:GetMSL(line('.')))
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call cursor(clnum, vcol)
|
call cursor(clnum, vcol)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
|||||||
" Vim indent file
|
" Vim indent file
|
||||||
" Language: Rust
|
" Language: Rust
|
||||||
" Author: Chris Morgan <me@chrismorgan.info>
|
" Author: Chris Morgan <me@chrismorgan.info>
|
||||||
" Last Change: 2014 Sep 13
|
" Last Change: 2016 Jul 15
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
" Only load this indent file when no other was loaded.
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
@@ -134,6 +134,7 @@ function GetRustIndent(lnum)
|
|||||||
\ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
|
\ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
|
||||||
\ && prevline !~ '^\s*fn\s'
|
\ && prevline !~ '^\s*fn\s'
|
||||||
\ && prevline !~ '([^()]\+,$'
|
\ && prevline !~ '([^()]\+,$'
|
||||||
|
\ && s:get_line_trimmed(a:lnum) !~ '^\s*\S\+\s*=>'
|
||||||
" Oh ho! The previous line ended in a comma! I bet cindent will try to
|
" Oh ho! The previous line ended in a comma! I bet cindent will try to
|
||||||
" take this too far... For now, let's normally use the previous line's
|
" take this too far... For now, let's normally use the previous line's
|
||||||
" indent.
|
" indent.
|
||||||
@@ -158,6 +159,8 @@ function GetRustIndent(lnum)
|
|||||||
" if baz && (foo ||
|
" if baz && (foo ||
|
||||||
" bar) {
|
" bar) {
|
||||||
"
|
"
|
||||||
|
" Another case is when the current line is a new match arm.
|
||||||
|
"
|
||||||
" There are probably other cases where we don't want to do this as
|
" There are probably other cases where we don't want to do this as
|
||||||
" well. Add them as needed.
|
" well. Add them as needed.
|
||||||
return indent(prevlinenum)
|
return indent(prevlinenum)
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ function! GetSassIndent()
|
|||||||
let indent = indent(lnum)
|
let indent = indent(lnum)
|
||||||
let cindent = indent(v:lnum)
|
let cindent = indent(v:lnum)
|
||||||
if line !~ s:property && line !~ s:extend && cline =~ s:property
|
if line !~ s:property && line !~ s:extend && cline =~ s:property
|
||||||
return indent + &sw
|
return indent + (exists('*shiftwidth') ? shiftwidth() : &sw)
|
||||||
"elseif line =~ s:property && cline !~ s:property
|
|
||||||
"return indent - &sw
|
|
||||||
else
|
else
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ let s:cpo_save = &cpo
|
|||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
setlocal nosmartindent
|
setlocal nosmartindent
|
||||||
setlocal indentkeys-=:
|
|
||||||
setlocal indentkeys-=e
|
setlocal indentkeys-=e
|
||||||
setlocal indentkeys+=0]
|
setlocal indentkeys+=0]
|
||||||
setlocal indentexpr=SwiftIndent()
|
setlocal indentexpr=SwiftIndent()
|
||||||
@@ -95,11 +94,13 @@ function! SwiftIndent(...)
|
|||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return indent(openingSquare)
|
" - Line starts with closing square, indent as opening square
|
||||||
endif
|
if line =~ '\v^\s*]'
|
||||||
|
return indent(openingSquare)
|
||||||
|
endif
|
||||||
|
|
||||||
if s:IsExcludedFromIndent()
|
" - Line contains closing square and more, indent a level above opening
|
||||||
return previousIndent
|
return indent(openingSquare) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if line =~ ":$"
|
if line =~ ":$"
|
||||||
@@ -153,7 +154,8 @@ function! SwiftIndent(...)
|
|||||||
endif
|
endif
|
||||||
return indent(openingBracket)
|
return indent(openingBracket)
|
||||||
else
|
else
|
||||||
return -1
|
" - Current line is blank, and the user presses 'o'
|
||||||
|
return previousIndent
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -195,7 +197,7 @@ function! SwiftIndent(...)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let previousParen = match(previous, "(")
|
let previousParen = match(previous, "(")
|
||||||
return previousParen + 1
|
return indent(previousParen) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if numOpenBrackets > numCloseBrackets
|
if numOpenBrackets > numCloseBrackets
|
||||||
@@ -207,6 +209,11 @@ function! SwiftIndent(...)
|
|||||||
return indent(openingParen) + shiftwidth()
|
return indent(openingParen) + shiftwidth()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" - Previous line has close then open braces, indent previous + 1 'sw'
|
||||||
|
if previous =~ "}.*{"
|
||||||
|
return previousIndent + shiftwidth()
|
||||||
|
endif
|
||||||
|
|
||||||
let line = line(".")
|
let line = line(".")
|
||||||
let column = col(".")
|
let column = col(".")
|
||||||
call cursor(previousNum, column)
|
call cursor(previousNum, column)
|
||||||
@@ -216,9 +223,14 @@ function! SwiftIndent(...)
|
|||||||
return indent(openingParen)
|
return indent(openingParen)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" - Line above has (unmatched) open paren, next line needs indent
|
||||||
if numOpenParens > 0
|
if numOpenParens > 0
|
||||||
let previousParen = match(previous, "(")
|
let savePosition = getcurpos()
|
||||||
return previousParen + 1
|
" 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
|
endif
|
||||||
|
|
||||||
return cindent
|
return cindent
|
||||||
|
|||||||
@@ -1,105 +1,505 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'typescript') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'typescript') == -1
|
||||||
|
|
||||||
" Vim indent file, taken from indent/java.vim
|
" Vim indent file
|
||||||
" Language: Typescript
|
" Language: Typescript
|
||||||
" Maintainer: None! Wanna improve this?
|
" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org
|
||||||
" Last Change: 2015 Mar 07
|
|
||||||
|
|
||||||
if get(g:, 'typescript_indent_disable')
|
" 0. Initialization {{{1
|
||||||
finish
|
" =================
|
||||||
endif
|
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
" Only load this indent file when no other was loaded.
|
||||||
if exists("b:did_indent")
|
if exists("b:did_indent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
" Use javascript cindent options
|
setlocal nosmartindent
|
||||||
setlocal cindent cinoptions& cinoptions+=j1,J1
|
|
||||||
setlocal indentkeys&
|
|
||||||
|
|
||||||
" Load typescript indent function
|
" Now, set up our indentation expression and keys that trigger it.
|
||||||
setlocal indentexpr=GetTypescriptIndent()
|
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")
|
if exists("*GetTypescriptIndent")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Make sure we have vim capabilities
|
let s:cpo_save = &cpo
|
||||||
let s:keepcpo = &cpo
|
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
function! TypescriptPrevNonBlankOrComment(lnum)
|
" 1. Variables {{{1
|
||||||
let pnum = prevnonblank(a:lnum)
|
" ============
|
||||||
" skip any comments (either `//`, `/*` or `*`)
|
|
||||||
while getline(pnum) =~ '^\s*\(\/\/\|\/\*\|\*\)'
|
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\)'
|
||||||
let pnum = prevnonblank(pnum-1)
|
|
||||||
endwhile
|
" Regex of syntax group names that are or delimit string or are comments.
|
||||||
return pnum
|
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
|
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()
|
function GetTypescriptIndent()
|
||||||
|
" 3.1. Setup {{{2
|
||||||
|
" ----------
|
||||||
|
|
||||||
" default value: trust cindent
|
" Set up variables for restoring position in file. Could use v:lnum here.
|
||||||
let ind = cindent(v:lnum)
|
let vcol = col('.')
|
||||||
|
|
||||||
if getline(v:lnum) =~ '^\s*[{}\*]'
|
" 3.2. Work on the current line {{{2
|
||||||
return ind
|
" -----------------------------
|
||||||
endif
|
|
||||||
|
|
||||||
" The last non-empty line
|
let ind = -1
|
||||||
let prev = TypescriptPrevNonBlankOrComment(v:lnum-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>;`
|
" If we got a closing bracket on an empty line, find its match and indent
|
||||||
" declaration (e.g. in interface definitions)
|
" according to it. For parentheses we indent to its column - 1, for the
|
||||||
if getline(prev) =~ '^\s*\w\+\s*:[^{]\+;\s*$'
|
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||||
return indent(prev)
|
let col = matchend(line, '^\s*[],})]')
|
||||||
endif
|
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
|
let lvar = s:InMultiVarStatement(v:lnum)
|
||||||
" the previous one
|
if lvar
|
||||||
if getline(prev) =~ '^\s*@\S\+\s*$'
|
let prevline_contents = s:RemoveTrailingComments(getline(prevline))
|
||||||
return indent(prev)
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If a var, let, or const was declared and the semicolon omitted, do not
|
" check for comma first
|
||||||
" indent the next line
|
if (line[col - 1] =~ ',')
|
||||||
if getline(prev) =~ '^\s*\(var\|let\|const\)\s\+\w\+'
|
" if the previous line ends in comma or semicolon don't indent
|
||||||
return indent(prev)
|
if (prevline_contents =~ '[;,]\s*$')
|
||||||
endif
|
return indent(s:GetMSL(line('.'), 0))
|
||||||
|
" get previous line indent, if it's comma first return prevline indent
|
||||||
" If the line ended with a ',', we should have the same indent as
|
elseif (prevline_contents =~ s:comma_first)
|
||||||
" the previous one
|
return indent(prevline)
|
||||||
if getline(prev) =~ ',\s*$'
|
" otherwise we indent 1 level
|
||||||
return indent(prev)
|
else
|
||||||
endif
|
return indent(lvar) + &sw
|
||||||
|
|
||||||
" 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)
|
|
||||||
endif
|
endif
|
||||||
|
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
|
endfunction
|
||||||
|
|
||||||
" Restore compatibility mode
|
" }}}1
|
||||||
let &cpo = s:keepcpo
|
|
||||||
unlet s:keepcpo
|
|
||||||
|
|
||||||
" 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
|
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
|
||||||
31
syntax/ansible_template.vim
Normal file
31
syntax/ansible_template.vim
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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 = 'jinja2'
|
||||||
|
endif
|
||||||
|
|
||||||
|
let b:current_syntax = ''
|
||||||
|
unlet b:current_syntax
|
||||||
|
runtime! syntax/jinja2.vim
|
||||||
|
|
||||||
|
if exists("g:ansible_extra_syntaxes")
|
||||||
|
let s:extra_syntax = split(g:ansible_extra_syntaxes)
|
||||||
|
for syntax_name in s:extra_syntax
|
||||||
|
let b:current_syntax = ''
|
||||||
|
unlet b:current_syntax
|
||||||
|
execute 'runtime!' "syntax/" . syntax_name
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
let b:current_syntax = "ansible_template"
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -1,45 +1,69 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||||
|
|
||||||
" Language: Blade
|
" Vim syntax file
|
||||||
|
" Language: Blade (Laravel)
|
||||||
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
||||||
" URL: https://github.com/xsbeats/vim-blade
|
" Filenames: *.blade.php
|
||||||
" License: DBAD
|
|
||||||
|
|
||||||
" Check if our syntax is already loaded
|
if exists('b:current_syntax')
|
||||||
if exists('b:current_syntax') && b:current_syntax == 'blade'
|
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Include PHP
|
if !exists("main_syntax")
|
||||||
|
let main_syntax = 'blade'
|
||||||
|
endif
|
||||||
|
|
||||||
|
runtime! syntax/html.vim
|
||||||
|
unlet! b:current_syntax
|
||||||
runtime! syntax/php.vim
|
runtime! syntax/php.vim
|
||||||
silent! unlet b:current_syntax
|
unlet! b:current_syntax
|
||||||
|
|
||||||
" Echos
|
syn case match
|
||||||
syn region bladeUnescapedEcho matchgroup=bladeEchoDelim start=/@\@<!\s*{!!/ end=/!!}\s*/ oneline contains=@phpClTop containedin=ALLBUT,bladeComment
|
syn clear htmlError
|
||||||
syn region bladeEscapedEcho matchgroup=bladeEchoDelim start=/@\@<!\s*{{{\@!/ end=/}}\s*/ oneline contains=@phpClTop containedin=ALLBUT,bladeComment
|
|
||||||
syn region bladeEscapedEcho matchgroup=bladeEchoDelim start=/@\@<!\s*{{{{\@!/ end=/}}}/ oneline contains=@phpClTop containedin=ALLBUT,bladeComment
|
|
||||||
|
|
||||||
" Structures
|
if has('patch-7.4.1142')
|
||||||
syn match bladeStructure /\s*@\(else\|empty\|endfor\|endforeach\|endforelse\|endif\|endpush\|endsection\|endunless\|endwhile\|overwrite\|show\|stop\)\>/
|
syn iskeyword @,48-57,_,192-255,@-@,:
|
||||||
syn match bladeStructure /\s*@\(append\|choice\|each\|elseif\|extends\|for\|foreach\|forelse\|if\|include\|lang\|push\|section\|stack\|unless\|while\|yield\|\)\>\s*/ nextgroup=bladeParens
|
else
|
||||||
syn region bladeParens matchgroup=bladeParen start=/(/ end=/)/ contained contains=@bladeAll,@phpClTop
|
setlocal iskeyword+=@-@
|
||||||
|
endif
|
||||||
|
|
||||||
" Comments
|
syn region bladeEcho matchgroup=bladeDelimiter start="@\@<!{{" end="}}" contains=@bladePhp,bladePhpParenBlock containedin=ALLBUT,@bladeExempt keepend
|
||||||
syn region bladeComments start=/\s*{{--/ end=/--}}/ contains=bladeComment keepend
|
syn region bladeEcho matchgroup=bladeDelimiter start="{!!" end="!!}" contains=@bladePhp,bladePhpParenBlock containedin=ALLBUT,@bladeExempt keepend
|
||||||
syn match bladeComment /.*/ contained containedin=bladeComments
|
syn region bladeComment matchgroup=bladeDelimiter start="{{--" end="--}}" contains=bladeTodo containedin=ALLBUT,@bladeExempt keepend
|
||||||
|
|
||||||
" Clusters
|
syn keyword bladeKeyword @if @elseif @foreach @forelse @for @while @can @cannot @elsecan @elsecannot @include @includeIf @each @inject @extends @section @stack @push @unless @yield @parent @hasSection @break @continue @unset @lang @choice nextgroup=bladePhpParenBlock skipwhite containedin=ALLBUT,@bladeExempt
|
||||||
syn cluster bladeAll contains=bladeStructure,bladeParens
|
syn keyword bladeKeyword @else @endif @endunless @endfor @endforeach @empty @endforelse @endwhile @endcan @endcannot @stop @append @endsection @endpush @show @overwrite @verbatim @endverbatim containedin=ALLBUT,@bladeExempt
|
||||||
|
|
||||||
" Highlighting
|
if exists('g:blade_custom_directives')
|
||||||
|
exe "syn keyword bladeKeyword @" . join(g:blade_custom_directives, ' @') . " nextgroup=bladePhpParenBlock skipwhite containedin=ALLBUT,@bladeExempt"
|
||||||
|
endif
|
||||||
|
if exists('g:blade_custom_directives_pairs')
|
||||||
|
exe "syn keyword bladeKeyword @" . join(keys(g:blade_custom_directives_pairs), ' @') . " nextgroup=bladePhpParenBlock skipwhite containedin=ALLBUT,@bladeExempt"
|
||||||
|
exe "syn keyword bladeKeyword @" . join(values(g:blade_custom_directives_pairs), ' @') . " containedin=ALLBUT,@bladeExempt"
|
||||||
|
endif
|
||||||
|
|
||||||
|
syn region bladePhpRegion matchgroup=bladeKeyword start="\<@php\>\%(\s*(\)\@!" end="\<@endphp\>" contains=@bladePhp containedin=ALLBUT,@bladeExempt keepend
|
||||||
|
syn match bladeKeyword "@php\ze\s*(" nextgroup=bladePhpParenBlock skipwhite containedin=ALLBUT,@bladeExempt
|
||||||
|
|
||||||
|
syn region bladePhpParenBlock matchgroup=bladeDelimiter start="\s*(" end=")" contains=@bladePhp,bladePhpParenBlock skipwhite contained
|
||||||
|
|
||||||
|
syn cluster bladePhp contains=@phpClTop
|
||||||
|
syn cluster bladeExempt contains=bladeComment,bladePhpRegion,bladePhpParenBlock,@htmlTop
|
||||||
|
|
||||||
|
syn cluster htmlPreproc add=bladeEcho,bladeComment,bladePhpRegion
|
||||||
|
|
||||||
|
syn case ignore
|
||||||
|
syn keyword bladeTodo todo fixme xxx note contained
|
||||||
|
|
||||||
|
hi def link bladeDelimiter PreProc
|
||||||
hi def link bladeComment Comment
|
hi def link bladeComment Comment
|
||||||
hi def link bladeEchoDelim Delimiter
|
hi def link bladeTodo Todo
|
||||||
hi def link bladeParen Delimiter
|
hi def link bladeKeyword Statement
|
||||||
hi def link bladeStructure Keyword
|
|
||||||
|
|
||||||
|
let b:current_syntax = 'blade'
|
||||||
|
|
||||||
if !exists('b:current_syntax')
|
if exists('main_syntax') && main_syntax == 'blade'
|
||||||
let b:current_syntax = 'blade'
|
unlet main_syntax
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
15
syntax/c.vim
15
syntax/c.vim
@@ -3,7 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c/c++') == -1
|
|||||||
" Vim syntax file
|
" Vim syntax file
|
||||||
" Language: C
|
" Language: C
|
||||||
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||||
" Last Change: 2015 Mar 05
|
" Last Change: 2016 Apr 10
|
||||||
|
|
||||||
" Quit when a (custom) syntax file was already loaded
|
" Quit when a (custom) syntax file was already loaded
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
@@ -184,6 +184,11 @@ syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumbe
|
|||||||
syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
|
syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
|
||||||
"hex number
|
"hex number
|
||||||
syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
|
syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
|
||||||
|
if s:ft ==# 'cpp' && !exists("cpp_no_cpp14")
|
||||||
|
syn match cNumber display contained "\d\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
|
||||||
|
syn match cNumber display contained "0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
|
||||||
|
syn match cNumber display contained "0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
|
||||||
|
endif
|
||||||
" Flag the first zero of an octal number as something special
|
" Flag the first zero of an octal number as something special
|
||||||
syn match cOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
|
syn match cOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
|
||||||
syn match cOctalZero display contained "\<0"
|
syn match cOctalZero display contained "\<0"
|
||||||
@@ -250,6 +255,10 @@ if !exists("c_no_c99") " ISO C99
|
|||||||
syn keyword cType _Bool bool _Complex complex _Imaginary imaginary
|
syn keyword cType _Bool bool _Complex complex _Imaginary imaginary
|
||||||
syn keyword cType int8_t int16_t int32_t int64_t
|
syn keyword cType int8_t int16_t int32_t int64_t
|
||||||
syn keyword cType uint8_t uint16_t uint32_t uint64_t
|
syn keyword cType uint8_t uint16_t uint32_t uint64_t
|
||||||
|
if !exists("c_no_bsd")
|
||||||
|
" These are BSD specific.
|
||||||
|
syn keyword cType u_int8_t u_int16_t u_int32_t u_int64_t
|
||||||
|
endif
|
||||||
syn keyword cType int_least8_t int_least16_t int_least32_t int_least64_t
|
syn keyword cType int_least8_t int_least16_t int_least32_t int_least64_t
|
||||||
syn keyword cType uint_least8_t uint_least16_t uint_least32_t uint_least64_t
|
syn keyword cType uint_least8_t uint_least16_t uint_least32_t uint_least64_t
|
||||||
syn keyword cType int_fast8_t int_fast16_t int_fast32_t int_fast64_t
|
syn keyword cType int_fast8_t int_fast16_t int_fast32_t int_fast64_t
|
||||||
@@ -266,7 +275,7 @@ syn keyword cStorageClass static register auto volatile extern const
|
|||||||
if exists("c_gnu")
|
if exists("c_gnu")
|
||||||
syn keyword cStorageClass inline __attribute__
|
syn keyword cStorageClass inline __attribute__
|
||||||
endif
|
endif
|
||||||
if !exists("c_no_c99")
|
if !exists("c_no_c99") && s:ft !=# 'cpp'
|
||||||
syn keyword cStorageClass inline restrict
|
syn keyword cStorageClass inline restrict
|
||||||
endif
|
endif
|
||||||
if !exists("c_no_c11")
|
if !exists("c_no_c11")
|
||||||
@@ -293,7 +302,7 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
|
|||||||
syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
|
syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
|
||||||
syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
|
syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
|
||||||
if !exists("c_no_c99")
|
if !exists("c_no_c99")
|
||||||
syn keyword cConstant __func__
|
syn keyword cConstant __func__ __VA_ARGS__
|
||||||
syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
|
syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
|
||||||
syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
|
syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
|
||||||
syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
|
syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user