mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11f53253ad | ||
|
|
9fe009095a | ||
|
|
dce9e8dec5 | ||
|
|
30c87b73de | ||
|
|
1713d35f06 | ||
|
|
5ddfa1ac28 | ||
|
|
dbe9bc927f | ||
|
|
d219055bc8 | ||
|
|
0e9041f29a | ||
|
|
a0b8a6e77f | ||
|
|
a61ab44810 | ||
|
|
dd4b5cbdd6 | ||
|
|
27903c5b86 | ||
|
|
d5e38fa97b | ||
|
|
7673a61990 | ||
|
|
6a12aa87f4 | ||
|
|
5b77877888 | ||
|
|
8148255ef1 | ||
|
|
40ddf334c9 | ||
|
|
7e10428cd6 | ||
|
|
6a4fe34e61 | ||
|
|
4cd5566b40 | ||
|
|
8b3418cab8 | ||
|
|
9bfde7574a | ||
|
|
8eab5f5403 | ||
|
|
d5b9c4ae84 | ||
|
|
7dd2e11698 | ||
|
|
9197c69900 | ||
|
|
c7dfe2f626 | ||
|
|
af87010071 | ||
|
|
ef369d45a5 | ||
|
|
64938393bd | ||
|
|
79fce146dd | ||
|
|
ef4435cffc | ||
|
|
c2a7f363c6 | ||
|
|
0134940f23 | ||
|
|
8bb259b1f6 | ||
|
|
466f20b12e | ||
|
|
461de4cc21 | ||
|
|
ba75890936 | ||
|
|
0801eac01a | ||
|
|
9f735b1fe7 | ||
|
|
fbeb019a85 |
180
README.md
180
README.md
@@ -1,4 +1,4 @@
|
||||
# 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.svg
|
||||
[travis-url]: https://travis-ci.org/sheerun/vim-polyglot
|
||||
@@ -8,13 +8,13 @@ A collection of language packs for Vim.
|
||||
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
|
||||
|
||||
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
|
||||
- It **installs and updates 70+ times faster** than 70+ packages it consist of.
|
||||
- Solid syntax and indentation support. Only the best language packs.
|
||||
- It **installs and updates 100+ times faster** than 100+ packages it consists of.
|
||||
- Solid syntax and indentation support (other features skipped). Only the best language packs.
|
||||
- All unnecessary files are ignored (like enormous documentation from php support).
|
||||
- No support for esoteric languages, only most popular ones (modern too, like `slim`).
|
||||
- Each build is tested by automated vimrunner script on CI. See `spec` directory.
|
||||
|
||||
\*To be completely honest, concatenated `ftdetect` script takes around `3ms` to load.
|
||||
\*To be completely honest, concatenated `ftdetect` script takes up to `17ms` to load.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -23,104 +23,124 @@ A collection of language packs for Vim.
|
||||
|
||||
Optionally download one of the [releases](https://github.com/sheerun/vim-polyglot/releases) and unpack it directly under `~/.vim` directory.
|
||||
|
||||
You can also use Vim 8 built-in package manager:
|
||||
|
||||
```
|
||||
mkdir -p ~/.vim/pack/default/start
|
||||
git clone https://github.com/sheerun/vim-polyglot ~/.vim/pack/default/start/vim-polyglot
|
||||
```
|
||||
|
||||
NOTE: Not all features of listed language packs are available. We strip them from functionality slowing vim startup in general (for example we ignore `plugins` folder that is loaded regardless of file type, use `ftplugin` instead).
|
||||
|
||||
If you need full functionality of any plugin, please use it directly with your plugin manager.
|
||||
|
||||
## Language packs
|
||||
|
||||
- [ansible](https://github.com/pearofducks/ansible-vim) (syntax, indent, ftplugin)
|
||||
- [apiblueprint](https://github.com/sheerun/apiblueprint.vim) (syntax)
|
||||
- [applescript](https://github.com/vim-scripts/applescript.vim) (syntax)
|
||||
- [ansible](https://github.com/pearofducks/ansible-vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent, ftdetect)
|
||||
- [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin, ftdetect)
|
||||
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent)
|
||||
- [asciidoc](https://github.com/asciidoc/vim-asciidoc) (syntax)
|
||||
- [autohotkey](https://github.com/hnamikaw/vim-autohotkey) (indent)
|
||||
- [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin)
|
||||
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
|
||||
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
|
||||
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim) (syntax, compiler, ftplugin, ftdetect)
|
||||
- [crystal](https://github.com/rhysd/vim-crystal) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [cql](https://github.com/elubow/cql-vim) (syntax, ftdetect)
|
||||
- [css](https://github.com/JulesWang/css.vim) (syntax)
|
||||
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [dart](https://github.com/dart-lang/dart-vim-plugin) (syntax, indent, autoload, ftplugin, ftdetect)
|
||||
- [dockerfile](https://github.com/honza/dockerfile.vim) (syntax, ftdetect)
|
||||
- [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [elm](https://github.com/lambdatoast/elm.vim) (syntax, indent, autoload, 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)
|
||||
- [fish](https://github.com/dag/vim-fish) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin, ftdetect)
|
||||
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent, ftdetect)
|
||||
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent, ftdetect)
|
||||
- [caddyfile](https://github.com/isobit/vim-caddyfile) (syntax, indent, ftplugin)
|
||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (syntax, ftplugin)
|
||||
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin)
|
||||
- [cmake](https://github.com/pboettch/vim-cmake-syntax) (syntax, indent)
|
||||
- [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin)
|
||||
- [cql](https://github.com/elubow/cql-vim) (syntax)
|
||||
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim) (syntax, compiler, ftplugin)
|
||||
- [crystal](https://github.com/rhysd/vim-crystal) (syntax, indent, autoload, ftplugin)
|
||||
- [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin)
|
||||
- [dart](https://github.com/dart-lang/dart-vim-plugin) (syntax, indent, autoload, ftplugin)
|
||||
- [dockerfile](https://github.com/docker/docker) (syntax)
|
||||
- [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, autoload, ftplugin)
|
||||
- [elm](https://github.com/ElmCast/elm-vim) (syntax, indent, autoload, ftplugin)
|
||||
- [emberscript](https://github.com/yalesov/vim-ember-script) (syntax, indent, ftplugin)
|
||||
- [emblem](https://github.com/yalesov/vim-emblem) (syntax, indent, ftplugin)
|
||||
- [erlang](https://github.com/vim-erlang/vim-erlang-runtime) (syntax, indent)
|
||||
- [fish](https://github.com/dag/vim-fish) (syntax, indent, compiler, autoload, ftplugin)
|
||||
- [fsharp](https://github.com/fsharp/vim-fsharp) (syntax, indent)
|
||||
- [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin)
|
||||
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent)
|
||||
- [gmpl](https://github.com/maelvalais/gmpl.vim) (syntax)
|
||||
- [gnuplot](https://github.com/vim-scripts/gnuplot-syntax-highlighting) (syntax)
|
||||
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent)
|
||||
- [groovy](https://github.com/vim-scripts/groovy.vim) (syntax)
|
||||
- [haml](https://github.com/sheerun/vim-haml) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, indent, ftplugin, ftdetect)
|
||||
- [haskell](https://github.com/neovimhaskell/haskell-vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [haxe](https://github.com/yaymukund/vim-haxe) (syntax, ftdetect)
|
||||
- [haml](https://github.com/sheerun/vim-haml) (syntax, indent, compiler, ftplugin)
|
||||
- [handlebars](https://github.com/mustache/vim-mustache-handlebars) (syntax, indent, ftplugin)
|
||||
- [haskell](https://github.com/neovimhaskell/haskell-vim) (syntax, indent, ftplugin)
|
||||
- [haxe](https://github.com/yaymukund/vim-haxe) (syntax)
|
||||
- [html5](https://github.com/othree/html5.vim) (syntax, indent, autoload, ftplugin)
|
||||
- [i3](https://github.com/PotatoesMaster/i3-vim-syntax) (syntax, ftplugin, ftdetect)
|
||||
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax, ftdetect)
|
||||
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftdetect, ftplugin, extras)
|
||||
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin, ftdetect)
|
||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent, ftdetect)
|
||||
- [jsx](https://github.com/mxw/vim-jsx) (ftdetect, after)
|
||||
- [julia](https://github.com/dcjones/julia-minimalist-vim) (syntax, indent, ftdetect)
|
||||
- [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent, ftdetect)
|
||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin, ftdetect)
|
||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
||||
- [livescript](https://github.com/gkz/vim-ls) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [i3](https://github.com/PotatoesMaster/i3-vim-syntax) (syntax, ftplugin)
|
||||
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax)
|
||||
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras)
|
||||
- [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent)
|
||||
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin)
|
||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent)
|
||||
- [jsx](https://github.com/mxw/vim-jsx) (after)
|
||||
- [julia](https://github.com/JuliaEditorSupport/julia-vim) (syntax, indent, autoload, ftplugin)
|
||||
- [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent)
|
||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) ()
|
||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin)
|
||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin)
|
||||
- [livescript](https://github.com/gkz/vim-ls) (syntax, indent, compiler, ftplugin)
|
||||
- [lua](https://github.com/tbastos/vim-lua) (syntax, indent)
|
||||
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin, ftdetect)
|
||||
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax, ftdetect)
|
||||
- [nginx](https://github.com/othree/nginx-contrib-vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, indent, ftdetect)
|
||||
- [nix](https://github.com/spwhitt/vim-nix) (syntax, ftplugin, ftdetect)
|
||||
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin)
|
||||
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax)
|
||||
- [mathematica](https://github.com/rsmenon/vim-mathematica) (syntax, ftplugin)
|
||||
- [nginx](https://github.com/chr4/nginx.vim) (syntax, indent, ftplugin)
|
||||
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, indent)
|
||||
- [nix](https://github.com/LnL7/vim-nix) (syntax, indent, ftplugin)
|
||||
- [objc](https://github.com/b4winckler/vim-objc) (ftplugin, syntax, indent)
|
||||
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
|
||||
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
|
||||
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect)
|
||||
- [perl](https://github.com/vim-perl/vim-perl) (syntax, indent, ftplugin, ftdetect)
|
||||
- [pgsql](https://github.com/exu/pgsql.vim) (syntax, ftdetect)
|
||||
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin)
|
||||
- [perl](https://github.com/vim-perl/vim-perl) (syntax, indent, ftplugin)
|
||||
- [pgsql](https://github.com/exu/pgsql.vim) (syntax)
|
||||
- [php](https://github.com/StanAngeloff/php.vim) (syntax)
|
||||
- [plantuml](https://github.com/aklt/plantuml-syntax) (syntax, indent, ftplugin, ftdetect)
|
||||
- [powershell](https://github.com/PProvost/vim-ps1) (syntax, indent, ftplugin, ftdetect)
|
||||
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, indent, 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, ftplugin, ftdetect)
|
||||
- [plantuml](https://github.com/aklt/plantuml-syntax) (syntax, indent, ftplugin)
|
||||
- [powershell](https://github.com/PProvost/vim-ps1) (syntax, indent, ftplugin)
|
||||
- [protobuf](https://github.com/uarun/vim-protobuf) (syntax, indent)
|
||||
- [pug](https://github.com/digitaltoad/vim-pug) (syntax, indent, ftplugin)
|
||||
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin)
|
||||
- [purescript](https://github.com/purescript-contrib/purescript-vim) (syntax, indent, ftplugin)
|
||||
- [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload)
|
||||
- [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent)
|
||||
- [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload, ftdetect)
|
||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin, ftdetect)
|
||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin)
|
||||
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
||||
- [raml](https://github.com/IN3D/vim-raml) (syntax, ftplugin, ftdetect)
|
||||
- [racket](https://github.com/wlangstroth/vim-racket) (syntax, indent, autoload, ftplugin)
|
||||
- [ragel](https://github.com/jneen/ragel.vim) (syntax)
|
||||
- [rspec](https://github.com/sheerun/rspec.vim) (syntax, ftdetect)
|
||||
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [rust](https://github.com/rust-lang/rust.vim) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [sbt](https://github.com/derekwyatt/vim-sbt) (syntax, ftdetect)
|
||||
- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [scss](https://github.com/cakebaker/scss-syntax.vim) (syntax, autoload, ftplugin, ftdetect)
|
||||
- [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [solidity](https://github.com/ethereum/vim-solidity) (syntax, indent, ftdetect)
|
||||
- [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin, ftdetect)
|
||||
- [swift](https://github.com/keith/swift.vim) (syntax, indent, ftplugin, ftdetect)
|
||||
- [systemd](https://github.com/kurayama/systemd-vim-syntax) (syntax, ftdetect)
|
||||
- [terraform](https://github.com/hashivim/vim-terraform) (syntax, indent, ftdetect, ftplugin)
|
||||
- [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin, ftdetect)
|
||||
- [thrift](https://github.com/solarnz/thrift.vim) (syntax, ftdetect)
|
||||
- [tmux](https://github.com/keith/tmux.vim) (syntax, ftplugin, ftdetect)
|
||||
- [raml](https://github.com/IN3D/vim-raml) (syntax, ftplugin)
|
||||
- [rspec](https://github.com/sheerun/rspec.vim) (syntax)
|
||||
- [ruby](https://github.com/vim-ruby/vim-ruby) (syntax, indent, compiler, autoload, ftplugin)
|
||||
- [rust](https://github.com/rust-lang/rust.vim) (syntax, indent, compiler, autoload, ftplugin)
|
||||
- [sbt](https://github.com/derekwyatt/vim-sbt) (syntax)
|
||||
- [scala](https://github.com/derekwyatt/vim-scala) (syntax, indent, compiler, ftplugin)
|
||||
- [scss](https://github.com/cakebaker/scss-syntax.vim) (syntax, autoload, ftplugin)
|
||||
- [slim](https://github.com/slim-template/vim-slim) (syntax, indent, ftplugin)
|
||||
- [slime](https://github.com/slime-lang/vim-slime-syntax) (syntax, indent)
|
||||
- [solidity](https://github.com/tomlion/vim-solidity) (syntax, indent, ftplugin)
|
||||
- [stylus](https://github.com/wavded/vim-stylus) (syntax, indent, ftplugin)
|
||||
- [swift](https://github.com/keith/swift.vim) (syntax, indent, ftplugin)
|
||||
- [sxhkd](https://github.com/baskerville/vim-sxhkdrc) (syntax)
|
||||
- [systemd](https://github.com/kurayama/systemd-vim-syntax) (syntax)
|
||||
- [terraform](https://github.com/hashivim/vim-terraform) (syntax, indent, ftplugin)
|
||||
- [textile](https://github.com/timcharper/textile.vim) (syntax, ftplugin)
|
||||
- [thrift](https://github.com/solarnz/thrift.vim) (syntax)
|
||||
- [tmux](https://github.com/keith/tmux.vim) (syntax, ftplugin)
|
||||
- [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)
|
||||
- [twig](https://github.com/lumiliet/vim-twig) (syntax, indent, ftplugin)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [vala](https://github.com/arrufat/vala.vim) (syntax, indent, ftdetect)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin)
|
||||
- [vala](https://github.com/arrufat/vala.vim) (syntax, indent)
|
||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax, ftdetect)
|
||||
- [vue](https://github.com/posva/vim-vue) (syntax, indent, ftplugin, ftdetect)
|
||||
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent, ftdetect)
|
||||
- [vcl](https://github.com/smerrill/vcl-vim-plugin) (syntax)
|
||||
- [vifm](https://github.com/vifm/vifm.vim) (syntax, autoload, ftplugin)
|
||||
- [vm](https://github.com/lepture/vim-velocity) (syntax, indent)
|
||||
- [vue](https://github.com/posva/vim-vue) (syntax, indent, ftplugin)
|
||||
- [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)
|
||||
|
||||
@@ -12,7 +12,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jsx') == -1
|
||||
if exists("loaded_matchit")
|
||||
let b:match_ignorecase = 0
|
||||
let b:match_words = '(:),\[:\],{:},<:>,' .
|
||||
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
|
||||
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(/\@<!>\|$\):<\@<=/\1>'
|
||||
endif
|
||||
|
||||
setlocal suffixesadd+=.jsx
|
||||
|
||||
@@ -4,6 +4,14 @@ if !exists('g:terraform_align')
|
||||
let g:terraform_align = 0
|
||||
endif
|
||||
|
||||
if !exists('g:terraform_remap_spacebar')
|
||||
let g:terraform_remap_spacebar = 0
|
||||
endif
|
||||
|
||||
if !exists('g:terraform_fold_sections')
|
||||
let g:terraform_fold_sections = 0
|
||||
endif
|
||||
|
||||
if g:terraform_align && exists(':Tabularize')
|
||||
inoremap <buffer> <silent> = =<Esc>:call <SID>terraformalign()<CR>a
|
||||
function! s:terraformalign()
|
||||
@@ -18,4 +26,53 @@ if g:terraform_align && exists(':Tabularize')
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if g:terraform_fold_sections
|
||||
function! TerraformFolds()
|
||||
let thisline = getline(v:lnum)
|
||||
if match(thisline, '^resource') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^provider') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^module') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^variable') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^output') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^data') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^terraform') >= 0
|
||||
return ">1"
|
||||
elseif match(thisline, '^locals') >= 0
|
||||
return ">1"
|
||||
else
|
||||
return "="
|
||||
endif
|
||||
endfunction
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=TerraformFolds()
|
||||
setlocal foldlevel=1
|
||||
|
||||
function! TerraformFoldText()
|
||||
let foldsize = (v:foldend-v:foldstart)
|
||||
return getline(v:foldstart).' ('.foldsize.' lines)'
|
||||
endfunction
|
||||
setlocal foldtext=TerraformFoldText()
|
||||
endif
|
||||
|
||||
" Re-map the space bar to fold and unfold
|
||||
if get(g:, "terraform_remap_spacebar", 1)
|
||||
"inoremap <space> <C-O>za
|
||||
nnoremap <space> za
|
||||
onoremap <space> <C-C>za
|
||||
vnoremap <space> zf
|
||||
endif
|
||||
|
||||
" Match the identation put in place by Hashicorp and :TerraformFmt, https://github.com/hashivim/vim-terraform/issues/21
|
||||
if get(g:, "terraform_align", 1)
|
||||
setlocal tabstop=2
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -20,9 +20,21 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
||||
" -----------------------------------------------------------------------------
|
||||
" Highlight function names.
|
||||
" -----------------------------------------------------------------------------
|
||||
if !exists('g:cpp_no_function_highlight')
|
||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
||||
syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen
|
||||
hi def link cCustomFunc Function
|
||||
endif
|
||||
|
||||
" -----------------------------------------------------------------------------
|
||||
" Highlight member variable names.
|
||||
" -----------------------------------------------------------------------------
|
||||
if exists('g:cpp_member_variable_highlight') && g:cpp_member_variable_highlight
|
||||
syn match cCustomDot "\." contained
|
||||
syn match cCustomPtr "->" contained
|
||||
syn match cCustomMemVar "\(\.\|->\)\w\+" contains=cCustomDot,cCustomPtr
|
||||
hi def link cCustomMemVar Function
|
||||
endif
|
||||
|
||||
" -----------------------------------------------------------------------------
|
||||
" Source: aftersyntaxc.vim
|
||||
|
||||
@@ -36,9 +36,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
||||
" -----------------------------------------------------------------------------
|
||||
|
||||
" Functions
|
||||
if !exists('g:cpp_no_function_highlight')
|
||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
||||
syn match cCustomFunc "\w\+\s*(\@="
|
||||
hi def link cCustomFunc Function
|
||||
endif
|
||||
|
||||
" Class and namespace scope
|
||||
if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight
|
||||
@@ -48,6 +50,52 @@ if exists('g:cpp_class_scope_highlight') && g:cpp_class_scope_highlight
|
||||
hi def link cCustomClass Function
|
||||
endif
|
||||
|
||||
" Clear cppStructure and replace "class" and/or "template" with matches
|
||||
" based on user configuration
|
||||
let s:needs_cppstructure_match = 0
|
||||
if exists('g:cpp_class_decl_highlight') && g:cpp_class_decl_highlight
|
||||
let s:needs_cppstructure_match += 1
|
||||
endif
|
||||
if exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_template_highlight
|
||||
let s:needs_cppstructure_match += 2
|
||||
endif
|
||||
|
||||
syn clear cppStructure
|
||||
if s:needs_cppstructure_match == 0
|
||||
syn keyword cppStructure typename namespace template class
|
||||
elseif s:needs_cppstructure_match == 1
|
||||
syn keyword cppStructure typename namespace template
|
||||
elseif s:needs_cppstructure_match == 2
|
||||
syn keyword cppStructure typename namespace class
|
||||
elseif s:needs_cppstructure_match == 3
|
||||
syn keyword cppStructure typename namespace
|
||||
endif
|
||||
unlet s:needs_cppstructure_match
|
||||
|
||||
|
||||
" Class name declaration
|
||||
if exists('g:cpp_class_decl_highlight') && g:cpp_class_decl_highlight
|
||||
syn match cCustomClassKey "\<class\>"
|
||||
hi def link cCustomClassKey cppStructure
|
||||
|
||||
" Clear cppAccess entirely and redefine as matches
|
||||
syn clear cppAccess
|
||||
syn match cCustomAccessKey "\<private\>"
|
||||
syn match cCustomAccessKey "\<public\>"
|
||||
syn match cCustomAccessKey "\<protected\>"
|
||||
hi def link cCustomAccessKey cppAccess
|
||||
|
||||
" Match the parts of a class declaration
|
||||
syn match cCustomClassName "\<class\_s\+\w\+\>"
|
||||
\ contains=cCustomClassKey
|
||||
syn match cCustomClassName "\<private\_s\+\w\+\>"
|
||||
\ contains=cCustomAccessKey
|
||||
syn match cCustomClassName "\<public\_s\+\w\+\>"
|
||||
\ contains=cCustomAccessKey
|
||||
syn match cCustomClassName "\<protected\_s\+\w\+\>"
|
||||
\ contains=cCustomAccessKey
|
||||
hi def link cCustomClassName Function
|
||||
endif
|
||||
" Template functions.
|
||||
" Naive implementation that sorta works in most cases. Should correctly
|
||||
" highlight everything in test/color2.cpp
|
||||
@@ -79,17 +127,12 @@ elseif exists('g:cpp_experimental_template_highlight') && g:cpp_experimental_tem
|
||||
\ 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
|
||||
\ contains=cppStructure,cCustomTemplate,cCustomClassKey,cCustomAngleBracketStart
|
||||
|
||||
" Remove 'operator' from cppStructure and use a custom match
|
||||
" Remove 'operator' from cppOperator 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
|
||||
@@ -106,7 +149,7 @@ endif
|
||||
"hi def link cCustomFunc Function
|
||||
|
||||
" Cluster for all the stdlib functions defined below
|
||||
syn cluster cppSTLgroup contains=cppSTLfunction,cppSTLfunctional,cppSTLconstant,cppSTLnamespace,cppSTLtype,cppSTLexception,cppSTLiterator,cppSTLiterator_tagcppSTLenumcppSTLioscppSTLcast
|
||||
syn cluster cppSTLgroup contains=cppSTLfunction,cppSTLfunctional,cppSTLconstant,cppSTLnamespace,cppSTLtype,cppSTLexception,cppSTLiterator,cppSTLiterator_tag,cppSTLenum,cppSTLios,cppSTLcast
|
||||
|
||||
|
||||
" -----------------------------------------------------------------------------
|
||||
@@ -184,6 +227,7 @@ syntax keyword cppSTLfunctional binary_negate
|
||||
syntax keyword cppSTLfunctional bit_and
|
||||
syntax keyword cppSTLfunctional bit_not
|
||||
syntax keyword cppSTLfunctional bit_or
|
||||
syntax keyword cppSTLfunctional bit_xor
|
||||
syntax keyword cppSTLfunctional divides
|
||||
syntax keyword cppSTLfunctional equal_to
|
||||
syntax keyword cppSTLfunctional greater
|
||||
@@ -557,6 +601,7 @@ syntax keyword cppSTLios defaultfloat
|
||||
syntax keyword cppSTLios endl
|
||||
syntax keyword cppSTLios ends
|
||||
syntax keyword cppSTLios fixed
|
||||
syntax keyword cppSTLios floatfield
|
||||
syntax keyword cppSTLios flush
|
||||
syntax keyword cppSTLios get_money
|
||||
syntax keyword cppSTLios get_time
|
||||
@@ -698,6 +743,7 @@ syntax keyword cppSTLtype slice_array
|
||||
syntax keyword cppSTLtype stack
|
||||
syntax keyword cppSTLtype stream
|
||||
syntax keyword cppSTLtype streambuf
|
||||
syntax keyword cppSTLtype streamsize
|
||||
syntax keyword cppSTLtype string
|
||||
syntax keyword cppSTLtype stringbuf
|
||||
syntax keyword cppSTLtype stringstream
|
||||
|
||||
@@ -34,6 +34,22 @@ syn region ShaderScript
|
||||
\ end="</script>"me=s-1
|
||||
\ contains=@GLSL,htmlScriptTag,@htmlPreproc
|
||||
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
||||
|
||||
" Vim syntax file
|
||||
" Language: HTML (version 5.1)
|
||||
" Last Change: 2017 Feb 15
|
||||
" License: Public domain
|
||||
" (but let me know if you like :) )
|
||||
"
|
||||
" Maintainer: Kao, Wei-Ko(othree) ( othree AT gmail DOT com )
|
||||
|
||||
" Comment
|
||||
" https://github.com/w3c/html/issues/694
|
||||
syntax region htmlComment start=+<!--+ end=+-->+ contains=@Spell
|
||||
syntax region htmlComment start=+<!DOCTYPE+ keepend end=+>+
|
||||
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'less') == -1
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ syn region jsxChild contained start=+{+ end=++ contains=jsBlock,javascriptBlock
|
||||
" and generic Flow type annotations (http://flowtype.org/).
|
||||
syn region jsxRegion
|
||||
\ contains=@Spell,@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=+<!--\_.\{-}-->+
|
||||
\ end=+</\z1\_\s\{-}>+
|
||||
\ end=+/>+
|
||||
|
||||
107
after/syntax/mma.vim
Normal file
107
after/syntax/mma.vim
Normal file
@@ -0,0 +1,107 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mathematica') == -1
|
||||
|
||||
"Vim conceal file
|
||||
" Language: Mathematica
|
||||
" Maintainer: R. Menon <rsmenon@icloud.com>
|
||||
" Last Change: Feb 25, 2013
|
||||
|
||||
if (exists('g:mma_candy') && g:mma_candy == 0) || !has('conceal') || &enc != 'utf-8'
|
||||
finish
|
||||
endif
|
||||
|
||||
"These are fairly safe and straightforward conceals
|
||||
if exists('g:mma_candy') && g:mma_candy > 0
|
||||
"Rules
|
||||
syntax match mmaOperator "->" conceal cchar=→ "Rule
|
||||
syntax match mmaOperator ":>" conceal cchar=⧴ "RuleDelayed
|
||||
|
||||
"Logicals
|
||||
syntax match mmaOperator "===" conceal cchar=≡ "SameQ
|
||||
syntax match mmaOperator "=!=" conceal cchar=≢ "UnsameQ
|
||||
syntax match mmaOperator "!=" conceal cchar=≠ "NotEqual
|
||||
syntax match mmaOperator "<=" conceal cchar=≤ "LessEqual
|
||||
syntax match mmaOperator ">=" conceal cchar=≥ "GreaterEqual
|
||||
|
||||
"Constants
|
||||
syntax keyword mmaSystemSymbol Pi conceal cchar=π
|
||||
syntax keyword mmaSystemSymbol Infinity conceal cchar=∞
|
||||
syntax keyword mmaSystemSymbol Degree conceal cchar=°
|
||||
|
||||
"Domains
|
||||
syntax keyword mmaSystemSymbol Reals conceal cchar=ℝ
|
||||
syntax keyword mmaSystemSymbol Integers conceal cchar=ℤ
|
||||
syntax keyword mmaSystemSymbol Complexes conceal cchar=ℂ
|
||||
syntax keyword mmaSystemSymbol Rationals conceal cchar=ℚ
|
||||
|
||||
"Greek
|
||||
syntax match mmaSymbol "\\\[CapitalAlpha\]" conceal cchar=Α
|
||||
syntax match mmaSymbol "\\\[CapitalBeta\]" conceal cchar=Β
|
||||
syntax match mmaSymbol "\\\[CapitalGamma\]" conceal cchar=Γ
|
||||
syntax match mmaSymbol "\\\[CapitalDelta\]" conceal cchar=Δ
|
||||
syntax match mmaSymbol "\\\[CapitalEpsilon\]" conceal cchar=Ε
|
||||
syntax match mmaSymbol "\\\[CapitalZeta\]" conceal cchar=Ζ
|
||||
syntax match mmaSymbol "\\\[CapitalEta\]" conceal cchar=Η
|
||||
syntax match mmaSymbol "\\\[CapitalTheta\]" conceal cchar=Θ
|
||||
syntax match mmaSymbol "\\\[CapitalIota\]" conceal cchar=Ι
|
||||
syntax match mmaSymbol "\\\[CapitalKappa\]" conceal cchar=Κ
|
||||
syntax match mmaSymbol "\\\[CapitalLambda\]" conceal cchar=Λ
|
||||
syntax match mmaSymbol "\\\[CapitalMu\]" conceal cchar=Μ
|
||||
syntax match mmaSymbol "\\\[CapitalNu\]" conceal cchar=Ν
|
||||
syntax match mmaSymbol "\\\[CapitalXi\]" conceal cchar=Ξ
|
||||
syntax match mmaSymbol "\\\[CapitalOmicron\]" conceal cchar=Ο
|
||||
syntax match mmaSymbol "\\\[CapitalPi\]" conceal cchar=Π
|
||||
syntax match mmaSymbol "\\\[CapitalRho\]" conceal cchar=Ρ
|
||||
syntax match mmaSymbol "\\\[CapitalSigma\]" conceal cchar=Σ
|
||||
syntax match mmaSymbol "\\\[CapitalTau\]" conceal cchar=Τ
|
||||
syntax match mmaSymbol "\\\[CapitalUpsilon\]" conceal cchar=Υ
|
||||
syntax match mmaSymbol "\\\[CapitalPhi\]" conceal cchar=Φ
|
||||
syntax match mmaSymbol "\\\[CapitalChi\]" conceal cchar=Χ
|
||||
syntax match mmaSymbol "\\\[CapitalPsi\]" conceal cchar=Ψ
|
||||
syntax match mmaSymbol "\\\[CapitalOmega\]" conceal cchar=Ω
|
||||
syntax match mmaSymbol "\\\[Alpha\]" conceal cchar=α
|
||||
syntax match mmaSymbol "\\\[Beta\]" conceal cchar=β
|
||||
syntax match mmaSymbol "\\\[Gamma\]" conceal cchar=γ
|
||||
syntax match mmaSymbol "\\\[Delta\]" conceal cchar=δ
|
||||
syntax match mmaSymbol "\\\[Epsilon\]" conceal cchar=ε
|
||||
syntax match mmaSymbol "\\\[Zeta\]" conceal cchar=ζ
|
||||
syntax match mmaSymbol "\\\[Eta\]" conceal cchar=η
|
||||
syntax match mmaSymbol "\\\[Theta\]" conceal cchar=θ
|
||||
syntax match mmaSymbol "\\\[Iota\]" conceal cchar=ι
|
||||
syntax match mmaSymbol "\\\[Kappa\]" conceal cchar=κ
|
||||
syntax match mmaSymbol "\\\[Lambda\]" conceal cchar=λ
|
||||
syntax match mmaSymbol "\\\[Mu\]" conceal cchar=μ
|
||||
syntax match mmaSymbol "\\\[Nu\]" conceal cchar=ν
|
||||
syntax match mmaSymbol "\\\[Xi\]" conceal cchar=ξ
|
||||
syntax match mmaSymbol "\\\[Omicron\]" conceal cchar=ο
|
||||
syntax match mmaSymbol "\\\[Pi\]" conceal cchar=π
|
||||
syntax match mmaSymbol "\\\[Rho\]" conceal cchar=ρ
|
||||
syntax match mmaSymbol "\\\[Sigma\]" conceal cchar=σ
|
||||
syntax match mmaSymbol "\\\[Tau\]" conceal cchar=τ
|
||||
syntax match mmaSymbol "\\\[Upsilon\]" conceal cchar=υ
|
||||
syntax match mmaSymbol "\\\[Phi\]" conceal cchar=φ
|
||||
syntax match mmaSymbol "\\\[Chi\]" conceal cchar=χ
|
||||
syntax match mmaSymbol "\\\[Psi\]" conceal cchar=ψ
|
||||
syntax match mmaSymbol "\\\[Omega\]" conceal cchar=ω
|
||||
endif
|
||||
|
||||
"These might be troublesome if the appropriate fonts are missing. Also, they don't
|
||||
"look quite as good as the earlier ones, so enable only if the user chooses to
|
||||
if exists('g:mma_candy') && g:mma_candy == 2
|
||||
"Constants
|
||||
syntax keyword mmaSystemSymbol I conceal cchar=ⅈ
|
||||
syntax keyword mmaSystemSymbol E conceal cchar=ⅇ
|
||||
|
||||
"Functions
|
||||
syntax keyword mmaSystemSymbol Sum conceal cchar=∑
|
||||
syntax keyword mmaSystemSymbol Product conceal cchar=∏
|
||||
syntax keyword mmaSystemSymbol Sqrt conceal cchar=√
|
||||
|
||||
"Misc
|
||||
syntax match mmaOperator ">>" conceal cchar=» "Put
|
||||
syntax match mmaOperator "<<" conceal cchar=« "Get
|
||||
endif
|
||||
|
||||
hi! link Conceal Normal
|
||||
setlocal conceallevel=2
|
||||
|
||||
endif
|
||||
@@ -1,13 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" adds support for cleverref package
|
||||
" \Cref, \cref, \cpageref, \labelcref, \labelcpageref
|
||||
syn region texRefZone matchgroup=texStatement start="\\Cref{" end="}\|%stopzone\>" contains=@texRefGroup
|
||||
syn region texRefZone matchgroup=texStatement start="\\\(label\|\)c\(page\|\)ref{" end="}\|%stopzone\>" contains=@texRefGroup
|
||||
|
||||
" adds support for listings package
|
||||
syn region texZone start="\\begin{lstlisting}" end="\\end{lstlisting}\|%stopzone\>"
|
||||
syn match texInputFile "\\lstinputlisting\s*\(\[.*\]\)\={.\{-}}" contains=texStatement,texInputCurlies,texInputFileOpt
|
||||
syn match texZone "\\lstinline\s*\(\[.*\]\)\={.\{-}}"
|
||||
|
||||
endif
|
||||
@@ -21,14 +21,12 @@ if version < 600
|
||||
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="\%(^\| \)\zs'" end="'\ze\%( \|$\)" skip="\\'"
|
||||
syn region yamlString start='"' end='"' skip='\\"' contains=yamlEscape
|
||||
syn match yamlEscape +\\[abfnrtv'"\\]+ contained
|
||||
syn match yamlEscape "\\\o\o\=\o\=" contained
|
||||
@@ -40,11 +38,12 @@ 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 "^\s*\zs\S\+\ze\s*:"
|
||||
syn match yamlKey "^\s*\zs[^ \t\"]\+\ze\s*:"
|
||||
syn match yamlKey "^\s*-\s*\zs[^ \t\"\']\+\ze\s*:"
|
||||
syn match yamlAnchor "&\S\+"
|
||||
syn match yamlAlias "*\S\+"
|
||||
|
||||
" Setupt the hilighting links
|
||||
" Setup the highlighting links
|
||||
|
||||
hi link yamlConstant Keyword
|
||||
hi link yamlIndicator PreCondit
|
||||
@@ -55,10 +54,7 @@ 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
|
||||
|
||||
625
autoload/LaTeXtoUnicode.vim
Normal file
625
autoload/LaTeXtoUnicode.vim
Normal file
@@ -0,0 +1,625 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'julia') == -1
|
||||
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Support for LaTex-to-Unicode conversion as in the Julia REPL "
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
function! s:L2U_Setup()
|
||||
|
||||
call s:L2U_SetupGlobal()
|
||||
|
||||
" Keep track of whether LaTeX-to-Unicode is activated
|
||||
" (used when filetype changes)
|
||||
if !has_key(b:, "l2u_enabled")
|
||||
let b:l2u_enabled = 0
|
||||
endif
|
||||
|
||||
" Did we install the L2U tab mappings?
|
||||
if !has_key(b:, "l2u_tab_set")
|
||||
let b:l2u_tab_set = 0
|
||||
endif
|
||||
if !has_key(b:, "l2u_cmdtab_set")
|
||||
let b:l2u_cmdtab_set = 0
|
||||
endif
|
||||
|
||||
" Did we activate the L2U as-you-type substitutions?
|
||||
if !has_key(b:, "l2u_autosub_set")
|
||||
let b:l2u_autosub_set = 0
|
||||
endif
|
||||
|
||||
" Following are some flags used to pass information between the function which
|
||||
" attempts the LaTeX-to-Unicode completion and the fallback function
|
||||
|
||||
" Was a (possibly partial) completion found?
|
||||
let b:l2u_found_completion = 0
|
||||
" Is the cursor just after a single backslash
|
||||
let b:l2u_singlebslash = 0
|
||||
" Backup value of the completeopt settings
|
||||
" (since we temporarily add the 'longest' setting while
|
||||
" attempting LaTeX-to-Unicode)
|
||||
let b:l2u_backup_commpleteopt = &completeopt
|
||||
" Are we in the middle of a L2U tab completion?
|
||||
let b:l2u_tab_completing = 0
|
||||
" Are we calling the tab fallback?
|
||||
let b:l2u_in_fallback = 0
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:L2U_SetupGlobal()
|
||||
|
||||
" Initialization of global and script-local variables
|
||||
" is only performed once
|
||||
if get(g:, "l2u_did_global_setup", 0)
|
||||
return
|
||||
endif
|
||||
|
||||
let g:l2u_did_global_setup = 1
|
||||
|
||||
let g:l2u_symbols_dict = julia_latex_symbols#get_dict()
|
||||
|
||||
call s:L2U_deprecated_options()
|
||||
|
||||
if v:version < 704
|
||||
let g:latex_to_unicode_tab = 0
|
||||
let g:latex_to_unicode_auto = 0
|
||||
endif
|
||||
|
||||
" YouCompleteMe and neocomplcache/neocomplete/deoplete plug-ins do not work well
|
||||
" with LaTeX symbols suggestions
|
||||
if exists("g:loaded_youcompleteme") ||
|
||||
\ exists("g:loaded_neocomplcache") ||
|
||||
\ exists("g:loaded_neocomplete") ||
|
||||
\ exists("g:loaded_deoplete")
|
||||
let g:latex_to_unicode_suggestions = 0
|
||||
endif
|
||||
|
||||
" A hack to forcibly get out of completion mode: feed
|
||||
" this string with feedkeys()
|
||||
if has("win32") || has("win64")
|
||||
if has("gui_running")
|
||||
let s:l2u_esc_sequence = "\u0006"
|
||||
else
|
||||
let s:l2u_esc_sequence = "\u0006\b"
|
||||
endif
|
||||
else
|
||||
let s:l2u_esc_sequence = "\u0091\b"
|
||||
end
|
||||
|
||||
" Trigger for the previous mapping of <Tab>
|
||||
let s:l2u_fallback_trigger = "\u0091L2UFallbackTab"
|
||||
|
||||
endfunction
|
||||
|
||||
" Each time the filetype changes, we may need to enable or
|
||||
" disable the LaTeX-to-Unicode functionality
|
||||
function! LaTeXtoUnicode#Refresh()
|
||||
|
||||
call s:L2U_Setup()
|
||||
|
||||
" by default, LaTeX-to-Unicode is only active on julia files
|
||||
let file_types = s:L2U_file_type_regex(get(g:, "latex_to_unicode_file_types", "julia"))
|
||||
let file_types_blacklist = s:L2U_file_type_regex(get(g:, "latex_to_unicode_file_types_blacklist", "$^"))
|
||||
|
||||
if match(&filetype, file_types) < 0 || match(&filetype, file_types_blacklist) >= 0
|
||||
if b:l2u_enabled
|
||||
call LaTeXtoUnicode#Disable()
|
||||
else
|
||||
return
|
||||
endif
|
||||
elseif !b:l2u_enabled
|
||||
call LaTeXtoUnicode#Enable()
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
function! LaTeXtoUnicode#Enable()
|
||||
|
||||
if b:l2u_enabled
|
||||
return
|
||||
end
|
||||
|
||||
call s:L2U_ResetLastCompletionInfo()
|
||||
|
||||
let b:l2u_enabled = 1
|
||||
|
||||
" If we're editing the first file upon opening vim, this will only init the
|
||||
" command line mode mapping, and the full initialization will be performed by
|
||||
" the autocmd triggered by InsertEnter, defined in /ftdetect.vim.
|
||||
" Otherwise, if we're opening a file from within a running vim session, this
|
||||
" will actually initialize all the LaTeX-to-Unicode substitutions.
|
||||
call LaTeXtoUnicode#Init()
|
||||
|
||||
return
|
||||
|
||||
endfunction
|
||||
|
||||
function! LaTeXtoUnicode#Disable()
|
||||
if !b:l2u_enabled
|
||||
return
|
||||
endif
|
||||
let b:l2u_enabled = 0
|
||||
call LaTeXtoUnicode#Init()
|
||||
return
|
||||
endfunction
|
||||
|
||||
" Translate old options to their new equivalents
|
||||
function! s:L2U_deprecated_options()
|
||||
for [new, old] in [["latex_to_unicode_tab", "julia_latex_to_unicode"],
|
||||
\ ["latex_to_unicode_auto", "julia_auto_latex_to_unicode"],
|
||||
\ ["latex_to_unicode_suggestions", "julia_latex_suggestions_enabled"],
|
||||
\ ["latex_to_unicode_eager", "julia_latex_to_unicode_eager"]]
|
||||
if !has_key(g:, new) && has_key(g:, old)
|
||||
exec "let g:" . new . " = g:" . old
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:L2U_file_type_regex(ft)
|
||||
if type(a:ft) == 3
|
||||
let file_types = "\\%(" . join(a:ft, "\\|") . "\\)"
|
||||
elseif type(a:ft) == 1
|
||||
let file_types = a:ft
|
||||
else
|
||||
echoerr "invalid file_type specification"
|
||||
endif
|
||||
return "^" . file_types . "$"
|
||||
endfunction
|
||||
|
||||
" Some data used to keep track of the previous completion attempt.
|
||||
" Used to detect
|
||||
" 1) if we just attempted the same completion, or
|
||||
" 2) if backspace was just pressed while completing
|
||||
" This function initializes and resets the required info
|
||||
|
||||
function! s:L2U_ResetLastCompletionInfo()
|
||||
let b:l2u_completed_once = 0
|
||||
let b:l2u_bs_while_completing = 0
|
||||
let b:l2u_last_compl = {
|
||||
\ 'line': '',
|
||||
\ 'col0': -1,
|
||||
\ 'col1': -1,
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
" This function only detects whether an exact match is found for a LaTeX
|
||||
" symbol in front of the cursor
|
||||
function! s:L2U_ismatch()
|
||||
let col1 = col('.')
|
||||
let l = getline('.')
|
||||
let col0 = match(l[0:col1-2], '\\[^[:space:]\\]\+$')
|
||||
if col0 == -1
|
||||
return 0
|
||||
endif
|
||||
let base = l[col0 : col1-1]
|
||||
return has_key(g:l2u_symbols_dict, base)
|
||||
endfunction
|
||||
|
||||
" Helper function to sort suggestion entries
|
||||
function! s:L2U_partmatches_sort(p1, p2)
|
||||
return a:p1.word > a:p2.word ? 1 : a:p1.word < a:p2.word ? -1 : 0
|
||||
endfunction
|
||||
|
||||
" Helper function to fix display of Unicode compose characters
|
||||
" in the suggestions menu (they are displayed on top of '◌')
|
||||
function! s:L2U_fix_compose_chars(uni)
|
||||
let u = matchstr(a:uni, '^.')
|
||||
let isc = ("\u0300" <= u && u <= "\u036F") ||
|
||||
\ ("\u1DC0" <= u && u <= "\u1DFF") ||
|
||||
\ ("\u20D0" <= u && u <= "\u20FF") ||
|
||||
\ ("\uFE20" <= u && u <= "\uFE2F")
|
||||
return isc ? "\u25CC" . a:uni : a:uni
|
||||
endfunction
|
||||
|
||||
" Helper function to find the longest common prefix among
|
||||
" partial completion matches (used when suggestions are disabled
|
||||
" and in command line mode)
|
||||
function! s:L2U_longest_common_prefix(partmatches)
|
||||
let common = a:partmatches[0]
|
||||
for i in range(1, len(a:partmatches)-1)
|
||||
let p = a:partmatches[i]
|
||||
if len(p) < len(common)
|
||||
let common = common[0 : len(p)-1]
|
||||
endif
|
||||
for j in range(1, len(common)-1)
|
||||
if p[j] != common[j]
|
||||
let common = common[0 : j-1]
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
return common
|
||||
endfunction
|
||||
|
||||
" Omnicompletion function. Besides the usual two-stage omnifunc behaviour,
|
||||
" it has the following peculiar features:
|
||||
" *) keeps track of the previous completion attempt
|
||||
" *) sets some info to be used by the fallback function
|
||||
" *) either returns a list of completions if a partial match is found, or a
|
||||
" Unicode char if an exact match is found
|
||||
" *) forces its way out of completion mode through a hack in some cases
|
||||
function! LaTeXtoUnicode#omnifunc(findstart, base)
|
||||
if a:findstart
|
||||
" first stage
|
||||
" avoid infinite loop if the fallback happens to call omnicompletion
|
||||
if b:l2u_in_fallback
|
||||
let b:l2u_in_fallback = 0
|
||||
return -3
|
||||
endif
|
||||
let b:l2u_in_fallback = 0
|
||||
" set info for the callback
|
||||
let b:l2u_tab_completing = 1
|
||||
let b:l2u_found_completion = 1
|
||||
" analyse current line
|
||||
let col1 = col('.')
|
||||
let l = getline('.')
|
||||
let col0 = match(l[0:col1-2], '\\[^[:space:]\\]\+$')
|
||||
" compare with previous completion attempt
|
||||
let b:l2u_bs_while_completing = 0
|
||||
let b:l2u_completed_once = 0
|
||||
if col0 == b:l2u_last_compl['col0']
|
||||
let prevl = b:l2u_last_compl['line']
|
||||
if col1 == b:l2u_last_compl['col1'] && l ==# prevl
|
||||
let b:l2u_completed_once = 1
|
||||
elseif col1 == b:l2u_last_compl['col1'] - 1 && l ==# prevl[0 : col1-2] . prevl[col1 : -1]
|
||||
let b:l2u_bs_while_completing = 1
|
||||
endif
|
||||
endif
|
||||
" store completion info for next attempt
|
||||
let b:l2u_last_compl['col0'] = col0
|
||||
let b:l2u_last_compl['col1'] = col1
|
||||
let b:l2u_last_compl['line'] = l
|
||||
" is the cursor right after a backslash?
|
||||
let b:l2u_singlebslash = (match(l[0:col1-2], '\\$') >= 0)
|
||||
" completion not found
|
||||
if col0 == -1
|
||||
let b:l2u_found_completion = 0
|
||||
call feedkeys(s:l2u_esc_sequence, 'n')
|
||||
let col0 = -2
|
||||
endif
|
||||
return col0
|
||||
else
|
||||
" read settings (eager mode is implicit when suggestions are disabled)
|
||||
let suggestions = get(g:, "latex_to_unicode_suggestions", 1)
|
||||
let eager = get(g:, "latex_to_unicode_eager", 1) || !suggestions
|
||||
" search for matches
|
||||
let partmatches = []
|
||||
let exact_match = 0
|
||||
for k in keys(g:l2u_symbols_dict)
|
||||
if k ==# a:base
|
||||
let exact_match = 1
|
||||
endif
|
||||
if len(k) >= len(a:base) && k[0 : len(a:base)-1] ==# a:base
|
||||
let menu = s:L2U_fix_compose_chars(g:l2u_symbols_dict[k])
|
||||
if suggestions
|
||||
call add(partmatches, {'word': k, 'menu': menu})
|
||||
else
|
||||
call add(partmatches, k)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
" exact matches are replaced with Unicode
|
||||
" exceptions:
|
||||
" *) we reached an exact match by pressing backspace while completing
|
||||
" *) the exact match is one among many, and the eager setting is
|
||||
" disabled, and it's the first time this completion is attempted
|
||||
if exact_match && !b:l2u_bs_while_completing && (len(partmatches) == 1 || eager || b:l2u_completed_once)
|
||||
" the completion is successful: reset the last completion info...
|
||||
call s:L2U_ResetLastCompletionInfo()
|
||||
" ...force our way out of completion mode...
|
||||
call feedkeys(s:l2u_esc_sequence, 'n')
|
||||
" ...return the Unicode symbol
|
||||
return [g:l2u_symbols_dict[a:base]]
|
||||
endif
|
||||
if !empty(partmatches)
|
||||
" here, only partial matches were found; either keep just the longest
|
||||
" common prefix, or pass them on
|
||||
if !suggestions
|
||||
let partmatches = [s:L2U_longest_common_prefix(partmatches)]
|
||||
else
|
||||
call sort(partmatches, "s:L2U_partmatches_sort")
|
||||
endif
|
||||
endif
|
||||
if empty(partmatches)
|
||||
call feedkeys(s:l2u_esc_sequence, 'n')
|
||||
let b:l2u_found_completion = 0
|
||||
endif
|
||||
return partmatches
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! LaTeXtoUnicode#PutLiteral(k)
|
||||
call feedkeys(a:k, 'ni')
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" Function which saves the current insert-mode mapping of a key sequence `s`
|
||||
" and associates it with another key sequence `k` (e.g. stores the current
|
||||
" <Tab> mapping into the Fallback trigger)
|
||||
function! s:L2U_SetFallbackMapping(s, k)
|
||||
let mmdict = maparg(a:s, 'i', 0, 1)
|
||||
if empty(mmdict)
|
||||
exe 'inoremap <buffer> ' . a:k . ' ' . a:s
|
||||
return
|
||||
endif
|
||||
let rhs = mmdict["rhs"]
|
||||
if rhs =~# '^<Plug>L2U'
|
||||
return
|
||||
endif
|
||||
let pre = '<buffer>'
|
||||
if mmdict["silent"]
|
||||
let pre = pre . '<silent>'
|
||||
endif
|
||||
if mmdict["expr"]
|
||||
let pre = pre . '<expr>'
|
||||
endif
|
||||
if mmdict["noremap"]
|
||||
let cmd = 'inoremap '
|
||||
else
|
||||
let cmd = 'imap '
|
||||
" This is a nasty hack used to prevent infinite recursion. It's not a
|
||||
" general solution.
|
||||
if mmdict["expr"]
|
||||
let rhs = substitute(rhs, '\c' . a:s, "\<C-R>=LaTeXtoUnicode#PutLiteral('" . a:s . "')\<CR>", 'g')
|
||||
endif
|
||||
endif
|
||||
exe cmd . pre . ' ' . a:k . ' ' . rhs
|
||||
endfunction
|
||||
|
||||
" This is the function which is mapped to <Tab>
|
||||
function! LaTeXtoUnicode#Tab()
|
||||
" the <Tab> is passed through to the fallback mapping if the completion
|
||||
" menu is present, and it hasn't been raised by the L2U tab, and there
|
||||
" isn't an exact match before the cursor when suggestions are disabled
|
||||
if pumvisible() && !b:l2u_tab_completing && (get(g:, "latex_to_unicode_suggestions", 1) || !s:L2U_ismatch())
|
||||
call feedkeys(s:l2u_fallback_trigger)
|
||||
return ''
|
||||
endif
|
||||
" reset the in_fallback info
|
||||
let b:l2u_in_fallback = 0
|
||||
" temporary change to completeopt to use the `longest` setting, which is
|
||||
" probably the only one which makes sense given that the goal of the
|
||||
" completion is to substitute the final string
|
||||
let b:l2u_backup_commpleteopt = &completeopt
|
||||
set completeopt+=longest
|
||||
set completeopt-=noinsert
|
||||
" invoke omnicompletion; failure to perform LaTeX-to-Unicode completion is
|
||||
" handled by the CompleteDone autocommand.
|
||||
return "\<C-X>\<C-O>"
|
||||
endfunction
|
||||
|
||||
" This function is called at every CompleteDone event, and is meant to handle
|
||||
" the failures of LaTeX-to-Unicode completion by calling a fallback
|
||||
function! LaTeXtoUnicode#FallbackCallback()
|
||||
if !b:l2u_tab_completing
|
||||
" completion was not initiated by L2U, nothing to do
|
||||
return
|
||||
else
|
||||
" completion was initiated by L2U, restore completeopt
|
||||
let &completeopt = b:l2u_backup_commpleteopt
|
||||
endif
|
||||
" at this point L2U tab completion is over
|
||||
let b:l2u_tab_completing = 0
|
||||
" if the completion was successful do nothing
|
||||
if b:l2u_found_completion == 1 || b:l2u_singlebslash == 1
|
||||
return
|
||||
endif
|
||||
" fallback
|
||||
let b:l2u_in_fallback = 1
|
||||
call feedkeys(s:l2u_fallback_trigger)
|
||||
return
|
||||
endfunction
|
||||
|
||||
" This is the function which is mapped to <S-Tab> in command-line mode
|
||||
function! LaTeXtoUnicode#CmdTab()
|
||||
" first stage
|
||||
" analyse command line
|
||||
let col1 = getcmdpos() - 1
|
||||
let l = getcmdline()
|
||||
let col0 = match(l[0:col1-1], '\\[^[:space:]\\]\+$')
|
||||
let b:l2u_singlebslash = (match(l[0:col1-1], '\\$') >= 0)
|
||||
" completion not found
|
||||
if col0 == -1
|
||||
return l
|
||||
endif
|
||||
let base = l[col0 : col1-1]
|
||||
" search for matches
|
||||
let partmatches = []
|
||||
let exact_match = 0
|
||||
for k in keys(g:l2u_symbols_dict)
|
||||
if k ==# base
|
||||
let exact_match = 1
|
||||
endif
|
||||
if len(k) >= len(base) && k[0 : len(base)-1] ==# base
|
||||
call add(partmatches, k)
|
||||
endif
|
||||
endfor
|
||||
if len(partmatches) == 0
|
||||
return l
|
||||
endif
|
||||
" exact matches are replaced with Unicode
|
||||
if exact_match
|
||||
let unicode = g:l2u_symbols_dict[base]
|
||||
if col0 > 0
|
||||
let pre = l[0 : col0 - 1]
|
||||
else
|
||||
let pre = ''
|
||||
endif
|
||||
let posdiff = col1-col0 - len(unicode)
|
||||
call setcmdpos(col1 - posdiff + 1)
|
||||
return pre . unicode . l[col1 : -1]
|
||||
endif
|
||||
" no exact match: complete with the longest common prefix
|
||||
let common = s:L2U_longest_common_prefix(partmatches)
|
||||
if col0 > 0
|
||||
let pre = l[0 : col0 - 1]
|
||||
else
|
||||
let pre = ''
|
||||
endif
|
||||
let posdiff = col1-col0 - len(common)
|
||||
call setcmdpos(col1 - posdiff + 1)
|
||||
return pre . common . l[col1 : -1]
|
||||
endfunction
|
||||
|
||||
" Setup the L2U tab mapping
|
||||
function! s:L2U_SetTab(wait_insert_enter)
|
||||
if !b:l2u_cmdtab_set && get(g:, "latex_to_unicode_tab", 1) && b:l2u_enabled
|
||||
cmap <buffer> <S-Tab> <Plug>L2UCmdTab
|
||||
cnoremap <buffer> <Plug>L2UCmdTab <C-\>eLaTeXtoUnicode#CmdTab()<CR>
|
||||
let b:l2u_cmdtab_set = 1
|
||||
endif
|
||||
if b:l2u_tab_set
|
||||
return
|
||||
endif
|
||||
" g:did_insert_enter is set from an autocommand in ftdetect
|
||||
if a:wait_insert_enter && !get(g:, "did_insert_enter", 0)
|
||||
return
|
||||
endif
|
||||
if !get(g:, "latex_to_unicode_tab", 1) || !b:l2u_enabled
|
||||
return
|
||||
endif
|
||||
|
||||
" Backup the previous omnifunc (the check is probably not really needed)
|
||||
if get(b:, "prev_omnifunc", "") != "LaTeXtoUnicode#omnifunc"
|
||||
let b:prev_omnifunc = &omnifunc
|
||||
endif
|
||||
setlocal omnifunc=LaTeXtoUnicode#omnifunc
|
||||
|
||||
call s:L2U_SetFallbackMapping('<Tab>', s:l2u_fallback_trigger)
|
||||
imap <buffer> <Tab> <Plug>L2UTab
|
||||
inoremap <buffer><expr> <Plug>L2UTab LaTeXtoUnicode#Tab()
|
||||
|
||||
augroup L2UTab
|
||||
autocmd! * <buffer>
|
||||
" Every time a completion finishes, the fallback may be invoked
|
||||
autocmd CompleteDone <buffer> call LaTeXtoUnicode#FallbackCallback()
|
||||
augroup END
|
||||
|
||||
let b:l2u_tab_set = 1
|
||||
endfunction
|
||||
|
||||
" Revert the LaTeX-to-Unicode tab mapping settings
|
||||
function! s:L2U_UnsetTab()
|
||||
if b:l2u_cmdtab_set
|
||||
cunmap <buffer> <S-Tab>
|
||||
let b:l2u_cmdtab_set = 0
|
||||
endif
|
||||
if !b:l2u_tab_set
|
||||
return
|
||||
endif
|
||||
exec "setlocal omnifunc=" . get(b:, "prev_omnifunc", "")
|
||||
iunmap <buffer> <Tab>
|
||||
if empty(maparg("<Tab>", "i"))
|
||||
call s:L2U_SetFallbackMapping(s:l2u_fallback_trigger, '<Tab>')
|
||||
endif
|
||||
iunmap <buffer> <Plug>L2UTab
|
||||
exe 'iunmap <buffer> ' . s:l2u_fallback_trigger
|
||||
augroup L2UTab
|
||||
autocmd! * <buffer>
|
||||
augroup END
|
||||
let b:l2u_tab_set = 0
|
||||
endfunction
|
||||
|
||||
" Function which looks for viable LaTeX-to-Unicode supstitutions as you type
|
||||
function! LaTeXtoUnicode#AutoSub(...)
|
||||
let vc = a:0 == 0 ? v:char : a:1
|
||||
let col1 = col('.')
|
||||
let lnum = line('.')
|
||||
if col1 == 1
|
||||
if a:0 > 1
|
||||
call feedkeys(a:2, 'n')
|
||||
endif
|
||||
return ''
|
||||
endif
|
||||
let bs = (vc != "\n")
|
||||
let l = getline(lnum)[0 : col1-1-bs] . v:char
|
||||
let col0 = match(l, '\\\%([_^]\?[A-Za-z]\+\%' . col1 . 'c\%([^A-Za-z]\|$\)\|[_^]\%([0-9()=+-]\)\%' . col1 .'c\%(.\|$\)\)')
|
||||
if col0 == -1
|
||||
if a:0 > 1
|
||||
call feedkeys(a:2, 'n')
|
||||
endif
|
||||
return ''
|
||||
endif
|
||||
let base = l[col0 : -1-bs]
|
||||
let unicode = get(g:l2u_symbols_dict, base, '')
|
||||
if empty(unicode)
|
||||
if a:0 > 1
|
||||
call feedkeys(a:2, 'n')
|
||||
endif
|
||||
return ''
|
||||
endif
|
||||
call feedkeys("\<C-G>u", 'n')
|
||||
call feedkeys(repeat("\b", len(base) + bs) . unicode . vc . s:l2u_esc_sequence, 'nt')
|
||||
call feedkeys("\<C-G>u", 'n')
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" Setup the auto as-you-type LaTeX-to-Unicode substitution
|
||||
function! s:L2U_SetAutoSub(wait_insert_enter)
|
||||
if b:l2u_autosub_set
|
||||
return
|
||||
endif
|
||||
" g:did_insert_enter is set from an autocommand in ftdetect
|
||||
if a:wait_insert_enter && !get(g:, "did_insert_enter", 0)
|
||||
return
|
||||
endif
|
||||
if !get(g:, "latex_to_unicode_auto", 0) || !b:l2u_enabled
|
||||
return
|
||||
endif
|
||||
" Viable substitutions are searched at every character insertion via the
|
||||
" autocmd InsertCharPre. The <Enter> key does not seem to be catched in
|
||||
" this way though, so we use a mapping for that case.
|
||||
imap <buffer> <CR> <Plug>L2UAutoSub
|
||||
inoremap <buffer><expr> <Plug>L2UAutoSub LaTeXtoUnicode#AutoSub("\n", "\<CR>")
|
||||
|
||||
augroup L2UAutoSub
|
||||
autocmd! * <buffer>
|
||||
autocmd InsertCharPre <buffer> call LaTeXtoUnicode#AutoSub()
|
||||
augroup END
|
||||
|
||||
let b:l2u_autosub_set = 1
|
||||
endfunction
|
||||
|
||||
" Revert the auto LaTeX-to-Unicode settings
|
||||
function! s:L2U_UnsetAutoSub()
|
||||
if !b:l2u_autosub_set
|
||||
return
|
||||
endif
|
||||
|
||||
iunmap <buffer> <CR>
|
||||
iunmap <buffer> <Plug>L2UAutoSub
|
||||
augroup L2UAutoSub
|
||||
autocmd! * <buffer>
|
||||
augroup END
|
||||
let b:l2u_autosub_set = 0
|
||||
endfunction
|
||||
|
||||
" Initialization. Can be used to re-init when global settings have changed.
|
||||
function! LaTeXtoUnicode#Init(...)
|
||||
let wait_insert_enter = a:0 > 0 ? a:1 : 1
|
||||
|
||||
if !wait_insert_enter
|
||||
augroup L2UInit
|
||||
autocmd!
|
||||
augroup END
|
||||
endif
|
||||
|
||||
call s:L2U_UnsetTab()
|
||||
call s:L2U_UnsetAutoSub()
|
||||
|
||||
call s:L2U_SetTab(wait_insert_enter)
|
||||
call s:L2U_SetAutoSub(wait_insert_enter)
|
||||
endfunction
|
||||
|
||||
function! LaTeXtoUnicode#Toggle()
|
||||
call s:L2U_Setup()
|
||||
if b:l2u_enabled
|
||||
call LaTeXtoUnicode#Disable()
|
||||
echo "LaTeX-to-Unicode disabled"
|
||||
else
|
||||
call LaTeXtoUnicode#Enable()
|
||||
echo "LaTeX-to-Unicode enabled"
|
||||
endif
|
||||
return
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -310,7 +310,7 @@ function! crystal_lang#format(option_str) abort
|
||||
|
||||
try
|
||||
call setreg('g', formatted, 'v')
|
||||
silent normal! ggvG$"gp
|
||||
silent normal! gg0vG$"gp
|
||||
finally
|
||||
call setreg('g', save_g_reg, save_g_regtype)
|
||||
let &l:selection = sel_save
|
||||
|
||||
@@ -24,9 +24,11 @@ function! dart#fmt(q_args) abort
|
||||
let joined_lines = system(printf('dartfmt %s', a:q_args), buffer_content)
|
||||
if 0 == v:shell_error
|
||||
let win_view = winsaveview()
|
||||
silent % delete _
|
||||
silent put=joined_lines
|
||||
silent 1 delete _
|
||||
let lines = split(joined_lines, "\n")
|
||||
silent keepjumps call setline(1, lines)
|
||||
if line('$') > len(lines)
|
||||
silent keepjumps execute string(len(lines)+1).',$ delete'
|
||||
endif
|
||||
call winrestview(win_view)
|
||||
else
|
||||
let errors = split(joined_lines, "\n")[2:]
|
||||
@@ -68,5 +70,95 @@ function! dart#tojs(q_args) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Finds the path to `uri`.
|
||||
"
|
||||
" If the file is a package: uri, looks for a .packages file to resolve the path.
|
||||
" If the path cannot be resolved, or is not a package: uri, returns the
|
||||
" original.
|
||||
function! dart#resolveUri(uri) abort
|
||||
if a:uri !~ 'package:'
|
||||
return a:uri
|
||||
endif
|
||||
let package_name = substitute(a:uri, 'package:\(\w\+\)\/.*', '\1', '')
|
||||
let [found, package_map] = s:PackageMap()
|
||||
if !found
|
||||
call s:error('cannot find .packages file')
|
||||
return a:uri
|
||||
endif
|
||||
if !has_key(package_map, package_name)
|
||||
call s:error('no package mapping for '.package_name)
|
||||
return a:uri
|
||||
endif
|
||||
let package_lib = package_map[package_name]
|
||||
return substitute(a:uri,
|
||||
\ 'package:'.package_name,
|
||||
\ escape(package_map[package_name], '\'),
|
||||
\ '')
|
||||
endfunction
|
||||
|
||||
" A map from package name to lib directory parse from a '.packages' file.
|
||||
"
|
||||
" Returns [found, package_map]
|
||||
function! s:PackageMap() abort
|
||||
let [found, dot_packages] = s:DotPackagesFile()
|
||||
if !found
|
||||
return [v:false, {}]
|
||||
endif
|
||||
let dot_packages_dir = fnamemodify(dot_packages, ':p:h')
|
||||
let lines = readfile(dot_packages)
|
||||
let map = {}
|
||||
for line in lines
|
||||
if line =~ '\s*#'
|
||||
continue
|
||||
endif
|
||||
let package = substitute(line, ':.*$', '', '')
|
||||
let lib_dir = substitute(line, '^[^:]*:', '', '')
|
||||
if lib_dir =~ 'file:/'
|
||||
let lib_dir = substitute(lib_dir, 'file://', '', '')
|
||||
if lib_dir =~ '/[A-Z]:/'
|
||||
let lib_dir = lib_dir[1:]
|
||||
endif
|
||||
else
|
||||
let lib_dir = resolve(dot_packages_dir.'/'.lib_dir)
|
||||
endif
|
||||
if lib_dir =~ '/$'
|
||||
let lib_dir = lib_dir[:len(lib_dir) - 2]
|
||||
endif
|
||||
let map[package] = lib_dir
|
||||
endfor
|
||||
return [v:true, map]
|
||||
endfunction
|
||||
|
||||
" Finds a file name '.packages' in the cwd, or in any directory above the open
|
||||
" file.
|
||||
"
|
||||
" Returns [found, file].
|
||||
function! s:DotPackagesFile() abort
|
||||
if filereadable('.packages')
|
||||
return [v:true, '.packages']
|
||||
endif
|
||||
let dir_path = expand('%:p:h')
|
||||
while v:true
|
||||
let file_path = dir_path.'/.packages'
|
||||
if filereadable(file_path)
|
||||
return [v:true, file_path]
|
||||
endif
|
||||
let parent = fnamemodify(dir_path, ':h')
|
||||
if dir_path == parent
|
||||
break
|
||||
endif
|
||||
let dir_path = parent
|
||||
endwhile
|
||||
return [v:false, '']
|
||||
endfunction
|
||||
|
||||
" Prevent writes to files in the pub cache.
|
||||
function! dart#setModifiable() abort
|
||||
let full_path = expand('%:p')
|
||||
if full_path =~# '.pub-cache' ||
|
||||
\ full_path =~# 'Pub\Cache'
|
||||
setlocal nomodifiable
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,219 +1,453 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
let s:NO_COLON_BEFORE = ':\@<!'
|
||||
let s:NO_COLON_AFTER = ':\@!'
|
||||
let s:ENDING_SYMBOLS = '\]\|}\|)'
|
||||
let s:ARROW = '->'
|
||||
let s:END_WITH_ARROW = s:ARROW.'$'
|
||||
let s:SKIP_SYNTAX = '\%(Comment\|String\)$'
|
||||
let s:BLOCK_SKIP = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:SKIP_SYNTAX."'"
|
||||
let s:DEF = '^\s*def'
|
||||
let s:FN = '\<fn\>'
|
||||
let s:MULTILINE_FN = s:FN.'\%(.*end\)\@!'
|
||||
let s:BLOCK_START = '\%(\<do\>\|'.s:FN.'\)\>'
|
||||
let s:MULTILINE_BLOCK = '\%(\<do\>'.s:NO_COLON_AFTER.'\|'.s:MULTILINE_FN.'\)'
|
||||
let s:BLOCK_MIDDLE = '\<\%(else\|match\|elsif\|catch\|after\|rescue\)\>'
|
||||
let s:BLOCK_END = 'end'
|
||||
let s:STARTS_WITH_PIPELINE = '^\s*|>.*$'
|
||||
let s:QUERY_FROM = '^\s*\<from\>.*\<in\>.*,'
|
||||
let s:ENDING_WITH_ASSIGNMENT = '=\s*$'
|
||||
let s:INDENT_KEYWORDS = s:NO_COLON_BEFORE.'\%('.s:MULTILINE_BLOCK.'\|'.s:BLOCK_MIDDLE.'\)'
|
||||
let s:DEINDENT_KEYWORDS = '^\s*\<\%('.s:BLOCK_END.'\|'.s:BLOCK_MIDDLE.'\)\>'
|
||||
let s:PAIR_START = '\<\%('.s:NO_COLON_BEFORE.s:BLOCK_START.'\)\>'.s:NO_COLON_AFTER
|
||||
let s:PAIR_MIDDLE = '^\s*\%('.s:BLOCK_MIDDLE.'\)\>'.s:NO_COLON_AFTER.'\zs'
|
||||
let s:PAIR_END = '\<\%('.s:NO_COLON_BEFORE.s:BLOCK_END.'\)\>\zs'
|
||||
let s:LINE_COMMENT = '^\s*#'
|
||||
let s:MATCH_OPERATOR = '[^!><=]=[^~=>]'
|
||||
if !exists("g:elixir_indent_max_lookbehind")
|
||||
let g:elixir_indent_max_lookbehind = 30
|
||||
endif
|
||||
|
||||
function! s:pending_parenthesis(line)
|
||||
if a:line.last_non_blank.text !~ s:ARROW
|
||||
return elixir#util#count_indentable_symbol_diff(a:line.last_non_blank, '(', '\%(end\s*\)\@<!)')
|
||||
end
|
||||
" Return the effective value of 'shiftwidth'
|
||||
function! s:sw()
|
||||
return &shiftwidth == 0 ? &tabstop : &shiftwidth
|
||||
endfunction
|
||||
|
||||
function! s:pending_square_brackets(line)
|
||||
if a:line.last_non_blank.text !~ s:ARROW
|
||||
return elixir#util#count_indentable_symbol_diff(a:line.last_non_blank, '[', ']')
|
||||
end
|
||||
function! elixir#indent#indent(lnum)
|
||||
let lnum = a:lnum
|
||||
let text = getline(lnum)
|
||||
let prev_nb_lnum = prevnonblank(lnum-1)
|
||||
let prev_nb_text = getline(prev_nb_lnum)
|
||||
|
||||
call s:debug("==> Indenting line " . lnum)
|
||||
call s:debug("text = '" . text . "'")
|
||||
|
||||
let handlers = [
|
||||
\'top_of_file',
|
||||
\'starts_with_end',
|
||||
\'starts_with_mid_or_end_block_keyword',
|
||||
\'following_trailing_do',
|
||||
\'following_trailing_binary_operator',
|
||||
\'starts_with_pipe',
|
||||
\'starts_with_close_bracket',
|
||||
\'starts_with_binary_operator',
|
||||
\'inside_nested_construct',
|
||||
\'starts_with_comment',
|
||||
\'inside_generic_block',
|
||||
\'follow_prev_nb'
|
||||
\]
|
||||
for handler in handlers
|
||||
call s:debug('testing handler elixir#indent#handle_'.handler)
|
||||
let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if indent != -1
|
||||
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent)
|
||||
return indent
|
||||
endif
|
||||
endfor
|
||||
|
||||
call s:debug("defaulting")
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:pending_brackets(line)
|
||||
if a:line.last_non_blank.text !~ s:ARROW
|
||||
return elixir#util#count_indentable_symbol_diff(a:line.last_non_blank, '{', '}')
|
||||
end
|
||||
function! s:debug(str)
|
||||
if exists("g:elixir_indent_debug") && g:elixir_indent_debug
|
||||
echom a:str
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#deindent_case_arrow(ind, line)
|
||||
if get(b:old_ind, 'arrow', 0) > 0
|
||||
\ && (a:line.current.text =~ s:ARROW
|
||||
\ || a:line.current.text =~ s:BLOCK_END)
|
||||
let ind = b:old_ind.arrow
|
||||
let b:old_ind.arrow = 0
|
||||
return ind
|
||||
" Returns 0 or 1 based on whether or not the text starts with the given
|
||||
" expression and is not a string or comment
|
||||
function! s:starts_with(text, expr, lnum)
|
||||
let pos = match(a:text, '^\s*'.a:expr)
|
||||
if pos == -1
|
||||
return 0
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#deindent_ending_symbols(ind, line)
|
||||
if a:line.current.text =~ '^\s*\('.s:ENDING_SYMBOLS.'\)'
|
||||
return a:ind - &sw
|
||||
" NOTE: @jbodah 2017-02-24: pos is the index of the match which is
|
||||
" zero-indexed. Add one to make it the column number
|
||||
if s:is_string_or_comment(a:lnum, pos + 1)
|
||||
return 0
|
||||
else
|
||||
return a:ind
|
||||
return 1
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#deindent_keywords(ind, line)
|
||||
if a:line.current.text =~ s:DEINDENT_KEYWORDS
|
||||
let bslnum = searchpair(
|
||||
\ s:PAIR_START,
|
||||
\ s:PAIR_MIDDLE,
|
||||
\ s:PAIR_END,
|
||||
\ 'nbW',
|
||||
\ s:BLOCK_SKIP
|
||||
\ )
|
||||
|
||||
return indent(bslnum)
|
||||
" Returns 0 or 1 based on whether or not the text ends with the given
|
||||
" expression and is not a string or comment
|
||||
function! s:ends_with(text, expr, lnum)
|
||||
let pos = match(a:text, a:expr.'\s*$')
|
||||
if pos == -1
|
||||
return 0
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#deindent_opened_symbols(ind, line)
|
||||
let s:opened_symbol =
|
||||
\ s:pending_parenthesis(a:line)
|
||||
\ + s:pending_square_brackets(a:line)
|
||||
\ + s:pending_brackets(a:line)
|
||||
|
||||
if s:opened_symbol < 0
|
||||
let ind = get(b:old_ind, 'symbol', a:ind + (s:opened_symbol * &sw))
|
||||
let ind = float2nr(ceil(floor(ind)/&sw)*&sw)
|
||||
return ind <= 0 ? 0 : ind
|
||||
if s:is_string_or_comment(a:lnum, pos)
|
||||
return 0
|
||||
else
|
||||
return a:ind
|
||||
return 1
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_after_pipeline(ind, line)
|
||||
if exists("b:old_ind.pipeline")
|
||||
\ && elixir#util#is_blank(a:line.last.text)
|
||||
\ && a:line.current.text !~ s:STARTS_WITH_PIPELINE
|
||||
" Reset indentation in pipelines if there is a blank line between
|
||||
" pipes
|
||||
let ind = b:old_ind.pipeline
|
||||
unlet b:old_ind.pipeline
|
||||
return ind
|
||||
elseif a:line.last_non_blank.text =~ s:STARTS_WITH_PIPELINE
|
||||
if empty(substitute(a:line.current.text, ' ', '', 'g'))
|
||||
\ || a:line.current.text =~ s:STARTS_WITH_PIPELINE
|
||||
return indent(a:line.last_non_blank.num)
|
||||
elseif a:line.last_non_blank.text !~ s:INDENT_KEYWORDS
|
||||
let ind = b:old_ind.pipeline
|
||||
unlet b:old_ind.pipeline
|
||||
return ind
|
||||
end
|
||||
end
|
||||
|
||||
return a:ind
|
||||
" Returns 0 or 1 based on whether or not the given line number and column
|
||||
" number pair is a string or comment
|
||||
function! s:is_string_or_comment(line, col)
|
||||
return synIDattr(synID(a:line, a:col, 1), "name") =~ '\%(String\|Comment\)'
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_assignment(ind, line)
|
||||
if a:line.last_non_blank.text =~ s:ENDING_WITH_ASSIGNMENT
|
||||
let b:old_ind.pipeline = indent(a:line.last_non_blank.num) " FIXME: side effect
|
||||
return a:ind + &sw
|
||||
" Skip expression for searchpair. Returns 0 or 1 based on whether the value
|
||||
" under the cursor is a string or comment
|
||||
function! elixir#indent#searchpair_back_skip()
|
||||
" NOTE: @jbodah 2017-02-27: for some reason this function gets called with
|
||||
" and index that doesn't exist in the line sometimes. Detect and account for
|
||||
" that situation
|
||||
let curr_col = col('.')
|
||||
if getline('.')[curr_col-1] == ''
|
||||
let curr_col = curr_col-1
|
||||
endif
|
||||
return s:is_string_or_comment(line('.'), curr_col)
|
||||
endfunction
|
||||
|
||||
" DRY up regex for keywords that 1) makes sure we only look at complete words
|
||||
" and 2) ignores atoms
|
||||
function! s:keyword(expr)
|
||||
return ':\@<!\<\C\%('.a:expr.'\)\>:\@!'
|
||||
endfunction
|
||||
|
||||
" Start at the end of text and search backwards looking for a match. Also peek
|
||||
" ahead if we get a match to make sure we get a complete match. This means
|
||||
" that the result should be the position of the start of the right-most match
|
||||
function! s:find_last_pos(lnum, text, match)
|
||||
let last = len(a:text) - 1
|
||||
let c = last
|
||||
|
||||
while c >= 0
|
||||
let substr = strpart(a:text, c, last)
|
||||
let peek = strpart(a:text, c - 1, last)
|
||||
let ss_match = match(substr, a:match)
|
||||
if ss_match != -1
|
||||
let peek_match = match(peek, a:match)
|
||||
if peek_match == ss_match + 1
|
||||
let syng = synIDattr(synID(a:lnum, c + ss_match, 1), 'name')
|
||||
if syng !~ '\%(String\|Comment\)'
|
||||
return c + ss_match
|
||||
end
|
||||
end
|
||||
end
|
||||
let c -= 1
|
||||
endwhile
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_top_of_file(_lnum, _text, prev_nb_lnum, _prev_nb_text)
|
||||
if a:prev_nb_lnum == 0
|
||||
return 0
|
||||
else
|
||||
return a:ind
|
||||
return -1
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_brackets(ind, line)
|
||||
if s:pending_brackets(a:line) > 0
|
||||
return a:ind + &sw
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
function! elixir#indent#handle_follow_prev_nb(_lnum, _text, prev_nb_lnum, prev_nb_text)
|
||||
return s:get_base_indent(a:prev_nb_lnum, a:prev_nb_text)
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_case_arrow(ind, line)
|
||||
if a:line.last_non_blank.text =~ s:END_WITH_ARROW && a:line.last_non_blank.text !~ '\<fn\>'
|
||||
let b:old_ind.arrow = a:ind
|
||||
return a:ind + &sw
|
||||
" Given the line at `lnum`, returns the indent of the line that acts as the 'base indent'
|
||||
" for this line. In particular it traverses backwards up things like pipelines
|
||||
" to find the beginning of the expression
|
||||
function! s:get_base_indent(lnum, text)
|
||||
let prev_nb_lnum = prevnonblank(a:lnum - 1)
|
||||
let prev_nb_text = getline(prev_nb_lnum)
|
||||
|
||||
let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
|
||||
let data_structure_close = '\%(\]\|}\|)\)'
|
||||
let pipe = '|>'
|
||||
|
||||
if s:starts_with(a:text, binary_operator, a:lnum)
|
||||
return s:get_base_indent(prev_nb_lnum, prev_nb_text)
|
||||
elseif s:starts_with(a:text, pipe, a:lnum)
|
||||
return s:get_base_indent(prev_nb_lnum, prev_nb_text)
|
||||
elseif s:ends_with(prev_nb_text, binary_operator, prev_nb_lnum)
|
||||
return s:get_base_indent(prev_nb_lnum, prev_nb_text)
|
||||
elseif s:ends_with(a:text, data_structure_close, a:lnum)
|
||||
let data_structure_open = '\%(\[\|{\|(\)'
|
||||
let close_match_idx = match(a:text, data_structure_close . '\s*$')
|
||||
let _move = cursor(a:lnum, close_match_idx + 1)
|
||||
let [open_match_lnum, open_match_col] = searchpairpos(data_structure_open, '', data_structure_close, 'bnW')
|
||||
let open_match_text = getline(open_match_lnum)
|
||||
return s:get_base_indent(open_match_lnum, open_match_text)
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
return indent(a:lnum)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_ending_symbols(ind, line)
|
||||
if a:line.last_non_blank.text =~ '^\s*\('.s:ENDING_SYMBOLS.'\)\s*$'
|
||||
return a:ind + &sw
|
||||
" TODO: @jbodah 2017-03-31: remove
|
||||
function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if s:ends_with(a:prev_nb_text, s:keyword('do'), a:prev_nb_lnum)
|
||||
if s:starts_with(a:text, s:keyword('end'), a:lnum)
|
||||
return indent(a:prev_nb_lnum)
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_keywords(ind, line)
|
||||
if a:line.last_non_blank.text =~ s:INDENT_KEYWORDS && a:line.last_non_blank.text !~ s:LINE_COMMENT
|
||||
return a:ind + &sw
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_parenthesis(ind, line)
|
||||
if s:pending_parenthesis(a:line) > 0
|
||||
\ && a:line.last_non_blank.text !~ s:DEF
|
||||
\ && a:line.last_non_blank.text !~ s:END_WITH_ARROW
|
||||
let b:old_ind.symbol = a:ind
|
||||
return matchend(a:line.last_non_blank.text, '(')
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_pipeline_assignment(ind, line)
|
||||
if a:line.current.text =~ s:STARTS_WITH_PIPELINE
|
||||
\ && a:line.last_non_blank.text =~ s:MATCH_OPERATOR
|
||||
let b:old_ind.pipeline = indent(a:line.last_non_blank.num)
|
||||
" if line starts with pipeline
|
||||
" and last_non_blank line is an attribution
|
||||
" indents pipeline in same level as attribution
|
||||
let assign_pos = match(a:line.last_non_blank.text, '=\s*\zs[^ ]')
|
||||
return (elixir#util#is_indentable_at(a:line.last_non_blank.num, assign_pos) ? assign_pos : a:ind)
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_pipeline_continuation(ind, line)
|
||||
if a:line.last_non_blank.text =~ s:STARTS_WITH_PIPELINE
|
||||
\ && a:line.current.text =~ s:STARTS_WITH_PIPELINE
|
||||
return indent(a:line.last_non_blank.num)
|
||||
else
|
||||
return a:ind
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_square_brackets(ind, line)
|
||||
if s:pending_square_brackets(a:line) > 0
|
||||
if a:line.last_non_blank.text =~ '[\s*$'
|
||||
return a:ind + &sw
|
||||
else
|
||||
" if start symbol is followed by a character, indent based on the
|
||||
" whitespace after the symbol, otherwise use the default shiftwidth
|
||||
" Avoid negative indentation index
|
||||
return matchend(a:line.last_non_blank.text, '[\s*')
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
end
|
||||
else
|
||||
return a:ind
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
|
||||
|
||||
if s:ends_with(a:prev_nb_text, binary_operator, a:prev_nb_lnum)
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_following_prev_end(_lnum, _text, prev_nb_lnum, prev_nb_text)
|
||||
if s:ends_with(a:prev_nb_text, s:keyword('end'), a:prev_nb_lnum)
|
||||
return indent(a:prev_nb_lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if s:starts_with(a:text, '|>', a:lnum)
|
||||
let match_operator = '\%(!\|=\|<\|>\)\@<!=\%(=\|>\|\~\)\@!'
|
||||
let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator)
|
||||
if pos == -1
|
||||
return indent(a:prev_nb_lnum)
|
||||
else
|
||||
let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S')
|
||||
if next_word_pos == -1
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
else
|
||||
return pos + 1 + next_word_pos
|
||||
end
|
||||
end
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_comment(_lnum, text, prev_nb_lnum, _prev_nb_text)
|
||||
if match(a:text, '^\s*#') != -1
|
||||
return indent(a:prev_nb_lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_end(lnum, text, _prev_nb_lnum, _prev_nb_text)
|
||||
if s:starts_with(a:text, s:keyword('end'), a:lnum)
|
||||
let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end').'\zs', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()")
|
||||
return indent(pair_lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_mid_or_end_block_keyword(lnum, text, _prev_nb_lnum, _prev_nb_text)
|
||||
if s:starts_with(a:text, s:keyword('catch\|rescue\|after\|else'), a:lnum)
|
||||
let pair_lnum = searchpair(s:keyword('with\|receive\|try\|if\|fn'), s:keyword('catch\|rescue\|after\|else').'\zs', s:keyword('end'), 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()")
|
||||
return indent(pair_lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_close_bracket(lnum, text, _prev_nb_lnum, _prev_nb_text)
|
||||
if s:starts_with(a:text, '\%(\]\|}\|)\)', a:lnum)
|
||||
let pair_lnum = searchpair('\%(\[\|{\|(\)', '', '\%(\]\|}\|)\)', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()")
|
||||
return indent(pair_lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_starts_with_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
|
||||
|
||||
if s:starts_with(a:text, binary_operator, a:lnum)
|
||||
let match_operator = '\%(!\|=\|<\|>\)\@<!=\%(=\|>\|\~\)\@!'
|
||||
let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator)
|
||||
if pos == -1
|
||||
return indent(a:prev_nb_lnum)
|
||||
else
|
||||
let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S')
|
||||
if next_word_pos == -1
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
else
|
||||
return pos + 1 + next_word_pos
|
||||
end
|
||||
end
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" To handle nested structures properly we need to find the innermost
|
||||
" nested structure. For example, we might be in a function in a map in a
|
||||
" function, etc... so we need to first figure out what the innermost structure
|
||||
" is then forward execution to the proper handler
|
||||
function! elixir#indent#handle_inside_nested_construct(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
let start_pattern = '\C\%(\<with\>\|\<if\>\|\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<fn\>\|{\|\[\|(\)'
|
||||
let end_pattern = '\C\%(\<end\>\|\]\|}\|)\)'
|
||||
let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()", max([0, a:lnum - g:elixir_indent_max_lookbehind]))
|
||||
let pair_lnum = pair_info[0]
|
||||
let pair_col = pair_info[1]
|
||||
if pair_lnum != 0 || pair_col != 0
|
||||
let pair_text = getline(pair_lnum)
|
||||
let pair_char = pair_text[pair_col - 1]
|
||||
if pair_char == 'f'
|
||||
call s:debug("testing s:do_handle_inside_fn")
|
||||
return s:do_handle_inside_fn(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
elseif pair_char == '['
|
||||
call s:debug("testing s:do_handle_inside_square_brace")
|
||||
return s:do_handle_inside_square_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
elseif pair_char == '{'
|
||||
call s:debug("testing s:do_handle_inside_curly_brace")
|
||||
return s:do_handle_inside_curly_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
elseif pair_char == '('
|
||||
call s:debug("testing s:do_handle_inside_parens")
|
||||
return s:do_handle_inside_parens(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
elseif pair_char == 'w'
|
||||
call s:debug("testing s:do_handle_inside_with")
|
||||
return s:do_handle_inside_with(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
else
|
||||
call s:debug("testing s:do_handle_inside_keyword_block")
|
||||
return s:do_handle_inside_keyword_block(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
end
|
||||
else
|
||||
return -1
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#indent_ecto_queries(ind, line)
|
||||
if a:line.last_non_blank.text =~ s:QUERY_FROM
|
||||
return a:ind + &sw
|
||||
function! s:do_handle_inside_with(pair_lnum, pair_col, lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if a:pair_lnum == a:lnum
|
||||
" This is the `with` line or an inline `with`/`do`
|
||||
call s:debug("current line is `with`")
|
||||
return -1
|
||||
else
|
||||
return a:ind
|
||||
" Determine if in with/do, do/else|end, or else/end
|
||||
let start_pattern = '\C\%(\<with\>\|\<else\>\|\<do\>\)'
|
||||
let end_pattern = '\C\%(\<end\>\)'
|
||||
let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()")
|
||||
let pair_lnum = pair_info[0]
|
||||
let pair_col = pair_info[1]
|
||||
|
||||
let pair_text = getline(pair_lnum)
|
||||
let pair_char = pair_text[pair_col - 1]
|
||||
|
||||
if s:starts_with(a:text, '\Cdo:', a:lnum)
|
||||
call s:debug("current line is do:")
|
||||
return pair_col - 1 + s:sw()
|
||||
elseif s:starts_with(a:text, '\Celse:', a:lnum)
|
||||
call s:debug("current line is else:")
|
||||
return pair_col - 1
|
||||
elseif s:starts_with(a:text, '\C\(\<do\>\|\<else\>\)', a:lnum)
|
||||
call s:debug("current line is do/else")
|
||||
return pair_col - 1
|
||||
elseif s:starts_with(pair_text, '\C\(do\|else\):', pair_lnum)
|
||||
call s:debug("inside do:/else:")
|
||||
return pair_col - 1 + s:sw()
|
||||
elseif pair_char == 'w'
|
||||
call s:debug("inside with/do")
|
||||
return pair_col + 4
|
||||
elseif pair_char == 'd'
|
||||
call s:debug("inside do/else|end")
|
||||
return pair_col - 1 + s:sw()
|
||||
else
|
||||
call s:debug("inside else/end")
|
||||
return s:do_handle_inside_pattern_match_block(pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
end
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! s:do_handle_inside_keyword_block(pair_lnum, _pair_col, _lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
let keyword_pattern = '\C\%(\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<after\>\|\<catch\>\|\<rescue\>\|\<else\>\)'
|
||||
if a:pair_lnum
|
||||
" last line is a "receive" or something
|
||||
if s:starts_with(a:prev_nb_text, keyword_pattern, a:prev_nb_lnum)
|
||||
call s:debug("prev nb line is keyword")
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
else
|
||||
return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
end
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Implements indent for pattern-matching blocks (e.g. case, fn, with/else)
|
||||
function! s:do_handle_inside_pattern_match_block(block_start_lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if a:text =~ '->'
|
||||
call s:debug("current line contains ->")
|
||||
return indent(a:block_start_lnum) + s:sw()
|
||||
elseif a:prev_nb_text =~ '->'
|
||||
call s:debug("prev nb line contains ->")
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
else
|
||||
return indent(a:prev_nb_lnum)
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! s:do_handle_inside_fn(pair_lnum, _pair_col, lnum, text, prev_nb_lnum, prev_nb_text)
|
||||
if a:pair_lnum && a:pair_lnum != a:lnum
|
||||
return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:do_handle_inside_square_brace(pair_lnum, pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text)
|
||||
" If in list...
|
||||
if a:pair_lnum != 0 || a:pair_col != 0
|
||||
let pair_text = getline(a:pair_lnum)
|
||||
let substr = strpart(pair_text, a:pair_col, len(pair_text)-1)
|
||||
let indent_pos = match(substr, '\S')
|
||||
if indent_pos != -1
|
||||
return indent_pos + a:pair_col
|
||||
else
|
||||
return indent(a:pair_lnum) + s:sw()
|
||||
endif
|
||||
else
|
||||
return -1
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! s:do_handle_inside_curly_brace(pair_lnum, _pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text)
|
||||
return indent(a:pair_lnum) + s:sw()
|
||||
endfunction
|
||||
|
||||
function! s:do_handle_inside_parens(pair_lnum, pair_col, _lnum, _text, prev_nb_lnum, prev_nb_text)
|
||||
if a:pair_lnum
|
||||
if s:ends_with(a:prev_nb_text, '(', a:prev_nb_lnum)
|
||||
return indent(a:prev_nb_lnum) + s:sw()
|
||||
elseif a:pair_lnum == a:prev_nb_lnum
|
||||
" Align indent (e.g. "def add(a,")
|
||||
let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, '[^(]\+,')
|
||||
if pos == -1
|
||||
return 0
|
||||
else
|
||||
return pos
|
||||
end
|
||||
else
|
||||
return indent(a:prev_nb_lnum)
|
||||
end
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! elixir#indent#handle_inside_generic_block(lnum, _text, prev_nb_lnum, prev_nb_text)
|
||||
let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end'), 'bW', "line('.') == ".a:lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:lnum - g:elixir_indent_max_lookbehind]))
|
||||
if pair_lnum
|
||||
" TODO: @jbodah 2017-03-29: this should probably be the case in *all*
|
||||
" blocks
|
||||
if s:ends_with(a:prev_nb_text, ',', a:prev_nb_lnum)
|
||||
return indent(pair_lnum) + 2 * s:sw()
|
||||
else
|
||||
return indent(pair_lnum) + s:sw()
|
||||
endif
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,52 +1,28 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
let s:SKIP_SYNTAX = '\%(Comment\|String\)$'
|
||||
function! elixir#util#get_filename(word) abort
|
||||
let word = a:word
|
||||
|
||||
function! elixir#util#is_indentable_at(line, col)
|
||||
if a:col == -1 " skip synID lookup for not found match
|
||||
return 1
|
||||
end
|
||||
" TODO: Remove these 2 lines
|
||||
" I don't know why, but for the test on spec/indent/lists_spec.rb:24.
|
||||
" Vim is making some mess on parsing the syntax of 'end', it is being
|
||||
" recognized as 'elixirString' when should be recognized as 'elixirBlock'.
|
||||
call synID(a:line, a:col, 1)
|
||||
" This forces vim to sync the syntax. Using fromstart is very slow on files
|
||||
" over 1k lines
|
||||
syntax sync minlines=20 maxlines=150
|
||||
" get first thing that starts uppercase, until the first space or end of line
|
||||
let word = substitute(word,'^\s*\(\u[^ ]\+\).*$','\1','g')
|
||||
|
||||
return synIDattr(synID(a:line, a:col, 1), "name")
|
||||
\ !~ s:SKIP_SYNTAX
|
||||
endfunction
|
||||
" remove any trailing characters that don't look like a nested module
|
||||
let word = substitute(word,'\.\U.*$','','g')
|
||||
|
||||
function! elixir#util#count_indentable_symbol_diff(line, open, close)
|
||||
return
|
||||
\ s:match_count(a:line, a:open)
|
||||
\ - s:match_count(a:line, a:close)
|
||||
endfunction
|
||||
" replace module dots with slash
|
||||
let word = substitute(word,'\.','/','g')
|
||||
|
||||
function! s:match_count(line, pattern)
|
||||
let size = strlen(a:line.text)
|
||||
let index = 0
|
||||
let counter = 0
|
||||
" remove any special chars
|
||||
let word = substitute(word,'[^A-z0-9-_/]','','g')
|
||||
|
||||
while index < size
|
||||
let index = match(a:line.text, a:pattern, index)
|
||||
if index >= 0
|
||||
let index += 1
|
||||
if elixir#util#is_indentable_at(a:line.num, index)
|
||||
let counter +=1
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
endwhile
|
||||
" 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 counter
|
||||
endfunction
|
||||
|
||||
function elixir#util#is_blank(string)
|
||||
return a:string =~ '^\s*$'
|
||||
return word
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
382
autoload/elm.vim
Normal file
382
autoload/elm.vim
Normal file
@@ -0,0 +1,382 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
let s:errors = []
|
||||
|
||||
function! s:elmOracle(...) abort
|
||||
let l:project = finddir('elm-stuff/..', '.;')
|
||||
if len(l:project) == 0
|
||||
echoerr '`elm-stuff` not found! run `elm-package install` for autocomplete.'
|
||||
return []
|
||||
endif
|
||||
|
||||
let l:filename = expand('%:p')
|
||||
|
||||
if a:0 == 0
|
||||
let l:oldiskeyword = &iskeyword
|
||||
" Some non obvious values used in 'iskeyword':
|
||||
" @ = all alpha
|
||||
" 48-57 = numbers 0 to 9
|
||||
" @-@ = character @
|
||||
" 124 = |
|
||||
setlocal iskeyword=@,48-57,@-@,_,-,~,!,#,$,%,&,*,+,=,<,>,/,?,.,\\,124,^
|
||||
let l:word = expand('<cword>')
|
||||
let &iskeyword = l:oldiskeyword
|
||||
else
|
||||
let l:word = a:1
|
||||
endif
|
||||
|
||||
let l:infos = elm#Oracle(l:filename, l:word)
|
||||
if v:shell_error != 0
|
||||
call elm#util#EchoError("elm-oracle failed:\n\n", l:infos)
|
||||
return []
|
||||
endif
|
||||
|
||||
let l:d = split(l:infos, '\n')
|
||||
if len(l:d) > 0
|
||||
return elm#util#DecodeJSON(l:d[0])
|
||||
endif
|
||||
|
||||
return []
|
||||
endf
|
||||
|
||||
" Vim command to format Elm files with elm-format
|
||||
function! elm#Format() abort
|
||||
" check for elm-format
|
||||
if elm#util#CheckBin('elm-format', 'https://github.com/avh4/elm-format') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
" save cursor position, folds and many other things
|
||||
let l:curw = {}
|
||||
try
|
||||
mkview!
|
||||
catch
|
||||
let l:curw = winsaveview()
|
||||
endtry
|
||||
|
||||
" save our undo file to be restored after we are done.
|
||||
let l:tmpundofile = tempname()
|
||||
exe 'wundo! ' . l:tmpundofile
|
||||
|
||||
" write current unsaved buffer to a temporary file
|
||||
let l:tmpname = tempname() . '.elm'
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
" call elm-format on the temporary file
|
||||
let l:out = system('elm-format ' . l:tmpname . ' --output ' . l:tmpname)
|
||||
|
||||
" if there is no error
|
||||
if v:shell_error == 0
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" replace current file with temp file, then reload buffer
|
||||
let l:old_fileformat = &fileformat
|
||||
call rename(l:tmpname, expand('%'))
|
||||
silent edit!
|
||||
let &fileformat = l:old_fileformat
|
||||
let &syntax = &syntax
|
||||
elseif g:elm_format_fail_silently == 0
|
||||
call elm#util#EchoLater('EchoError', 'elm-format:', l:out)
|
||||
endif
|
||||
|
||||
" save our undo history
|
||||
silent! exe 'rundo ' . l:tmpundofile
|
||||
call delete(l:tmpundofile)
|
||||
|
||||
" restore our cursor/windows positions, folds, etc..
|
||||
if empty(l:curw)
|
||||
silent! loadview
|
||||
else
|
||||
call winrestview(l:curw)
|
||||
endif
|
||||
endf
|
||||
|
||||
" Query elm-oracle and echo the type and docs for the word under the cursor.
|
||||
function! elm#ShowDocs() abort
|
||||
" check for the elm-oracle binary
|
||||
if elm#util#CheckBin('elm-oracle', 'https://github.com/elmcast/elm-oracle') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
let l:response = s:elmOracle()
|
||||
|
||||
if len(l:response) > 0
|
||||
let l:info = l:response[0]
|
||||
redraws! | echohl Identifier | echon l:info.fullName | echohl None | echon ' : ' | echohl Function | echon l:info.signature | echohl None | echon "\n\n" . l:info.comment
|
||||
else
|
||||
call elm#util#Echo('elm-oracle:', '...no match found')
|
||||
endif
|
||||
endf
|
||||
|
||||
" Query elm-oracle and open the docs for the word under the cursor.
|
||||
function! elm#BrowseDocs() abort
|
||||
" check for the elm-oracle binary
|
||||
if elm#util#CheckBin('elm-oracle', 'https://github.com/elmcast/elm-oracle') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
let l:response = s:elmOracle()
|
||||
|
||||
if len(l:response) > 0
|
||||
let l:info = l:response[0]
|
||||
call elm#util#OpenBrowser(l:info.href)
|
||||
else
|
||||
call elm#util#Echo('elm-oracle:', '...no match found')
|
||||
endif
|
||||
endf
|
||||
|
||||
|
||||
function! elm#Syntastic(input) abort
|
||||
let l:fixes = []
|
||||
|
||||
let l:bin = 'elm-make'
|
||||
let l:format = '--report=json'
|
||||
let l:input = shellescape(a:input)
|
||||
let l:output = '--output=' . shellescape(syntastic#util#DevNull())
|
||||
let l:command = l:bin . ' ' . l:format . ' ' . l:input . ' ' . l:output
|
||||
let l:reports = s:ExecuteInRoot(l:command)
|
||||
|
||||
for l:report in split(l:reports, '\n')
|
||||
if l:report[0] ==# '['
|
||||
for l:error in elm#util#DecodeJSON(l:report)
|
||||
if g:elm_syntastic_show_warnings == 0 && l:error.type ==? 'warning'
|
||||
else
|
||||
if a:input == l:error.file
|
||||
call add(s:errors, l:error)
|
||||
call add(l:fixes, {'filename': l:error.file,
|
||||
\'valid': 1,
|
||||
\'bufnr': bufnr('%'),
|
||||
\'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
||||
\'lnum': l:error.region.start.line,
|
||||
\'col': l:error.region.start.column,
|
||||
\'text': l:error.overview})
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:fixes
|
||||
endf
|
||||
|
||||
function! elm#Build(input, output, show_warnings) abort
|
||||
let s:errors = []
|
||||
let l:fixes = []
|
||||
let l:rawlines = []
|
||||
|
||||
let l:bin = 'elm-make'
|
||||
let l:format = '--report=json'
|
||||
let l:input = shellescape(a:input)
|
||||
let l:output = '--output=' . shellescape(a:output)
|
||||
let l:command = l:bin . ' ' . l:format . ' ' . l:input . ' ' . l:output
|
||||
let l:reports = s:ExecuteInRoot(l:command)
|
||||
|
||||
for l:report in split(l:reports, '\n')
|
||||
if l:report[0] ==# '['
|
||||
for l:error in elm#util#DecodeJSON(l:report)
|
||||
if a:show_warnings == 0 && l:error.type ==? 'warning'
|
||||
else
|
||||
call add(s:errors, l:error)
|
||||
call add(l:fixes, {'filename': l:error.file,
|
||||
\'valid': 1,
|
||||
\'type': (l:error.type ==? 'error') ? 'E' : 'W',
|
||||
\'lnum': l:error.region.start.line,
|
||||
\'col': l:error.region.start.column,
|
||||
\'text': l:error.overview})
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call add(l:rawlines, l:report)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let l:details = join(l:rawlines, "\n")
|
||||
let l:lines = split(l:details, "\n")
|
||||
if !empty(l:lines)
|
||||
let l:overview = l:lines[0]
|
||||
else
|
||||
let l:overview = ''
|
||||
endif
|
||||
|
||||
if l:details ==# '' || l:details =~? '^Successfully.*'
|
||||
else
|
||||
call add(s:errors, {'overview': l:details, 'details': l:details})
|
||||
call add(l:fixes, {'filename': expand('%', 1),
|
||||
\'valid': 1,
|
||||
\'type': 'E',
|
||||
\'lnum': 0,
|
||||
\'col': 0,
|
||||
\'text': l:overview})
|
||||
endif
|
||||
|
||||
return l:fixes
|
||||
endf
|
||||
|
||||
" Make the given file, or the current file if none is given.
|
||||
function! elm#Make(...) abort
|
||||
if elm#util#CheckBin('elm-make', 'http://elm-lang.org/install') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
call elm#util#Echo('elm-make:', 'building...')
|
||||
|
||||
let l:input = (a:0 == 0) ? expand('%:p') : a:1
|
||||
let l:fixes = elm#Build(l:input, g:elm_make_output_file, g:elm_make_show_warnings)
|
||||
|
||||
if len(l:fixes) > 0
|
||||
call elm#util#EchoWarning('', 'found ' . len(l:fixes) . ' errors')
|
||||
|
||||
call setqflist(l:fixes, 'r')
|
||||
cwindow
|
||||
|
||||
if get(g:, 'elm_jump_to_error', 1)
|
||||
ll 1
|
||||
endif
|
||||
else
|
||||
call elm#util#EchoSuccess('', 'Sucessfully compiled')
|
||||
|
||||
call setqflist([])
|
||||
cwindow
|
||||
endif
|
||||
endf
|
||||
|
||||
" Show the detail of the current error in the quickfix window.
|
||||
function! elm#ErrorDetail() abort
|
||||
if !empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") ==? "quickfix"'))
|
||||
exec ':copen'
|
||||
let l:linenr = line('.')
|
||||
exec ':wincmd p'
|
||||
if len(s:errors) > 0
|
||||
let l:detail = s:errors[l:linenr-1].details
|
||||
if l:detail ==# ''
|
||||
let l:detail = s:errors[l:linenr-1].overview
|
||||
endif
|
||||
echo l:detail
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
" Open the elm repl in a subprocess.
|
||||
function! elm#Repl() abort
|
||||
" check for the elm-repl binary
|
||||
if elm#util#CheckBin('elm-repl', 'http://elm-lang.org/install') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
term('elm-repl')
|
||||
else
|
||||
!elm-repl
|
||||
endif
|
||||
endf
|
||||
|
||||
function! elm#Oracle(filepath, word) abort
|
||||
let l:bin = 'elm-oracle'
|
||||
let l:filepath = shellescape(a:filepath)
|
||||
let l:word = shellescape(a:word)
|
||||
let l:command = l:bin . ' ' . l:filepath . ' ' . l:word
|
||||
return s:ExecuteInRoot(l:command)
|
||||
endfunction
|
||||
|
||||
let s:fullComplete = ''
|
||||
|
||||
" Complete the current token using elm-oracle
|
||||
function! elm#Complete(findstart, base) abort
|
||||
" a:base is unused, but the callback function for completion expects 2 arguments
|
||||
if a:findstart
|
||||
let l:line = getline('.')
|
||||
|
||||
let l:idx = col('.') - 1
|
||||
let l:start = 0
|
||||
while l:idx > 0 && l:line[l:idx - 1] =~# '[a-zA-Z0-9_\.]'
|
||||
if l:line[l:idx - 1] ==# '.' && l:start == 0
|
||||
let l:start = l:idx
|
||||
endif
|
||||
let l:idx -= 1
|
||||
endwhile
|
||||
|
||||
if l:start == 0
|
||||
let l:start = l:idx
|
||||
endif
|
||||
|
||||
let s:fullComplete = l:line[l:idx : col('.')-2]
|
||||
|
||||
return l:start
|
||||
else
|
||||
" check for the elm-oracle binary
|
||||
if elm#util#CheckBin('elm-oracle', 'https://github.com/elmcast/elm-oracle') ==# ''
|
||||
return []
|
||||
endif
|
||||
|
||||
let l:res = []
|
||||
let l:response = s:elmOracle(s:fullComplete)
|
||||
|
||||
let l:detailed = get(g:, 'elm_detailed_complete', 0)
|
||||
|
||||
for l:r in l:response
|
||||
let l:menu = ''
|
||||
if l:detailed
|
||||
let l:menu = ': ' . l:r.signature
|
||||
endif
|
||||
call add(l:res, {'word': l:r.name, 'menu': l:menu})
|
||||
endfor
|
||||
|
||||
return l:res
|
||||
endif
|
||||
endf
|
||||
|
||||
" If the current buffer contains a consoleRunner, run elm-test with it.
|
||||
" Otherwise run elm-test in the root of your project which deafults to
|
||||
" running 'elm-test tests/TestRunner'.
|
||||
function! elm#Test() abort
|
||||
if elm#util#CheckBin('elm-test', 'https://github.com/rtfeldman/node-elm-test') ==# ''
|
||||
return
|
||||
endif
|
||||
|
||||
if match(getline(1, '$'), 'consoleRunner') < 0
|
||||
let l:out = s:ExecuteInRoot('elm-test')
|
||||
call elm#util#EchoSuccess('elm-test', l:out)
|
||||
else
|
||||
let l:filepath = shellescape(expand('%:p'))
|
||||
let l:out = s:ExecuteInRoot('elm-test ' . l:filepath)
|
||||
call elm#util#EchoSuccess('elm-test', l:out)
|
||||
endif
|
||||
endf
|
||||
|
||||
" Returns the closest parent with an elm-package.json file.
|
||||
function! elm#FindRootDirectory() abort
|
||||
let l:elm_root = getbufvar('%', 'elmRoot')
|
||||
if empty(l:elm_root)
|
||||
let l:current_file = expand('%:p')
|
||||
let l:dir_current_file = fnameescape(fnamemodify(l:current_file, ':h'))
|
||||
let l:match = findfile('elm-package.json', l:dir_current_file . ';')
|
||||
if empty(l:match)
|
||||
let l:elm_root = ''
|
||||
else
|
||||
let l:elm_root = fnamemodify(l:match, ':p:h')
|
||||
endif
|
||||
|
||||
if !empty(l:elm_root)
|
||||
call setbufvar('%', 'elmRoot', l:elm_root)
|
||||
endif
|
||||
endif
|
||||
return l:elm_root
|
||||
endfunction
|
||||
|
||||
" Executes a command in the project directory.
|
||||
function! s:ExecuteInRoot(cmd) abort
|
||||
let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let l:current_dir = getcwd()
|
||||
let l:root_dir = elm#FindRootDirectory()
|
||||
|
||||
try
|
||||
execute l:cd . fnameescape(l:root_dir)
|
||||
let l:out = system(a:cmd)
|
||||
finally
|
||||
execute l:cd . fnameescape(l:current_dir)
|
||||
endtry
|
||||
|
||||
return l:out
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -1,12 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" System IO
|
||||
|
||||
" Craft a system command and run it, returning the output.
|
||||
function! elm#io#system(program, args)
|
||||
let cmd ="which " . a:program . " && " . a:program . " " . a:args
|
||||
return system(cmd)
|
||||
endfunction
|
||||
|
||||
|
||||
endif
|
||||
178
autoload/elm/util.vim
Normal file
178
autoload/elm/util.vim
Normal file
@@ -0,0 +1,178 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" IsWin returns 1 if current OS is Windows or 0 otherwise
|
||||
fun! elm#util#IsWin() abort
|
||||
let l:win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
|
||||
for l:w in l:win
|
||||
if (has(l:w))
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
endf
|
||||
|
||||
fun! elm#util#CheckBin(bin, url) abort
|
||||
let l:binpath = substitute(a:bin, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
if executable(l:binpath)
|
||||
return l:binpath
|
||||
endif
|
||||
|
||||
call elm#util#EchoWarning('elm-vim:', 'could not find ' . l:binpath . ' [' . a:url . ']')
|
||||
|
||||
return ''
|
||||
endf
|
||||
|
||||
" Determines the browser command to use
|
||||
fun! s:get_browser_command() abort
|
||||
let l:elm_browser_command = get(g:, 'elm_browser_command', '')
|
||||
if l:elm_browser_command ==? ''
|
||||
if elm#util#IsWin()
|
||||
let l:elm_browser_command = '!start rundll32 url.dll,FileProtocolHandler %URL%'
|
||||
elseif has('mac') || has('macunix') || has('gui_macvim') || system('uname') =~? '^darwin'
|
||||
let l:elm_browser_command = 'open %URL%'
|
||||
elseif executable('xdg-open')
|
||||
let l:elm_browser_command = 'xdg-open %URL%'
|
||||
elseif executable('firefox')
|
||||
let l:elm_browser_command = 'firefox %URL% &'
|
||||
else
|
||||
let l:elm_browser_command = ''
|
||||
endif
|
||||
endif
|
||||
return l:elm_browser_command
|
||||
endf
|
||||
|
||||
" OpenBrowser opens a url in the default browser
|
||||
fun! elm#util#OpenBrowser(url) abort
|
||||
let l:cmd = s:get_browser_command()
|
||||
if len(l:cmd) == 0
|
||||
redraw
|
||||
echohl WarningMsg
|
||||
echo "It seems that you don't have general web browser. Open URL below."
|
||||
echohl None
|
||||
echo a:url
|
||||
return
|
||||
endif
|
||||
if l:cmd =~? '^!'
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=shellescape(a:url)', 'g')
|
||||
silent! exec l:cmd
|
||||
elseif l:cmd =~# '^:[A-Z]'
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=a:url', 'g')
|
||||
exec l:cmd
|
||||
else
|
||||
let l:cmd = substitute(l:cmd, '%URL%', '\=shellescape(a:url)', 'g')
|
||||
call system(l:cmd)
|
||||
endif
|
||||
endf
|
||||
|
||||
" DecodeJSON decodes a string of json into a viml object
|
||||
fun! elm#util#DecodeJSON(s) abort
|
||||
let l:true = 1
|
||||
let l:false = 0
|
||||
let l:null = 0
|
||||
return eval(a:s)
|
||||
endf
|
||||
|
||||
" Remove ANSI escape characters used for highlighting purposes
|
||||
fun! s:strip_color(msg) abort
|
||||
return substitute(a:msg, '\e\[[0-9;]\+[mK]', '', 'g')
|
||||
endf
|
||||
|
||||
" Print functions
|
||||
fun! elm#util#Echo(title, msg) abort
|
||||
redraws! | echon a:title . ' ' | echohl Identifier | echon s:strip_color(a:msg) | echohl None
|
||||
endf
|
||||
|
||||
fun! elm#util#EchoSuccess(title, msg) abort
|
||||
redraws! | echon a:title . ' ' | echohl Function | echon s:strip_color(a:msg) | echohl None
|
||||
endf
|
||||
|
||||
fun! elm#util#EchoWarning(title, msg) abort
|
||||
redraws! | echon a:title . ' ' | echohl WarningMsg | echon s:strip_color(a:msg) | echohl None
|
||||
endf
|
||||
|
||||
fun! elm#util#EchoError(title, msg) abort
|
||||
redraws! | echon a:title . ' ' | echohl ErrorMsg | echon s:strip_color(a:msg) | echohl None
|
||||
endf
|
||||
|
||||
fun! elm#util#EchoLater(func_name, title, msg) abort
|
||||
let s:echo_func_name = a:func_name
|
||||
let s:echo_title = a:title
|
||||
let s:echo_msg = a:msg
|
||||
endf
|
||||
|
||||
fun! elm#util#EchoStored() abort
|
||||
if exists('s:echo_func_name') && exists('s:echo_title') && exists('s:echo_msg')
|
||||
call elm#util#{s:echo_func_name}(s:echo_title, s:echo_msg)
|
||||
unlet s:echo_func_name
|
||||
unlet s:echo_title
|
||||
unlet s:echo_msg
|
||||
endif
|
||||
endf
|
||||
|
||||
function! elm#util#GoToModule(name)
|
||||
if empty(a:name) | return | endif
|
||||
if empty(matchstr(a:name, '^Native\.'))
|
||||
let l:extension = '.elm'
|
||||
else
|
||||
let l:extension = '.js'
|
||||
endif
|
||||
let l:rel_path = substitute(a:name, '\.', '/', 'g') . l:extension
|
||||
let l:root = elm#FindRootDirectory()
|
||||
|
||||
let l:module_file = s:findLocalModule(l:rel_path, l:root)
|
||||
if !filereadable(l:module_file)
|
||||
let l:module_file = s:findDependencyModule(l:rel_path, l:root)
|
||||
endif
|
||||
|
||||
if filereadable(l:module_file)
|
||||
exec 'edit ' . fnameescape(l:module_file)
|
||||
else
|
||||
return s:error("Can't find module \"" . a:name . "\"")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:findLocalModule(rel_path, root)
|
||||
let l:package_json = a:root . '/elm-package.json'
|
||||
if exists('*json_decode')
|
||||
let l:package = json_decode(readfile(l:package_json))
|
||||
let l:source_roots = l:package['source-directories']
|
||||
else
|
||||
" This is a fallback for vim's which do not support json_decode.
|
||||
" It simply only looks in the 'src' subdirectory and fails otherwise.
|
||||
let l:source_roots = ['src']
|
||||
end
|
||||
for l:source_root in l:source_roots
|
||||
let l:file_path = a:root . '/' . l:source_root . '/' . a:rel_path
|
||||
if !filereadable(l:file_path)
|
||||
continue
|
||||
endif
|
||||
return l:file_path
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:findDependencyModule(rel_path, root)
|
||||
" If we are a dependency ourselves, we need to check our siblings.
|
||||
" This is because elm package doesn't install dependencies recursively.
|
||||
let l:root = substitute(a:root, '\/elm-stuff/packages.\+$', '', '')
|
||||
|
||||
" We naively craws the dependencies dir for any fitting module name.
|
||||
" If it exists, we'll find it. If multiple filenames match,
|
||||
" there's a chance we return the wrong one.
|
||||
let l:module_paths = glob(l:root . '/elm-stuff/packages/**/' . a:rel_path, 0, 1)
|
||||
if len(l:module_paths) > 0
|
||||
return l:module_paths[0]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Using the built-in :echoerr prints a stacktrace, which isn't that nice.
|
||||
" From: https://github.com/moll/vim-node/blob/master/autoload/node.vim
|
||||
function! s:error(msg)
|
||||
echohl ErrorMsg
|
||||
echomsg a:msg
|
||||
echohl NONE
|
||||
let v:errmsg = a:msg
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -1,6 +1,7 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
|
||||
|
||||
function! fish#Indent()
|
||||
let l:shiftwidth = shiftwidth()
|
||||
let l:prevlnum = prevnonblank(v:lnum - 1)
|
||||
if l:prevlnum ==# 0
|
||||
return 0
|
||||
@@ -8,15 +9,15 @@ function! fish#Indent()
|
||||
let l:indent = 0
|
||||
let l:prevline = getline(l:prevlnum)
|
||||
if l:prevline =~# '\v^\s*switch>'
|
||||
let l:indent = &shiftwidth * 2
|
||||
let l:indent = l:shiftwidth * 2
|
||||
elseif l:prevline =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
|
||||
let l:indent = &shiftwidth
|
||||
let l:indent = l:shiftwidth
|
||||
endif
|
||||
let l:line = getline(v:lnum)
|
||||
if l:line =~# '\v^\s*end>'
|
||||
return indent(v:lnum) - (l:indent ==# 0 ? &shiftwidth : l:indent)
|
||||
return indent(v:lnum) - (l:indent ==# 0 ? l:shiftwidth : l:indent)
|
||||
elseif l:line =~# '\v^\s*%(case|else)>'
|
||||
return indent(v:lnum) - &shiftwidth
|
||||
return indent(v:lnum) - l:shiftwidth
|
||||
endif
|
||||
return indent(l:prevlnum) + l:indent
|
||||
endfunction
|
||||
|
||||
188
autoload/julia.vim
Normal file
188
autoload/julia.vim
Normal file
@@ -0,0 +1,188 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'julia') == -1
|
||||
|
||||
function! julia#set_syntax_version(jvers)
|
||||
if &filetype != "julia"
|
||||
echo "Not a Julia file"
|
||||
return
|
||||
endif
|
||||
syntax clear
|
||||
let b:julia_syntax_version = a:jvers
|
||||
set filetype=julia
|
||||
endfunction
|
||||
|
||||
function! julia#toggle_deprecated_syntax()
|
||||
if &filetype != "julia"
|
||||
echo "Not a Julia file"
|
||||
return
|
||||
endif
|
||||
syntax clear
|
||||
let hd = get(b:, "julia_syntax_highlight_deprecated",
|
||||
\ get(g:, "julia_syntax_highlight_deprecated", 0))
|
||||
let b:julia_syntax_highlight_deprecated = hd ? 0 : 1
|
||||
set filetype=julia
|
||||
if b:julia_syntax_highlight_deprecated
|
||||
echo "Highlighting of deprecated syntax enabled"
|
||||
else
|
||||
echo "Highlighting of deprecated syntax disabled"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
if exists("loaded_matchit")
|
||||
|
||||
function! julia#toggle_function_blockassign()
|
||||
let sav_pos = getcurpos()
|
||||
let l = getline('.')
|
||||
let c = match(l, '\C\m\<function\s\+.\+(')
|
||||
if c != -1
|
||||
return julia#function_block2assign()
|
||||
endif
|
||||
let c = match(l, '\C\m)\%(::\S\+\)\?\%(\s\+where\s\+.*\)\?\s*=\s*')
|
||||
if c == -1
|
||||
echohl WarningMsg | echo "Not on a function definition or assignment line" | echohl None
|
||||
return
|
||||
endif
|
||||
return julia#function_assign2block()
|
||||
endfunction
|
||||
|
||||
function! julia#function_block2assign()
|
||||
let sav_pos = getcurpos()
|
||||
let l = getline('.')
|
||||
let c = match(l, '\C\m\<function\s\+.\+(')
|
||||
if c == -1
|
||||
echohl WarningMsg | echo "Not on a function definition line" | echohl None
|
||||
return
|
||||
endif
|
||||
let fpos = copy(sav_pos)
|
||||
let fpos[2] = c+1
|
||||
call setpos('.', fpos)
|
||||
normal %
|
||||
if line('.') != fpos[1]+2 || match(getline('.'), '\C\m^\s*end\s*$') == -1
|
||||
echohl WarningMsg | echo "Only works with 3-lines functions" | echohl None
|
||||
call setpos('.', sav_pos)
|
||||
return
|
||||
endif
|
||||
call setpos('.', fpos)
|
||||
normal! f(
|
||||
normal %
|
||||
while line('.') == fpos[1] && match(l[col('.')-1:], '\C\m)(') == 0
|
||||
normal! l
|
||||
normal %
|
||||
endwhile
|
||||
if line('.') != fpos[1] || match(l[(col('.')-1):], '\C\m)\%(::\S\+\)\?\%(\s\+where\s\+.*\)\?\s*$') != 0
|
||||
echohl WarningMsg | echo "Unrecognized function definition format" | echohl None
|
||||
call setpos('.', sav_pos)
|
||||
return
|
||||
endif
|
||||
|
||||
call setpos('.', fpos)
|
||||
normal! dwA = J
|
||||
if match(getline('.')[(col('.')-1):], '\C\mreturn\>') == 0
|
||||
normal! dw
|
||||
endif
|
||||
if match(getline('.')[(col('.')-1):], '\C\m\s*$') == 0
|
||||
normal! F=C= nothing
|
||||
endif
|
||||
normal! jddk^
|
||||
return
|
||||
endfunction
|
||||
|
||||
function! julia#function_assign2block()
|
||||
let sav_pos = getcurpos()
|
||||
let l = getline('.')
|
||||
let c = match(l, '\C\m)\%(::\S\+\)\?\%(\s\+where\s\+.*\)\?\s*=\s*')
|
||||
if c == -1
|
||||
echohl WarningMsg | echo "Not on a function assignment-definition line" | echohl None
|
||||
return
|
||||
endif
|
||||
normal ^
|
||||
while match(l[(col('.')-1):], '\%(\S\+\.\)*@') == 0
|
||||
normal! W
|
||||
endwhile
|
||||
normal! ifunction
|
||||
let l = getline('.')
|
||||
let c = match(l, '\C\m)\%(::\S\+\)\?\%(\s\+where\s\+.*\)\?\s*\zs=\s*')
|
||||
let eqpos = copy(sav_pos)
|
||||
let eqpos[2] = c+1
|
||||
call setpos('.', eqpos)
|
||||
normal! cw
|
||||
oend
|
||||
normal %
|
||||
s/\s*$// | noh
|
||||
return
|
||||
endfunction
|
||||
|
||||
|
||||
let s:nonid_chars = "\U01-\U07" . "\U0E-\U1F" .
|
||||
\ "\"#$'(,.:;=?@`\\U5B{" .
|
||||
\ "\U80-\UA1" . "\UA7\UA8\UAB\UAD\UAF\UB4" . "\UB6-\UB8" . "\UBB\UBF"
|
||||
|
||||
let s:nonidS_chars = "[:space:])\\U5D}" . s:nonid_chars
|
||||
|
||||
" the following excludes '!' since it can be used as an identifier,
|
||||
" and '$' since it can be used in interpolations
|
||||
" note that \U2D is '-'
|
||||
let s:uniop_chars = "+\\U2D~¬√∛∜"
|
||||
|
||||
let s:binop_chars = "=+\\U2D*/\\%÷^&|⊻<>≤≥≡≠≢∈∉⋅×∪∩⊆⊈⊂⊄⊊←→∋∌⊕⊖⊞⊟∘∧⊗⊘↑↓∨⊠±"
|
||||
|
||||
" the following is a list of all remainig valid operator chars,
|
||||
" but it's more efficient when expressed with ranges (see below)
|
||||
" let s:binop_chars_extra = "↔↚↛↠↣↦↮⇎⇏⇒⇔⇴⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿⟵⟶⟷⟷⟹⟺⟻⟼⟽⟾⟿⤀⤁⤂⤃⤄⤅⤆⤇⤌⤍⤎⤏⤐⤑⤔⤕⤖⤗⤘⤝⤞⤟⤠⥄⥅⥆⥇⥈⥊⥋⥎⥐⥒⥓⥖⥗⥚⥛⥞⥟⥢⥤⥦⥧⥨⥩⥪⥫⥬⥭⥰⧴⬱⬰⬲⬳⬴⬵⬶⬷⬸⬹⬺⬻⬼⬽⬾⬿⭀⭁⭂⭃⭄⭇⭈⭉⭊⭋⭌←→" .
|
||||
" \ "∝∊∍∥∦∷∺∻∽∾≁≃≄≅≆≇≈≉≊≋≌≍≎≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≣≦≧≨≩≪≫≬≭≮≯≰≱≲≳≴≵≶≷≸≹≺≻≼≽≾≿⊀⊁⊃⊅⊇⊉⊋⊏⊐⊑⊒⊜⊩⊬⊮⊰⊱⊲⊳⊴⊵⊶⊷⋍⋐⋑⋕⋖⋗⋘⋙⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋪⋫⋬⋭⋲⋳⋴⋵⋶⋷⋸⋹⋺⋻⋼⋽⋾⋿⟈⟉⟒⦷⧀⧁⧡⧣⧤⧥⩦⩧⩪⩫⩬⩭⩮⩯⩰⩱⩲⩳⩴⩵⩶⩷⩸⩹⩺⩻⩼⩽⩾⩿⪀⪁⪂⪃⪄⪅⪆⪇⪈⪉⪊⪋⪌⪍⪎⪏⪐⪑⪒⪓⪔⪕⪖⪗⪘⪙⪚⪛⪜⪝⪞⪟⪠⪡⪢⪣⪤⪥⪦⪧⪨⪩⪪⪫⪬⪭⪮⪯⪰⪱⪲⪳⪴⪵⪶⪷⪸⪹⪺⪻⪼⪽⪾⪿⫀⫁⫂⫃⫄⫅⫆⫇⫈⫉⫊⫋⫌⫍⫎⫏⫐⫑⫒⫓⫔⫕⫖⫗⫘⫙⫷⫸⫹⫺⊢⊣" .
|
||||
" \ "⊔∓∔∸≂≏⊎⊽⋎⋓⧺⧻⨈⨢⨣⨤⨥⨦⨧⨨⨩⨪⨫⨬⨭⨮⨹⨺⩁⩂⩅⩊⩌⩏⩐⩒⩔⩖⩗⩛⩝⩡⩢⩣" .
|
||||
" \ "⊙⊚⊛⊡⊓∗∙∤⅋≀⊼⋄⋆⋇⋉⋊⋋⋌⋏⋒⟑⦸⦼⦾⦿⧶⧷⨇⨰⨱⨲⨳⨴⨵⨶⨷⨸⨻⨼⨽⩀⩃⩄⩋⩍⩎⩑⩓⩕⩘⩚⩜⩞⩟⩠⫛⊍▷⨝⟕⟖⟗" .
|
||||
" \ "⇵⟰⟱⤈⤉⤊⤋⤒⤓⥉⥌⥍⥏⥑⥔⥕⥘⥙⥜⥝⥠⥡⥣⥥⥮⥯↑↓"
|
||||
|
||||
" same as above, but with character ranges, for performance
|
||||
let s:binop_chars_extra = "\\U214B\\U2190-\\U2194\\U219A\\U219B\\U21A0\\U21A3\\U21A6\\U21AE\\U21CE\\U21CF\\U21D2\\U21D4\\U21F4-\\U21FF\\U2208-\\U220D\\U2213\\U2214\\U2217-\\U2219\\U221D\\U2224-\\U222A\\U2237\\U2238\\U223A\\U223B\\U223D\\U223E\\U2240-\\U228B\\U228D-\\U229C\\U229E-\\U22A3\\U22A9\\U22AC\\U22AE\\U22B0-\\U22B7\\U22BB-\\U22BD\\U22C4-\\U22C7\\U22C9-\\U22D3\\U22D5-\\U22ED\\U22F2-\\U22FF\\U25B7\\U27C8\\U27C9\\U27D1\\U27D2\\U27D5-\\U27D7\\U27F0\\U27F1\\U27F5-\\U27F7\\U27F7\\U27F9-\\U27FF\\U2900-\\U2918\\U291D-\\U2920\\U2944-\\U2970\\U29B7\\U29B8\\U29BC\\U29BE-\\U29C1\\U29E1\\U29E3-\\U29E5\\U29F4\\U29F6\\U29F7\\U29FA\\U29FB\\U2A07\\U2A08\\U2A1D\\U2A22-\\U2A2E\\U2A30-\\U2A3D\\U2A40-\\U2A45\\U2A4A-\\U2A58\\U2A5A-\\U2A63\\U2A66\\U2A67\\U2A6A-\\U2AD9\\U2ADB\\U2AF7-\\U2AFA\\U2B30-\\U2B44\\U2B47-\\U2B4C\\UFFE9-\\UFFEC"
|
||||
|
||||
" a Julia identifier, sort of
|
||||
let s:idregex = '[^' . s:nonidS_chars . '0-9!' . s:uniop_chars . s:binop_chars . '][^' . s:nonidS_chars . s:uniop_chars . s:binop_chars . s:binop_chars_extra . ']*'
|
||||
|
||||
let s:operators = '\%(' . '\.\%([-+*/^÷%|&!]\|//\|\\\|<<\|>>>\?\)\?=' .
|
||||
\ '\|' . '[:$<>]=\|||\|&&\||>\|<|\|<:\|:>\|::\|<<\|>>>\?\|//\|[-=]>\|\.\{3\}' .
|
||||
\ '\|' . '[' . s:uniop_chars . '!$]' .
|
||||
\ '\|' . '\.\?[' . s:binop_chars . s:binop_chars_extra . ']' .
|
||||
\ '\)'
|
||||
|
||||
function! julia#idundercursor()
|
||||
" TODO...
|
||||
let w = expand('<cword>')
|
||||
" let [l,c] = [line('.'),col('.')]
|
||||
" let ll = getline(l)
|
||||
return w
|
||||
endfunction
|
||||
|
||||
function! julia#gotodefinition()
|
||||
let w = julia#idundercursor()
|
||||
if empty(w)
|
||||
return ''
|
||||
endif
|
||||
let [l,c] = [line('.'),col('.')]
|
||||
let st = map(synstack(l,c), 'synIDattr(v:val, "name")')
|
||||
let n = len(st)
|
||||
if n > 0 && st[-1] =~# '^julia\%(\%(Range\|Ternary\|CTrans\)\?Operator\|\%(Possible\)\?SymbolS\?\|\%(Bl\|Rep\)\?Keyword\|Conditional\|ParDelim\|Char\|Colon\|Typedef\|Number\|Float\|Const\%(Generic\|Bool\)\|ComplexUnit\|\%(Special\|\%(Octal\|Hex\)Escape\)Char\|UniChar\%(Small\|Large\)\|Comment[LM]\|Todo\|Semicolon\)$'
|
||||
return ''
|
||||
endif
|
||||
|
||||
let comprehension = 0
|
||||
let indollar = 0
|
||||
for i in range(n-1, 0, -1)
|
||||
if st[i] =~# '^juliaDollar\%(Var\|Par\|SqBra\)$'
|
||||
let indollar = 1
|
||||
endif
|
||||
if !indollar && st[i] =~# '^julia\%(\a*String\|QuotedParBlockS\?\)$'
|
||||
return ''
|
||||
endif
|
||||
if st[i] =~# '^julia\%(ParBlock\%(InRange\)\?\|SqBraBlock\|\%(Dollar\|StringVars\)\%(Par\|SqBra\)\)$'
|
||||
let comprehension = 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
let s1 = search('\C\<' . w . '\s*=[^=]', 'bcWzs')
|
||||
|
||||
return
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
798
autoload/julia_blocks.vim
Normal file
798
autoload/julia_blocks.vim
Normal file
@@ -0,0 +1,798 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'julia') == -1
|
||||
|
||||
" Facilities for moving around Julia blocks (e.g. if/end, function/end etc.)
|
||||
" (AKA a collection of horrible hacks)
|
||||
|
||||
let s:default_mappings = {
|
||||
\ "moveblock_n" : "]]",
|
||||
\ "moveblock_N" : "][",
|
||||
\ "moveblock_p" : "[[",
|
||||
\ "moveblock_P" : "[]",
|
||||
\
|
||||
\ "move_n" : "]j",
|
||||
\ "move_N" : "]J",
|
||||
\ "move_p" : "[j",
|
||||
\ "move_P" : "[J",
|
||||
\
|
||||
\ "select_a" : "aj",
|
||||
\ "select_i" : "ij",
|
||||
\
|
||||
\ "whereami" : "",
|
||||
\ }
|
||||
|
||||
function! s:getmapchars(function)
|
||||
if exists("g:julia_blocks_mappings") && has_key(g:julia_blocks_mappings, a:function)
|
||||
return s:escape(g:julia_blocks_mappings[a:function])
|
||||
else
|
||||
return s:escape(s:default_mappings[a:function])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:map_move(function, toend, backwards)
|
||||
let chars = s:getmapchars(a:function)
|
||||
if empty(chars)
|
||||
return
|
||||
endif
|
||||
let fn = "julia_blocks#" . a:function
|
||||
let lhs = "<buffer> <nowait> <silent> " . chars . " "
|
||||
let cnt = ":<C-U>let b:jlblk_count=v:count1"
|
||||
exe "nnoremap " . lhs . cnt
|
||||
\ . " <Bar> call " . fn . "()<CR>"
|
||||
exe "onoremap " . lhs . cnt
|
||||
\ . "<CR><Esc>:call julia_blocks#owrapper_move(v:operator, \"" . fn . "\", " . a:toend . ", " . a:backwards . ")<CR>"
|
||||
exe "xnoremap " . lhs . cnt
|
||||
\ . "<CR>gv<Esc>:call julia_blocks#vwrapper_move(\"" . fn . "\")<CR>"
|
||||
let b:jlblk_mapped[a:function] = 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#owrapper_move(oper, function, toend, backwards)
|
||||
let F = function(a:function)
|
||||
|
||||
let save_redraw = &lazyredraw
|
||||
let save_select = &selection
|
||||
|
||||
let restore_cmds = "\<Esc>"
|
||||
\ . ":let &l:selection = \"" . save_select . "\"\<CR>"
|
||||
\ . ":let &l:lazyredraw = " . save_redraw . "\<CR>"
|
||||
\ . ":\<BS>"
|
||||
|
||||
setlocal lazyredraw
|
||||
|
||||
let start_pos = getpos('.')
|
||||
let b:jlblk_abort_calls_esc = 0
|
||||
call F()
|
||||
let b:jlblk_abort_calls_esc = 1
|
||||
let end_pos = getpos('.')
|
||||
if start_pos == end_pos
|
||||
call feedkeys(restore_cmds, 'n')
|
||||
endif
|
||||
|
||||
let &l:selection = "inclusive"
|
||||
if a:backwards || !a:toend
|
||||
let &l:selection = "exclusive"
|
||||
endif
|
||||
if a:toend && a:backwards
|
||||
let end_pos[2] += 1
|
||||
endif
|
||||
|
||||
if s:compare_pos(start_pos, end_pos) > 0
|
||||
let [start_pos, end_pos] = [end_pos, start_pos]
|
||||
endif
|
||||
|
||||
call setpos("'<", start_pos)
|
||||
call setpos("'>", end_pos)
|
||||
|
||||
" NOTE: the 'c' operator behaves differently, for mysterious reasons. We
|
||||
" simulate it with 'd' followed by 'i' instead
|
||||
call feedkeys("gv" . (a:oper == "c" ? "d" : a:oper) . restore_cmds . (a:oper == "c" ? "i" : ""), 'n')
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#vwrapper_move(function)
|
||||
let F = function(a:function)
|
||||
|
||||
let s = getpos('.')
|
||||
let b1 = getpos("'<")
|
||||
let b2 = getpos("'>")
|
||||
|
||||
let b = b1 == s ? b2 : b1
|
||||
call setpos('.', s)
|
||||
let b:jlblk_abort_calls_esc = 0
|
||||
call F()
|
||||
let b:jlblk_abort_calls_esc = 1
|
||||
let e = getpos('.')
|
||||
call setpos('.', b)
|
||||
exe "normal " . visualmode()
|
||||
call setpos('.', e)
|
||||
endfunction
|
||||
|
||||
function! s:unmap(function)
|
||||
if !get(b:jlblk_mapped, a:function, 0)
|
||||
return
|
||||
endif
|
||||
let chars = s:getmapchars(a:function)
|
||||
if empty(chars)
|
||||
" shouldn't happen
|
||||
return
|
||||
endif
|
||||
let mapids = a:function =~# "^move" ? ["n", "x", "o"] :
|
||||
\ a:function =~# "^select" ? ["x", "o"] :
|
||||
\ ["n"]
|
||||
let fn = "julia_blocks#" . a:function
|
||||
let cmd = "<buffer> " . chars
|
||||
for m in mapids
|
||||
exe m . "unmap " . cmd
|
||||
endfor
|
||||
let b:jlblk_mapped[a:function] = 0
|
||||
endfunction
|
||||
|
||||
function! s:escape(chars)
|
||||
let c = a:chars
|
||||
let c = substitute(c, '|', '<Bar>', 'g')
|
||||
return c
|
||||
endfunction
|
||||
|
||||
function! s:map_select(function)
|
||||
let chars = s:getmapchars(a:function)
|
||||
if empty(chars)
|
||||
return
|
||||
endif
|
||||
let fn = "julia_blocks#" . a:function
|
||||
let lhs = "<buffer> <nowait> <silent> " . chars . " "
|
||||
let cnt = ":<C-U>let b:jlblk_inwrapper=1<CR>:let b:jlblk_count=max([v:prevcount,1])<CR>"
|
||||
exe "onoremap " . lhs . "<Esc>" . cnt
|
||||
\ . ":call julia_blocks#owrapper_select(v:operator, \"" . fn . "\")<CR>"
|
||||
exe "xnoremap " . lhs . cnt
|
||||
\ . ":call julia_blocks#vwrapper_select(\"" . fn . "\")<CR>"
|
||||
let b:jlblk_mapped[a:function] = 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#owrapper_select(oper, function) ", toend, backwards)
|
||||
let F = function(a:function)
|
||||
|
||||
let save_redraw = &lazyredraw
|
||||
let save_select = &selection
|
||||
|
||||
let restore_cmds = "\<Esc>"
|
||||
\ . ":let &l:selection = \"" . save_select . "\"\<CR>"
|
||||
\ . ":let &l:lazyredraw = " . save_redraw . "\<CR>"
|
||||
\ . ":\<BS>"
|
||||
|
||||
setlocal lazyredraw
|
||||
|
||||
let b:jlblk_abort_calls_esc = 0
|
||||
let retF = F()
|
||||
let b:jlblk_abort_calls_esc = 1
|
||||
if empty(retF)
|
||||
let b:jlblk_inwrapper = 0
|
||||
call feedkeys(restore_cmds, 'n')
|
||||
return
|
||||
end
|
||||
let [start_pos, end_pos] = retF
|
||||
|
||||
if start_pos == end_pos
|
||||
call feedkeys(restore_cmds, 'n')
|
||||
endif
|
||||
|
||||
let &l:selection = "inclusive"
|
||||
|
||||
call setpos("'<", start_pos)
|
||||
call setpos("'>", end_pos)
|
||||
|
||||
let b:jlblk_inwrapper = 0
|
||||
" NOTE: the 'c' operator behaves differently, for mysterious reasons. We
|
||||
" simulate it with 'd' followed by 'i' instead
|
||||
call feedkeys("gv" . (a:oper == "c" ? "d" : a:oper) . restore_cmds . (a:oper == "c" ? "i" : ""), 'n')
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#vwrapper_select(function)
|
||||
let F = function(a:function)
|
||||
|
||||
let b:jlblk_abort_calls_esc = 0
|
||||
let retF = F()
|
||||
let b:jlblk_abort_calls_esc = 1
|
||||
if empty(retF)
|
||||
let b:jlblk_inwrapper = 0
|
||||
return
|
||||
end
|
||||
let [start_pos, end_pos] = retF
|
||||
call setpos("'<", start_pos)
|
||||
call setpos("'>", end_pos)
|
||||
normal! gv
|
||||
let b:jlblk_inwrapper = 0
|
||||
endfunction
|
||||
|
||||
function! s:map_aux(function)
|
||||
let chars = s:getmapchars(a:function)
|
||||
if empty(chars)
|
||||
return
|
||||
endif
|
||||
let fn = "julia_blocks#" . a:function
|
||||
let lhs = "<buffer> <nowait> <silent> " . chars . " "
|
||||
exe "nnoremap " . lhs . ":<C-U>echo " . fn . "()<CR>"
|
||||
let b:jlblk_mapped[a:function] = 1
|
||||
endfunction
|
||||
|
||||
let s:julia_blocks_functions = {
|
||||
\ "moveblock_N": [1, 0],
|
||||
\ "moveblock_n": [0, 0],
|
||||
\ "moveblock_p": [0, 1],
|
||||
\ "moveblock_P": [1, 1],
|
||||
\
|
||||
\ "move_N": [1, 0],
|
||||
\ "move_n": [0, 0],
|
||||
\ "move_p": [0, 1],
|
||||
\ "move_P": [1, 1],
|
||||
\
|
||||
\ "select_a": [],
|
||||
\ "select_i": [],
|
||||
\
|
||||
\ "whereami": [],
|
||||
\ }
|
||||
|
||||
function! julia_blocks#init_mappings()
|
||||
let b:jlblk_mapped = {}
|
||||
for f in keys(s:julia_blocks_functions)
|
||||
if f =~# "^move"
|
||||
let [te, bw] = s:julia_blocks_functions[f]
|
||||
call s:map_move(f, te, bw)
|
||||
elseif f =~# "^select"
|
||||
call s:map_select(f)
|
||||
else
|
||||
call s:map_aux(f)
|
||||
endif
|
||||
endfor
|
||||
call julia_blocks#select_reset()
|
||||
augroup JuliaBlocks
|
||||
au!
|
||||
au InsertEnter *.jl call julia_blocks#select_reset()
|
||||
au CursorMoved *.jl call s:cursor_moved()
|
||||
augroup END
|
||||
|
||||
" we would need some autocmd event associated with exiting from
|
||||
" visual mode, but there isn't any, so we resort to this crude
|
||||
" hack
|
||||
" ACTUALLY this creates more problems than it solves, so the crude hack
|
||||
" is just disabled
|
||||
"vnoremap <buffer><silent><unique> <Esc> <Esc>:call julia_blocks#select_reset()<CR>
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#remove_mappings()
|
||||
if exists("b:jlblk_mapped")
|
||||
for f in keys(s:julia_blocks_functions)
|
||||
call s:unmap(f)
|
||||
endfor
|
||||
endif
|
||||
unlet! b:jlblk_save_pos b:jlblk_view b:jlblk_count b:jlblk_abort_calls_esc
|
||||
unlet! b:jlblk_inwrapper b:jlblk_did_select b:jlblk_doing_select
|
||||
unlet! b:jlblk_last_start_pos b:jlblk_last_end_pos b:jlblk_last_mode
|
||||
augroup JuliaBlocks
|
||||
au!
|
||||
augroup END
|
||||
augroup! JuliaBlocks
|
||||
let md = maparg("<Esc>", "x", 0, 1)
|
||||
if !empty(md) && md["buffer"]
|
||||
vunmap <buffer> <Esc>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:restore_view()
|
||||
"redraw! " would ensure correct behaviour, but is annoying
|
||||
let pos = getpos('.')
|
||||
if pos == b:jlblk_save_pos
|
||||
call winrestview(b:jlblk_view)
|
||||
return
|
||||
endif
|
||||
let oldtopline = b:jlblk_view["topline"]
|
||||
let newtopline = winsaveview()["topline"]
|
||||
let l = pos[1]
|
||||
if l >= oldtopline + &l:scrolloff && l <= oldtopline + winheight(0) - 1 - &l:scrolloff
|
||||
if newtopline > oldtopline
|
||||
exe ":normal! " . (newtopline - oldtopline) . "\<C-Y>"
|
||||
elseif newtopline < oldtopline
|
||||
exe ":normal! " . (oldtopline - newtopline) . "\<C-E>"
|
||||
endif
|
||||
" these reduce the scrolling to the minimum (which is maybe not
|
||||
" standard ViM behaviour?)
|
||||
elseif newtopline < oldtopline && (l - newtopline - &l:scrolloff) > 0
|
||||
exe ":normal! " . (l - newtopline - &l:scrolloff) . "\<C-E>"
|
||||
elseif newtopline > oldtopline && (newtopline + &l:scrolloff - l) > 0
|
||||
exe ":normal! " . (l - newtopline - &l:scrolloff) . "\<C-E>"
|
||||
endif
|
||||
call setpos('.', pos) " make sure we didn't screw up
|
||||
" (since winsaveview may not be up to date)
|
||||
endfunction
|
||||
|
||||
function! s:abort()
|
||||
call setpos('.', b:jlblk_save_pos)
|
||||
call s:restore_view()
|
||||
if get(b:, "jlblk_abort_calls_esc", 1)
|
||||
call feedkeys("\<Esc>", 'n')
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:set_mark_tick(...)
|
||||
" This could be a one-liner:
|
||||
" call setpos("''", b:jlblk_save_pos)
|
||||
" but we want to append to the jumplist,
|
||||
" which setpos doesn't do
|
||||
let p = getpos('.')
|
||||
call setpos('.', b:jlblk_save_pos)
|
||||
normal! m'
|
||||
call setpos('.', p)
|
||||
endfunction
|
||||
|
||||
function! s:get_save_pos(...)
|
||||
if !exists("b:jlblk_save_pos") || (a:0 == 0) || (a:0 > 0 && a:1)
|
||||
let b:jlblk_save_pos = getpos('.')
|
||||
endif
|
||||
let b:jlblk_view = winsaveview()
|
||||
endfunction
|
||||
|
||||
function! s:on_end()
|
||||
return getline('.')[col('.')-1] =~# '\k' && expand("<cword>") =~# b:julia_end_keywords
|
||||
endfunction
|
||||
|
||||
function! s:on_begin()
|
||||
let [l,c] = [line('.'), col('.')]
|
||||
normal! ^
|
||||
let patt = '\%<'.(c+1).'c\(' . b:julia_begin_keywordsm . '\)\%>'.(c-1).'c'
|
||||
let n = search(patt, 'Wnc', l)
|
||||
call cursor(l, c)
|
||||
return n > 0
|
||||
endfunction
|
||||
|
||||
function! s:matchit()
|
||||
let lkj = exists(":lockjumps") == 2 ? "lockjumps " : ""
|
||||
exe lkj . "normal %"
|
||||
endfunction
|
||||
|
||||
function! s:move_before_begin()
|
||||
call search(b:julia_begin_keywordsm, 'Wbc')
|
||||
normal! h
|
||||
endfunction
|
||||
|
||||
function! s:cycle_until_end()
|
||||
let pos = getpos('.')
|
||||
while !s:on_end()
|
||||
call s:matchit()
|
||||
let c = 0
|
||||
if getpos('.') == pos || c > 1000
|
||||
" shouldn't happen, but let's avoid infinite loops anyway
|
||||
return 0
|
||||
endif
|
||||
let c += 1
|
||||
endwhile
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:moveto_block_delim(toend, backwards, ...)
|
||||
let pattern = a:toend ? b:julia_end_keywords : b:julia_begin_keywordsm
|
||||
let flags = a:backwards ? 'Wb' : 'W'
|
||||
let cnt = a:0 > 0 ? a:1 : b:jlblk_count
|
||||
if !a:toend && a:backwards && s:on_begin()
|
||||
call s:move_before_begin()
|
||||
endif
|
||||
let ret = 0
|
||||
for c in range(cnt)
|
||||
if a:toend && a:backwards && s:on_end()
|
||||
normal! l
|
||||
normal! bh
|
||||
endif
|
||||
while 1
|
||||
let searchret = search(pattern, flags)
|
||||
if !searchret
|
||||
return ret
|
||||
endif
|
||||
exe "let skip = " . b:match_skip
|
||||
if !skip
|
||||
let ret = 1
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
endfor
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
function! s:compare_pos(pos1, pos2)
|
||||
if a:pos1[1] < a:pos2[1]
|
||||
return -1
|
||||
elseif a:pos1[1] > a:pos2[1]
|
||||
return 1
|
||||
elseif a:pos1[2] < a:pos2[2]
|
||||
return -1
|
||||
elseif a:pos1[2] > a:pos2[2]
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#move_N()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = s:moveto_block_delim(1, 0)
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
normal! e
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#move_n()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = s:moveto_block_delim(0, 0)
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#move_p()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = s:moveto_block_delim(0, 1)
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#move_P()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = s:moveto_block_delim(1, 1)
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
normal! e
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:moveto_currentblock_end()
|
||||
let flags = 'W'
|
||||
if s:on_end()
|
||||
let flags .= 'c'
|
||||
" NOTE: using "normal! lb" fails at the end of the file (?!)
|
||||
normal! l
|
||||
normal! b
|
||||
endif
|
||||
|
||||
let ret = searchpair(b:julia_begin_keywordsm, '', b:julia_end_keywords, flags, b:match_skip)
|
||||
if ret <= 0
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
normal! e
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#moveblock_N()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = 0
|
||||
for c in range(b:jlblk_count)
|
||||
let last_seen_pos = getpos('.')
|
||||
if s:on_end()
|
||||
normal! hel
|
||||
let save_pos = getpos('.')
|
||||
let ret_start = s:moveto_block_delim(0, 0, 1)
|
||||
let start1_pos = ret_start ? getpos('.') : [0,0,0,0]
|
||||
call setpos('.', save_pos)
|
||||
if s:on_end()
|
||||
normal! h
|
||||
endif
|
||||
let ret_end = s:moveto_block_delim(1, 0, 1)
|
||||
let end1_pos = ret_end ? getpos('.') : [0,0,0,0]
|
||||
|
||||
if ret_start && (!ret_end || s:compare_pos(start1_pos, end1_pos) < 0)
|
||||
call setpos('.', start1_pos)
|
||||
else
|
||||
call setpos('.', save_pos)
|
||||
endif
|
||||
endif
|
||||
|
||||
let moveret = s:moveto_currentblock_end()
|
||||
if !moveret && c == 0
|
||||
let moveret = s:moveto_block_delim(0, 0, 1) && s:cycle_until_end()
|
||||
if moveret
|
||||
normal! e
|
||||
endif
|
||||
endif
|
||||
if !moveret
|
||||
call setpos('.', last_seen_pos)
|
||||
break
|
||||
endif
|
||||
|
||||
let ret = 1
|
||||
endfor
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#moveblock_n()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = 0
|
||||
for c in range(b:jlblk_count)
|
||||
let last_seen_pos = getpos('.')
|
||||
|
||||
call s:moveto_currentblock_end()
|
||||
if s:moveto_block_delim(0, 0, 1)
|
||||
let ret = 1
|
||||
else
|
||||
call setpos('.', last_seen_pos)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#moveblock_p()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = 0
|
||||
for c in range(b:jlblk_count)
|
||||
let last_seen_pos = getpos('.')
|
||||
if s:on_begin()
|
||||
call s:move_before_begin()
|
||||
if s:on_end()
|
||||
normal! l
|
||||
endif
|
||||
let save_pos = getpos('.')
|
||||
let ret_start = s:moveto_block_delim(0, 1, 1)
|
||||
let start1_pos = ret_start ? getpos('.') : [0,0,0,0]
|
||||
call setpos('.', save_pos)
|
||||
let ret_end = s:moveto_block_delim(1, 1, 1)
|
||||
let end1_pos = ret_end ? getpos('.') : [0,0,0,0]
|
||||
|
||||
if ret_end && (!ret_start || s:compare_pos(start1_pos, end1_pos) < 0)
|
||||
call setpos('.', end1_pos)
|
||||
else
|
||||
call setpos('.', save_pos)
|
||||
endif
|
||||
endif
|
||||
|
||||
let moveret = s:moveto_currentblock_end()
|
||||
if !moveret && c == 0
|
||||
let moveret = s:moveto_block_delim(1, 1, 1)
|
||||
endif
|
||||
if !moveret
|
||||
call setpos('.', last_seen_pos)
|
||||
break
|
||||
endif
|
||||
|
||||
call s:matchit()
|
||||
let ret = 1
|
||||
endfor
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
call s:restore_view()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#moveblock_P()
|
||||
call s:get_save_pos()
|
||||
|
||||
let ret = 0
|
||||
for c in range(b:jlblk_count)
|
||||
let last_seen_pos = getpos('.')
|
||||
|
||||
call s:moveto_currentblock_end()
|
||||
if s:on_end()
|
||||
call s:matchit()
|
||||
endif
|
||||
|
||||
if s:moveto_block_delim(1, 1, 1)
|
||||
" NOTE: normal! he does not work unless &whichwrap inlcudes h
|
||||
normal! h
|
||||
normal! e
|
||||
let ret = 1
|
||||
else
|
||||
call setpos('.', last_seen_pos)
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !ret
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
call s:restore_view()
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#whereami()
|
||||
let b:jlblk_count = v:count1
|
||||
let save_redraw = &lazyredraw
|
||||
setlocal lazyredraw
|
||||
let pos = getpos('.')
|
||||
let ret = julia_blocks#select_a('w')
|
||||
if empty(ret)
|
||||
call setpos('.', pos)
|
||||
let &l:lazyredraw = save_redraw
|
||||
return ""
|
||||
end
|
||||
let [start_pos, end_pos] = ret
|
||||
let m = getline(start_pos[1])[start_pos[2]-1:]
|
||||
|
||||
" If cursor_moved was not forced from select_a, we force it now
|
||||
" (TODO: this is *really* ugly)
|
||||
if end_pos != pos
|
||||
call s:cursor_moved(1)
|
||||
endif
|
||||
call setpos('.', pos)
|
||||
call s:restore_view()
|
||||
let &l:lazyredraw = save_redraw
|
||||
return m
|
||||
endfunction
|
||||
|
||||
" Block text objects
|
||||
|
||||
function! s:find_block(current_mode)
|
||||
|
||||
let flags = 'W'
|
||||
|
||||
if b:jlblk_did_select
|
||||
call setpos('.', b:jlblk_last_start_pos)
|
||||
if !s:cycle_until_end()
|
||||
return s:abort()
|
||||
endif
|
||||
if !(a:current_mode[0] == 'a' && a:current_mode == b:jlblk_last_mode)
|
||||
let flags .= 'c'
|
||||
endif
|
||||
elseif s:on_end()
|
||||
let flags .= 'c'
|
||||
" NOTE: using "normal! lb" fails at the end of the file (?!)
|
||||
normal! l
|
||||
normal! b
|
||||
endif
|
||||
let searchret = searchpair(b:julia_begin_keywordsm, '', b:julia_end_keywords, flags, b:match_skip)
|
||||
if searchret <= 0
|
||||
if !b:jlblk_did_select
|
||||
return s:abort()
|
||||
else
|
||||
call setpos('.', b:jlblk_last_end_pos)
|
||||
endif
|
||||
endif
|
||||
|
||||
let end_pos = getpos('.')
|
||||
" Jump to match
|
||||
call s:matchit()
|
||||
let start_pos = getpos('.')
|
||||
|
||||
let b:jlblk_last_start_pos = copy(start_pos)
|
||||
let b:jlblk_last_end_pos = copy(end_pos)
|
||||
|
||||
return [start_pos, end_pos]
|
||||
endfunction
|
||||
|
||||
function! s:repeated_find(ai_mode)
|
||||
let repeat = b:jlblk_count + (a:ai_mode == 'i' && v:count1 > 1 ? 1 : 0)
|
||||
for c in range(repeat)
|
||||
let current_mode = (c < repeat - 1 ? 'a' : a:ai_mode)
|
||||
let ret_find_block = s:find_block(current_mode)
|
||||
if empty(ret_find_block)
|
||||
return 0
|
||||
endif
|
||||
let [start_pos, end_pos] = ret_find_block
|
||||
call setpos('.', end_pos)
|
||||
let b:jlblk_last_mode = current_mode
|
||||
if c < repeat - 1
|
||||
let b:jlblk_doing_select = 0
|
||||
let b:jlblk_did_select = 1
|
||||
endif
|
||||
endfor
|
||||
return [start_pos, end_pos]
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#select_a(...)
|
||||
let mode_flag = a:0 > 0 ? a:1 : ''
|
||||
call s:get_save_pos(!b:jlblk_did_select)
|
||||
let current_pos = getpos('.')
|
||||
let ret_find_block = s:repeated_find('a' . mode_flag)
|
||||
if empty(ret_find_block)
|
||||
return 0
|
||||
endif
|
||||
let [start_pos, end_pos] = ret_find_block
|
||||
|
||||
call setpos('.', end_pos)
|
||||
normal! e
|
||||
let end_pos = getpos('.')
|
||||
|
||||
let b:jlblk_doing_select = 1
|
||||
|
||||
" CursorMove is only triggered if end_pos
|
||||
" end_pos is different than the staring position;
|
||||
" so when starting from the 'd' in 'end' we need to
|
||||
" force it
|
||||
if current_pos == end_pos
|
||||
call s:cursor_moved(1)
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
return [start_pos, end_pos]
|
||||
endfunction
|
||||
|
||||
function! julia_blocks#select_i()
|
||||
call s:get_save_pos(!b:jlblk_did_select)
|
||||
let current_pos = getpos('.')
|
||||
let ret_find_block = s:repeated_find('i')
|
||||
if empty(ret_find_block)
|
||||
return 0
|
||||
endif
|
||||
let [start_pos, end_pos] = ret_find_block
|
||||
|
||||
if end_pos[1] <= start_pos[1]+1
|
||||
return s:abort()
|
||||
endif
|
||||
|
||||
call setpos('.', end_pos)
|
||||
|
||||
let b:jlblk_doing_select = 1
|
||||
|
||||
let start_pos[1] += 1
|
||||
call setpos('.', start_pos)
|
||||
normal! ^
|
||||
let start_pos = getpos('.')
|
||||
let end_pos[1] -= 1
|
||||
let end_pos[2] = len(getline(end_pos[1]))
|
||||
|
||||
" CursorMove is only triggered if end_pos
|
||||
" end_pos is different than the staring position;
|
||||
" so when starting from the 'd' in 'end' we need to
|
||||
" force it
|
||||
if current_pos == end_pos
|
||||
call s:cursor_moved(1)
|
||||
endif
|
||||
|
||||
call s:set_mark_tick()
|
||||
return [start_pos, end_pos]
|
||||
endfunction
|
||||
|
||||
function julia_blocks#select_reset()
|
||||
let b:jlblk_did_select = 0
|
||||
let b:jlblk_doing_select = 0
|
||||
let b:jlblk_inwrapper = 0
|
||||
let b:jlblk_last_mode = ""
|
||||
endfunction
|
||||
|
||||
function! s:cursor_moved(...)
|
||||
if b:jlblk_inwrapper && !(a:0 > 0 && a:1)
|
||||
return
|
||||
endif
|
||||
let b:jlblk_did_select = b:jlblk_doing_select
|
||||
let b:jlblk_doing_select = 0
|
||||
endfunction
|
||||
|
||||
endif
|
||||
3316
autoload/julia_latex_symbols.vim
Normal file
3316
autoload/julia_latex_symbols.vim
Normal file
File diff suppressed because it is too large
Load Diff
7
autoload/racket.vim
Normal file
7
autoload/racket.vim
Normal file
@@ -0,0 +1,7 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'racket') == -1
|
||||
|
||||
if !exists("g:raco_command")
|
||||
let g:raco_command = system("which raco")
|
||||
endif
|
||||
|
||||
endif
|
||||
@@ -589,13 +589,15 @@ class VimRubyCompletion
|
||||
# {{{ main completion code
|
||||
def self.preload_rails
|
||||
a = VimRubyCompletion.new
|
||||
require 'Thread'
|
||||
if VIM::evaluate("has('nvim')") == 0
|
||||
require 'thread'
|
||||
Thread.new(a) do |b|
|
||||
begin
|
||||
b.load_rails
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
a.load_rails
|
||||
rescue
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
" Author: Kevin Ballard
|
||||
" Description: Helper functions for Rust commands/mappings
|
||||
" Last Modified: May 27, 2014
|
||||
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
|
||||
|
||||
" Jump {{{1
|
||||
|
||||
@@ -408,11 +409,15 @@ function! rust#Play(count, line1, line2, ...) abort
|
||||
let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {})
|
||||
let url = res.content
|
||||
|
||||
if exists('g:rust_clip_command')
|
||||
call system(g:rust_clip_command, url)
|
||||
endif
|
||||
|
||||
redraw | echomsg 'Done: '.url
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" vim: set noet sw=4 ts=4:
|
||||
" vim: set noet sw=8 ts=8:
|
||||
|
||||
endif
|
||||
|
||||
@@ -3,6 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
" Author: Stephen Sugden <stephen@stephensugden.com>
|
||||
"
|
||||
" Adapted from https://github.com/fatih/vim-go
|
||||
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
|
||||
|
||||
if !exists("g:rustfmt_autosave")
|
||||
let g:rustfmt_autosave = 0
|
||||
|
||||
18
autoload/vifm/edit.vim
Normal file
18
autoload/vifm/edit.vim
Normal file
@@ -0,0 +1,18 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" common functions for vifm command-line editing buffer filetype plugins
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: August 18, 2013
|
||||
|
||||
" Prepare buffer
|
||||
function! vifm#edit#Init()
|
||||
" Mappings for quick leaving the buffer (behavior similar to Command line
|
||||
" buffer in Vim)
|
||||
nnoremap <buffer> <cr> :copy 0 \| wq<cr>
|
||||
imap <buffer> <cr> <esc><cr>
|
||||
|
||||
" Start buffer editing in insert mode
|
||||
startinsert
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -3,33 +3,220 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'html5') == -1
|
||||
" Vim completion for WAI-ARIA data file
|
||||
" Language: HTML + WAI-ARIA
|
||||
" Maintainer: othree <othree@gmail.com>
|
||||
" Last Change: 2010 Sep 09
|
||||
" Last Change: 2017 Mar 07
|
||||
|
||||
" WAI_ARIA: {{{
|
||||
" Ref: http://www.w3.org/TR/wai-aria/
|
||||
" Version: Draft 15 December 2009
|
||||
" Ref: https://www.w3.org/TR/wai-aria-1.1/
|
||||
" Version: W3C Candidate Recommendation 27 October 2016
|
||||
|
||||
let abstract_role = {}
|
||||
let role_attributes = {}
|
||||
let default_role = {}
|
||||
|
||||
" Ref: http://www.w3.org/TR/wai-aria/roles
|
||||
" Version: Draft 15 December 2009
|
||||
let widget_role = ['alert', 'alertdialog', 'button', 'checkbox', 'combobox', 'dialog', 'gridcell', 'link', 'log', 'marquee', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'option', 'progressbar', 'radio', 'radiogroup', 'scrollbar', 'slider', 'spinbutton', 'status', 'tab', 'tabpanel', 'textbox', 'timer', 'tooltip', 'treeitem', 'combobox', 'grid', 'listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid']
|
||||
let document_structure = ['article', 'columnheader', 'definition', 'directory', 'document', 'group', 'heading', 'img', 'list', 'listitem', 'math', 'note', 'presentation', 'region', 'row', 'rowheader', 'separator']
|
||||
let landmark_role = ['application', 'banner', 'complementary', 'contentinfo', 'form', 'main', 'navigation', 'search']
|
||||
let dpub_role = ['dpub-abstract', 'dpub-afterword', 'dpub-appendix', 'dpub-biblioentry', 'dpub-bibliography', 'dpub-biblioref', 'dpub-chapter', 'dpub-cover', 'dpub-epilogue', 'dpub-footnote', 'dpub-footnotes', 'dpub-foreword', 'dpub-glossary', 'dpub-glossdef', 'dpub-glossref', 'dpub-glossterm', 'dpub-index', 'dpub-locator', 'dpub-noteref', 'dpub-notice', 'dpub-pagebreak', 'dpub-pagelist', 'dpub-part', 'dpub-preface', 'dpub-prologue', 'dpub-pullquote', 'dpub-qna', 'dpub-subtitle', 'dpub-tip', 'dpub-title', 'dpub-toc']
|
||||
" Ref: https://www.w3.org/TR/wai-aria-1.1/#roles_categorization
|
||||
" Version: W3C Candidate Recommendation 27 October 2016
|
||||
let widget_role = [
|
||||
\ 'alert',
|
||||
\ 'alertdialog',
|
||||
\ 'button',
|
||||
\ 'checkbox',
|
||||
\ 'combobox',
|
||||
\ 'dialog',
|
||||
\ 'gridcell',
|
||||
\ 'link',
|
||||
\ 'log',
|
||||
\ 'marquee',
|
||||
\ 'menuitem',
|
||||
\ 'menuitemcheckbox',
|
||||
\ 'menuitemradio',
|
||||
\ 'option',
|
||||
\ 'progressbar',
|
||||
\ 'radio',
|
||||
\ 'radiogroup',
|
||||
\ 'scrollbar',
|
||||
\ 'searchbox',
|
||||
\ 'slider',
|
||||
\ 'spinbutton',
|
||||
\ 'status',
|
||||
\ 'switch',
|
||||
\ 'tab',
|
||||
\ 'tabpanel',
|
||||
\ 'textbox',
|
||||
\ 'timer',
|
||||
\ 'tooltip',
|
||||
\ 'treeitem',
|
||||
\ 'combobox',
|
||||
\ 'grid',
|
||||
\ 'listbox',
|
||||
\ 'menu',
|
||||
\ 'menubar',
|
||||
\ 'radiogroup',
|
||||
\ 'tablist',
|
||||
\ 'tree',
|
||||
\ 'treegrid'
|
||||
\ ]
|
||||
|
||||
let document_structure = [
|
||||
\ 'article',
|
||||
\ 'cell',
|
||||
\ 'columnheader',
|
||||
\ 'definition',
|
||||
\ 'directory',
|
||||
\ 'document',
|
||||
\ 'feed',
|
||||
\ 'figure',
|
||||
\ 'group',
|
||||
\ 'heading',
|
||||
\ 'img',
|
||||
\ 'list',
|
||||
\ 'listitem',
|
||||
\ 'math',
|
||||
\ 'none',
|
||||
\ 'note',
|
||||
\ 'presentation',
|
||||
\ 'region',
|
||||
\ 'row',
|
||||
\ 'rowheader',
|
||||
\ 'separator',
|
||||
\ 'table',
|
||||
\ 'term'
|
||||
\ ]
|
||||
|
||||
let landmark_role = [
|
||||
\ 'application',
|
||||
\ 'banner',
|
||||
\ 'complementary',
|
||||
\ 'contentinfo',
|
||||
\ 'form',
|
||||
\ 'main',
|
||||
\ 'navigation',
|
||||
\ 'search'
|
||||
\ ]
|
||||
|
||||
" Ref: https://www.w3.org/TR/dpub-aria-1.0/
|
||||
" Version: W3C Candidate Recommendation 15 December 2016
|
||||
let dpub_role = [
|
||||
\ 'dpub-abstract',
|
||||
\ 'dpub-afterword',
|
||||
\ 'dpub-appendix',
|
||||
\ 'dpub-biblioentry',
|
||||
\ 'dpub-bibliography',
|
||||
\ 'dpub-biblioref',
|
||||
\ 'dpub-chapter',
|
||||
\ 'dpub-cover',
|
||||
\ 'dpub-epilogue',
|
||||
\ 'dpub-footnote',
|
||||
\ 'dpub-footnotes',
|
||||
\ 'dpub-foreword',
|
||||
\ 'dpub-glossary',
|
||||
\ 'dpub-glossdef',
|
||||
\ 'dpub-glossref',
|
||||
\ 'dpub-glossterm',
|
||||
\ 'dpub-index',
|
||||
\ 'dpub-locator',
|
||||
\ 'dpub-noteref',
|
||||
\ 'dpub-notice',
|
||||
\ 'dpub-pagebreak',
|
||||
\ 'dpub-pagelist',
|
||||
\ 'dpub-part',
|
||||
\ 'dpub-preface',
|
||||
\ 'dpub-prologue',
|
||||
\ 'dpub-pullquote',
|
||||
\ 'dpub-qna',
|
||||
\ 'dpub-subtitle',
|
||||
\ 'dpub-tip',
|
||||
\ 'dpub-title',
|
||||
\ 'dpub-toc'
|
||||
\ ]
|
||||
|
||||
let role = extend(widget_role, document_structure)
|
||||
let role = extend(role, landmark_role)
|
||||
let role = extend(role, dpub_role)
|
||||
|
||||
" http://www.w3.org/TR/wai-aria/states_and_properties#state_prop_taxonomy
|
||||
"let global_states_and_properties = {'aria-atomic': ['true', 'false'], 'aria-busy': ['true', 'false'], 'aria-controls': [], 'aria-describedby': [], 'aria-disabled': ['true', 'false'], 'aria-dropeffect': ['copy', 'move', 'link', 'execute', 'popup', 'none'], 'aria-flowto': [], 'aria-grabbed': ['true', 'false', 'undefined'], 'aria-haspopup': ['true', 'false'], 'aria-hidden': ['true', 'false'], 'aria-invalid': ['grammar', 'spelling', 'true', 'false'], 'aria-label': [], 'aria-labelledby': [], 'aria-live': ['off', 'polite', 'assertive'], 'aria-owns': [], 'aria-relevant': ['additions', 'removals', 'text', 'all']}
|
||||
let widget_attributes = {'aria-autocomplete': ['inline', 'list', 'both', 'none'], 'aria-checked': ['true', 'false', 'mixed', 'undefined'], 'aria-disabled': ['true', 'false'], 'aria-expanded': ['true', 'false', 'undefined'], 'aria-haspopup': ['true', 'false'], 'aria-hidden': ['true', 'false'], 'aria-invalid': ['grammar', 'spelling', 'true', 'false'], 'aria-label': [], 'aria-level': [], 'aria-multiline': ['true', 'false'], 'aria-multiselectable': ['true', 'false'], 'aria-orientation': ['horizontal', 'vertical'], 'aria-pressed': ['true', 'false', 'mixed', 'undefined'], 'aria-readonly': ['true', 'false'], 'aria-required': ['true', 'false'], 'aria-selected': ['true', 'false', 'undefined'], 'aria-sort': ['ascending', 'descending', 'none', 'other'], 'aria-valuemax': [], 'aria-valuemin': [], 'aria-valuenow': [], 'aria-valuetext': []}
|
||||
let live_region_attributes = {'aria-atomic': ['true', 'false'], 'aria-busy': ['true', 'false'], 'aria-live': ['off', 'polite', 'assertive'], 'aria-relevant': ['additions', 'removals', 'text', 'all', 'additions text']}
|
||||
let drag_and_drop_attributes = {'aria-dropeffect': ['copy', 'move', 'link', 'execute', 'popup', 'none'], 'aria-grabbed': ['true', 'false', 'undefined']}
|
||||
let relationship_attributes = {'aria-activedescendant': [], 'aria-controls': [], 'aria-describedby': [], 'aria-flowto': [], 'aria-labelledby': [], 'aria-owns': [], 'aria-posinset': [], 'aria-setsize': []}
|
||||
let aria_attributes = widget_attributes
|
||||
" https://www.w3.org/TR/wai-aria-1.1/#states_and_properties
|
||||
let global_states_and_properties = {
|
||||
\ 'aria-atomic': ['true', 'false'],
|
||||
\ 'aria-busy': ['true', 'false'],
|
||||
\ 'aria-controls': [],
|
||||
\ 'aria-current': [],
|
||||
\ 'aria-describedby': [],
|
||||
\ 'aria-disabled': ['true', 'false'],
|
||||
\ 'aria-dropeffect': ['copy', 'move', 'link', 'execute', 'popup', 'none'],
|
||||
\ 'aria-errormessage': [],
|
||||
\ 'aria-flowto': [],
|
||||
\ 'aria-grabbed': ['true', 'false', 'undefined'],
|
||||
\ 'aria-haspopup': ['true', 'false'],
|
||||
\ 'aria-hidden': ['true', 'false'],
|
||||
\ 'aria-invalid': ['grammar', 'spelling', 'true', 'false'],
|
||||
\ 'aria-keyshortcuts': [],
|
||||
\ 'aria-label': [],
|
||||
\ 'aria-labelledby': [],
|
||||
\ 'aria-live': ['off', 'polite', 'assertive'],
|
||||
\ 'aria-owns': [],
|
||||
\ 'aria-relevant': ['additions', 'removals', 'text', 'all'],
|
||||
\ 'aria-roledescription': [],
|
||||
\ }
|
||||
|
||||
let widget_attributes = {
|
||||
\ 'aria-autocomplete': ['inline', 'list', 'both', 'none'],
|
||||
\ 'aria-checked': ['true', 'false', 'mixed', 'undefined'],
|
||||
\ 'aria-disabled': ['true', 'false'],
|
||||
\ 'aria-errormessage': [],
|
||||
\ 'aria-expanded': ['true', 'false', 'undefined'],
|
||||
\ 'aria-haspopup': ['true', 'false'],
|
||||
\ 'aria-hidden': ['true', 'false'],
|
||||
\ 'aria-invalid': ['grammar', 'spelling', 'true', 'false'],
|
||||
\ 'aria-label': [],
|
||||
\ 'aria-level': [],
|
||||
\ 'aria-modal': ['true', 'false'],
|
||||
\ 'aria-multiline': ['true', 'false'],
|
||||
\ 'aria-multiselectable': ['true', 'false'],
|
||||
\ 'aria-orientation': ['horizontal', 'vertical'],
|
||||
\ 'aria-placeholder': [],
|
||||
\ 'aria-pressed': ['true', 'false', 'mixed', 'undefined'],
|
||||
\ 'aria-readonly': ['true', 'false'],
|
||||
\ 'aria-required': ['true', 'false'],
|
||||
\ 'aria-selected': ['true', 'false', 'undefined'],
|
||||
\ 'aria-sort': ['ascending', 'descending', 'none', 'other'],
|
||||
\ 'aria-valuemax': [],
|
||||
\ 'aria-valuemin': [],
|
||||
\ 'aria-valuenow': [],
|
||||
\ 'aria-valuetext': []
|
||||
\ }
|
||||
|
||||
let live_region_attributes = {
|
||||
\ 'aria-atomic': ['true', 'false'],
|
||||
\ 'aria-busy': ['true', 'false'],
|
||||
\ 'aria-live': ['off', 'polite', 'assertive'],
|
||||
\ 'aria-relevant': ['additions', 'removals', 'text', 'all', 'additions text']
|
||||
\ }
|
||||
|
||||
let drag_and_drop_attributes = {
|
||||
\ 'aria-dropeffect': ['copy', 'move', 'link', 'execute', 'popup', 'none'],
|
||||
\ 'aria-grabbed': ['true', 'false', 'undefined']
|
||||
\ }
|
||||
|
||||
let relationship_attributes = {
|
||||
\ 'aria-activedescendant': [],
|
||||
\ 'aria-colcount': [],
|
||||
\ 'aria-colindex': [],
|
||||
\ 'aria-colspan': [],
|
||||
\ 'aria-controls': [],
|
||||
\ 'aria-describedby': [],
|
||||
\ 'aria-details': [],
|
||||
\ 'aria-errormessage': [],
|
||||
\ 'aria-flowto': [],
|
||||
\ 'aria-labelledby': [],
|
||||
\ 'aria-owns': [],
|
||||
\ 'aria-posinset': [],
|
||||
\ 'aria-rowcount': [],
|
||||
\ 'aria-rowindex': [],
|
||||
\ 'aria-rowspan': [],
|
||||
\ 'aria-setsize': []
|
||||
\ }
|
||||
|
||||
let aria_attributes = global_states_and_properties
|
||||
let aria_attributes = extend(aria_attributes, widget_attributes)
|
||||
let aria_attributes = extend(aria_attributes, live_region_attributes)
|
||||
let aria_attributes = extend(aria_attributes, drag_and_drop_attributes)
|
||||
let aria_attributes = extend(aria_attributes, relationship_attributes)
|
||||
@@ -84,6 +271,8 @@ let role_attributes['status'] = abstract_role['composite'] + role_attributes['re
|
||||
let role_attributes['tab'] = abstract_role['sectionhead'] + abstract_role['widget'] + ['aria-selected']
|
||||
let role_attributes['tabpanel'] = role_attributes['region']
|
||||
let role_attributes['textbox'] = abstract_role['input'] + ['aria-autocomplete', 'aria-multiline', 'aria-readonly', 'aria-required']
|
||||
let role_attributes['searchbox'] = role_attributes['textbox']
|
||||
let role_attributes['switch'] = role_attributes['checkbox']
|
||||
let role_attributes['timer'] = role_attributes['status']
|
||||
let role_attributes['tooltip'] = abstract_role['section']
|
||||
let role_attributes['treeitem'] = role_attributes['listitem'] + role_attributes['option']
|
||||
@@ -101,16 +290,22 @@ let role_attributes['treegrid'] = role_attributes['grid'] + role_attributes['tre
|
||||
let role_attributes['document'] = abstract_role['structure'] + ['aria-expanded']
|
||||
|
||||
let role_attributes['article'] = role_attributes['document'] + role_attributes['region']
|
||||
let role_attributes['cell'] = abstract_role['section'] + ['aria-colindex', 'aria-colspan', 'aria-rowindex', 'aria-rowspan']
|
||||
let role_attributes['columnheader'] = role_attributes['gridcell'] + abstract_role['sectionhead'] + ['aria-sort']
|
||||
let role_attributes['definition'] = abstract_role['section']
|
||||
let role_attributes['feed'] = role_attributes['list']
|
||||
let role_attributes['figure'] = abstract_role['section']
|
||||
let role_attributes['heading'] = abstract_role['sectionhead'] + ['aria-level']
|
||||
let role_attributes['img'] = abstract_role['section']
|
||||
let role_attributes['math'] = abstract_role['section']
|
||||
let role_attributes['note'] = abstract_role['section']
|
||||
let role_attributes['presentation'] = abstract_role['structure']
|
||||
let role_attributes['none'] = role_attributes['presentation']
|
||||
let role_attributes['row'] = role_attributes['group'] + ['aria-level', 'aria-selected']
|
||||
let role_attributes['rowheader'] = role_attributes['gridcell'] + abstract_role['sectionhead']
|
||||
let role_attributes['separator'] = abstract_role['structure'] + ['aria-expanded']
|
||||
let role_attributes['table'] = abstract_role['section'] + ['aria-colcount', 'aria-rowcount']
|
||||
let role_attributes['term'] = abstract_role['section']
|
||||
|
||||
" Landmark Roles
|
||||
let role_attributes['application'] = abstract_role['landmark']
|
||||
@@ -126,19 +321,30 @@ let role_attributes['search'] = abstract_role['landmark']
|
||||
let aria_attributes_value = {
|
||||
\ 'aria-autocomplete': ['ID', ''],
|
||||
\ 'aria-checked': ['Token', ''],
|
||||
\ 'aria-colcount': ['Number', ''],
|
||||
\ 'aria-colindex': ['Number', ''],
|
||||
\ 'aria-colspan': ['Number', ''],
|
||||
\ 'aria-disabled': ['true/false', ''],
|
||||
\ 'aria-errormessage': ['ID', ''],
|
||||
\ 'aria-expanded': ['Token', ''],
|
||||
\ 'aria-haspopup': ['true/false', ''],
|
||||
\ 'aria-haspopup': ['Token', ''],
|
||||
\ 'aria-hidden': ['true/false', ''],
|
||||
\ 'aria-invalid': ['Token', ''],
|
||||
\ 'aria-keyshortcuts': ['String', ''],
|
||||
\ 'aria-label': ['String', ''],
|
||||
\ 'aria-level': ['Int', ''],
|
||||
\ 'aria-modal': ['true/false', ''],
|
||||
\ 'aria-multiline': ['true/false', ''],
|
||||
\ 'aria-multiselectable': ['true/false', ''],
|
||||
\ 'aria-orientation': ['Token', ''],
|
||||
\ 'aria-placeholder': ['String', ''],
|
||||
\ 'aria-pressed': ['Token', ''],
|
||||
\ 'aria-readonly': ['true/false', ''],
|
||||
\ 'aria-required': ['true/false', ''],
|
||||
\ 'aria-roledescription': ['String', ''],
|
||||
\ 'aria-rowcount': ['Number', ''],
|
||||
\ 'aria-rowindex': ['Number', ''],
|
||||
\ 'aria-rowspan': ['Number', ''],
|
||||
\ 'aria-selected': ['Token', ''],
|
||||
\ 'aria-sort': ['Token', ''],
|
||||
\ 'aria-valuemax': ['Number', ''],
|
||||
|
||||
@@ -80,6 +80,9 @@ let attributes_value = {
|
||||
\ 'accept-charset': ['Charset', ''],
|
||||
\ 'accesskey': ['Character', ''],
|
||||
\ 'action': ['URL', ''],
|
||||
\ 'allowfullscreen': ['Bool', ''],
|
||||
\ 'allowpaymentrequest': ['Bool', ''],
|
||||
\ 'allowusermedia': ['Bool', ''],
|
||||
\ 'alt': ['Text', ''],
|
||||
\ 'async': ['Bool', ''],
|
||||
\ 'autocomplete': ['*Token', ''],
|
||||
@@ -142,6 +145,7 @@ let attributes_value = {
|
||||
\ 'optimum': ['Number', ''],
|
||||
\ 'pattern': ['Pattern', ''],
|
||||
\ 'placeholder': ['Text', ''],
|
||||
\ 'playsinline': ['Bool', ''],
|
||||
\ 'poster': ['URL', ''],
|
||||
\ 'preload': ['Token', ''],
|
||||
\ 'pubdate': ['Bool', ''],
|
||||
@@ -315,10 +319,10 @@ if !exists('g:html5_aria_attributes_complete')
|
||||
let g:html5_aria_attributes_complete = 1
|
||||
endif
|
||||
if g:html5_aria_attributes_complete == 1
|
||||
" Ref: http://www.w3.org/TR/wai-aria/roles
|
||||
" Version: Draft 15 December 2009
|
||||
let widget_role = ['alert', 'alertdialog', 'button', 'checkbox', 'combobox', 'dialog', 'gridcell', 'link', 'log', 'marquee', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'option', 'progressbar', 'radio', 'radiogroup', 'scrollbar', 'slider', 'spinbutton', 'status', 'tab', 'tabpanel', 'textbox', 'timer', 'tooltip', 'treeitem', 'combobox', 'grid', 'listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid']
|
||||
let document_structure = ['article', 'columnheader', 'definition', 'directory', 'document', 'group', 'heading', 'img', 'list', 'listitem', 'math', 'note', 'presentation', 'region', 'row', 'rowheader', 'separator']
|
||||
" Ref: https://www.w3.org/TR/wai-aria-1.1/#role_definitions
|
||||
" Version: W3C Candidate Recommendation 27 October 2016
|
||||
let widget_role = ['alert', 'alertdialog', 'button', 'checkbox', 'combobox', 'dialog', 'gridcell', 'link', 'log', 'marquee', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'option', 'progressbar', 'radio', 'radiogroup', 'scrollbar', 'searchbox', 'slider', 'spinbutton', 'status', 'switch', 'tab', 'tabpanel', 'textbox', 'timer', 'tooltip', 'treeitem', 'combobox', 'grid', 'listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid']
|
||||
let document_structure = ['article', 'cell', 'columnheader', 'definition', 'directory', 'document', 'feed', 'figure', 'group', 'heading', 'img', 'list', 'listitem', 'math', 'none', 'note', 'presentation', 'region', 'row', 'rowheader', 'separator', 'table', 'term']
|
||||
let landmark_role = ['application', 'banner', 'complementary', 'contentinfo', 'form', 'main', 'navigation', 'search']
|
||||
let dpub_role = ['dpub-abstract', 'dpub-afterword', 'dpub-appendix', 'dpub-biblioentry', 'dpub-bibliography', 'dpub-biblioref', 'dpub-chapter', 'dpub-cover', 'dpub-epilogue', 'dpub-footnote', 'dpub-footnotes', 'dpub-foreword', 'dpub-glossary', 'dpub-glossdef', 'dpub-glossref', 'dpub-glossterm', 'dpub-index', 'dpub-locator', 'dpub-noteref', 'dpub-notice', 'dpub-pagebreak', 'dpub-pagelist', 'dpub-part', 'dpub-preface', 'dpub-prologue', 'dpub-pullquote', 'dpub-qna', 'dpub-subtitle', 'dpub-tip', 'dpub-title', 'dpub-toc']
|
||||
let role = extend(widget_role, document_structure)
|
||||
@@ -336,14 +340,38 @@ let metadata_elements = ['link', 'style', 'meta', 'script', 'noscript', 'command
|
||||
|
||||
let flow_elements = phrasing_elements + ['p', 'hr', 'pre', 'ul', 'ol', 'dl', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup', 'address', 'blockquote', 'ins', 'del', 'element', 'object', 'main', 'map', 'noscript', 'section', 'nav', 'article', 'aside', 'header', 'footer', 'video', 'audio', 'figure', 'table', 'template', 'form', 'fieldset', 'menu', 'canvas', 'details']
|
||||
|
||||
" http://dev.w3.org/html5/spec/Overview.html#linkTypes
|
||||
let linktypes = ['alternate', 'author', 'bookmark', 'external', 'help', 'icon', 'license', 'next', 'nofollow', 'noreferrer', 'pingback', 'prefetch', 'prev', 'search', 'stylesheet', 'sidebar', 'tag']
|
||||
" https://html.spec.whatwg.org/#linkTypes
|
||||
let linktypes = ['alternate', 'author', 'bookmark', 'dns-prefetch', 'external', 'help', 'icon', 'license', 'next', 'nofollow', 'noreferrer', 'noopener', 'pingback', 'preconnect', 'prefetch', 'preload', 'prerender', 'prev', 'search', 'stylesheet', 'tag']
|
||||
" https://w3c.github.io/manifest/
|
||||
let linkreltypes = linktypes
|
||||
let linkreltypes = linkreltypes + ['manifest']
|
||||
" http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
|
||||
let linkreltypes = linktypes + ['canonical', 'import']
|
||||
" http://www.ysearchblog.com/2009/02/12/fighting-duplication-adding-more-arrows-to-your-quiver/
|
||||
" http://blogs.bing.com/webmaster/2009/02/12/partnering-to-help-solve-duplicate-content-issues
|
||||
let linkreltypes = linkreltypes + ['canonical']
|
||||
" http://w3c.github.io/webcomponents/spec/imports/
|
||||
let linkreltypes = linkreltypes + ['import']
|
||||
" https://www.w3.org/TR/webmention/#sender-discovers-receiver-webmention-endpoint
|
||||
let linkreltypes = linkreltypes + ['webmention']
|
||||
" http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML
|
||||
let linkreltypes = linkreltypes + ['search']
|
||||
" http://microformats.org/wiki/rel-sitemap
|
||||
let linkreltypes = linkreltypes + ['sitemap']
|
||||
" https://www.ampproject.org/docs/get_started/create/prepare_for_discovery
|
||||
let linkreltypes = linkreltypes + ['amphtml']
|
||||
" https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
|
||||
let linkreltypes = linkreltypes + ['apple-touch-icon', 'apple-touch-icon-precomposed', 'apple-touch-startup-image']
|
||||
" https://developer.chrome.com/webstore/inline_installation
|
||||
let linkreltypes = linkreltypes + ['chrome-webstore-item']
|
||||
" http://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html#rfc.section.4
|
||||
let linkreltypes = linkreltypes + ['hub']
|
||||
" https://golem.ph.utexas.edu/~distler/blog/archives/000320.html
|
||||
let linkreltypes = linkreltypes + ['pgpkey']
|
||||
|
||||
" a and button are special elements for interactive, some element can't be its descendent
|
||||
let abutton_dec = 'details\\|embed\\|iframe\\|keygen\\|label\\|menu\\|select\\|textarea'
|
||||
|
||||
let crossorigin = ['anonymous', 'use-credentials']
|
||||
|
||||
|
||||
let g:xmldata_html5 = {
|
||||
@@ -551,15 +579,15 @@ let g:xmldata_html5 = {
|
||||
\ ],
|
||||
\ 'iframe': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'src': [], 'srcdoc': [], 'name': [], 'width': [], 'height': [], 'sandbox': ['allow-same-origin', 'allow-forms', 'allow-scripts'], 'seamless': ['seamless', ''], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url']})
|
||||
\ extend(copy(global_attributes), {'src': [], 'srcdoc': [], 'name': [], 'width': [], 'height': [], 'sandbox': ['allow-same-origin', 'allow-forms', 'allow-scripts'], 'seamless': ['seamless', ''], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url'], 'allowfullscreen': [], 'allowpaymentrequest': [], 'allowusermedia': []})
|
||||
\ ],
|
||||
\ 'img': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'src': [], 'alt': [], 'height': [], 'width': [], 'usemap': [], 'ismap': ['ismap', ''], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url']})
|
||||
\ extend(copy(global_attributes), {'src': [], 'alt': [], 'height': [], 'width': [], 'decoding': ['async', 'sync', 'auto'], 'usemap': [], 'ismap': ['ismap', ''], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url'], 'crossorigin': ['anonymous', 'use-credentials']})
|
||||
\ ],
|
||||
\ 'input': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']})
|
||||
\ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']})
|
||||
\ ],
|
||||
\ 'ins': [
|
||||
\ flow_elements,
|
||||
@@ -587,7 +615,7 @@ let g:xmldata_html5 = {
|
||||
\ ],
|
||||
\ 'link': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'href': [], 'rel': linkreltypes, 'hreflang': lang_tag, 'media': [], 'type': [], 'sizes': ['any'], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url']})
|
||||
\ extend(copy(global_attributes), {'href': [], 'rel': linkreltypes, 'hreflang': lang_tag, 'media': [], 'type': [], 'sizes': ['any'], 'referrerpolicy': ['no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-cross-origin', 'unsafe-url'], 'crossorigin': crossorigin, 'preload': ['preload', ''], 'prefetch': ['prefetch', '']})
|
||||
\ ],
|
||||
\ 'main': [
|
||||
\ flow_elements + ['style'],
|
||||
@@ -695,7 +723,7 @@ let g:xmldata_html5 = {
|
||||
\ ],
|
||||
\ 'script': [
|
||||
\ [],
|
||||
\ extend(copy(global_attributes), {'src': [], 'defer': ['defer', ''], 'async': ['async', ''], 'type': [], 'charset': charset, 'nonce': []})
|
||||
\ extend(copy(global_attributes), {'src': [], 'defer': ['defer', ''], 'async': ['async', ''], 'type': [], 'charset': charset, 'nonce': [], 'crossorigin': crossorigin})
|
||||
\ ],
|
||||
\ 'section': [
|
||||
\ flow_elements + ['style'],
|
||||
@@ -807,7 +835,7 @@ let g:xmldata_html5 = {
|
||||
\ ],
|
||||
\ 'video': [
|
||||
\ flow_elements + ['source', 'track'],
|
||||
\ extend(copy(global_attributes), {'autoplay': ['autoplay', ''], 'preload': ['none', 'metadata', 'auto', ''], 'controls': ['controls', ''], 'loop': ['loop', ''], 'poster': [], 'height': [], 'width': [], 'src': []})
|
||||
\ extend(copy(global_attributes), {'autoplay': ['autoplay', ''], 'preload': ['none', 'metadata', 'auto', ''], 'controls': ['controls', ''], 'loop': ['loop', ''], 'playsinline': ['playsinline', ''], 'poster': [], 'height': [], 'width': [], 'src': [], 'crossorigin': crossorigin})
|
||||
\ ],
|
||||
\ 'wbr': [
|
||||
\ [],
|
||||
|
||||
65
build
65
build
@@ -2,10 +2,10 @@
|
||||
|
||||
set -E
|
||||
|
||||
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_ALL="syntax indent compiler autoload ftplugin ftdetect after"
|
||||
DIRS_SYNTAX="syntax ftdetect after/syntax after/ftdetect"
|
||||
DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin"
|
||||
DIRS_BASIC="syntax compiler indent after/syntax after/indent"
|
||||
DIRS_ALL="syntax indent compiler autoload ftplugin after"
|
||||
DIRS_SYNTAX="syntax after/syntax"
|
||||
DIRS_JAVASCRIPT="${DIRS} extras"
|
||||
DIRS_RM="$DIRS_JAVASCRIPT"
|
||||
|
||||
@@ -29,6 +29,9 @@ download() {
|
||||
|
||||
extract() {
|
||||
printf "\n"
|
||||
|
||||
cat config.vim >> tmp/polyglot.vim
|
||||
|
||||
for pack in $1; do
|
||||
name="$(printf "$pack" | cut -d ':' -f 1)"
|
||||
path="$(printf "$pack" | cut -d ':' -f 2)"
|
||||
@@ -49,10 +52,21 @@ extract() {
|
||||
fi
|
||||
done
|
||||
|
||||
for f in ${dir}/ftdetect/*; do
|
||||
(
|
||||
echo "augroup filetypedetect";
|
||||
echo '" '"$pack";
|
||||
cat "${f}";
|
||||
echo "augroup END";
|
||||
echo
|
||||
) >> tmp/polyglot.vim;
|
||||
done
|
||||
|
||||
output "${subdirs##, })\n"
|
||||
done
|
||||
|
||||
mv tmp/polyglot.vim ftdetect/
|
||||
|
||||
for pack in $1; do
|
||||
name="$(printf "$pack" | cut -d ':' -f 1)"
|
||||
path="$(printf "$pack" | cut -d ':' -f 2)"
|
||||
@@ -76,15 +90,6 @@ copy_dir() {
|
||||
done
|
||||
}
|
||||
|
||||
concat_ftdetect() {
|
||||
echo "augroup filetypedetect" > tmp/polyglot.vim
|
||||
cat config.vim >> tmp/polyglot.vim
|
||||
for f in ftdetect/*; do (echo '" '"$f"; cat "${f}"; echo) >> tmp/polyglot.vim; done
|
||||
echo "augroup END" >> tmp/polyglot.vim
|
||||
rm -f ftdetect/*
|
||||
mv tmp/polyglot.vim ftdetect/
|
||||
}
|
||||
|
||||
update_readme() {
|
||||
OLD_README="$(cat README.md)"
|
||||
|
||||
@@ -93,7 +98,7 @@ update_readme() {
|
||||
+2kb
|
||||
/##
|
||||
'b,-2c
|
||||
$(printf -- "$OUTPUT")
|
||||
$(printf -- "$OUTPUT" | sort)
|
||||
.
|
||||
w
|
||||
q
|
||||
@@ -102,30 +107,38 @@ EOF
|
||||
}
|
||||
|
||||
PACKS="
|
||||
apiblueprint:sheerun/apiblueprint.vim
|
||||
applescript:vim-scripts/applescript.vim
|
||||
asciidoc:asciidoc/vim-asciidoc
|
||||
yaml:stephpy/vim-yaml
|
||||
ansible:pearofducks/ansible-vim
|
||||
arduino:sudar/vim-arduino-syntax
|
||||
autohotkey:hnamikaw/vim-autohotkey
|
||||
blade:jwalton512/vim-blade
|
||||
c++11:octol/vim-cpp-enhanced-highlight
|
||||
c/c++:vim-jp/vim-cpp
|
||||
caddyfile:isobit/vim-caddyfile
|
||||
cjsx:mtscout6/vim-cjsx
|
||||
clojure:guns/vim-clojure-static
|
||||
cmake:pboettch/vim-cmake-syntax
|
||||
coffee-script:kchmck/vim-coffee-script
|
||||
cryptol:victoredwardocallaghan/cryptol.vim
|
||||
crystal:rhysd/vim-crystal
|
||||
cql:elubow/cql-vim
|
||||
css:JulesWang/css.vim
|
||||
cucumber:tpope/vim-cucumber
|
||||
dart:dart-lang/dart-vim-plugin
|
||||
dockerfile:honza/dockerfile.vim
|
||||
dockerfile:docker/docker::/contrib/syntax/vim/
|
||||
elixir:elixir-lang/vim-elixir
|
||||
elm:lambdatoast/elm.vim
|
||||
elm:ElmCast/elm-vim
|
||||
emberscript:yalesov/vim-ember-script
|
||||
emblem:yalesov/vim-emblem
|
||||
erlang:vim-erlang/vim-erlang-runtime
|
||||
fish:dag/vim-fish
|
||||
fsharp:fsharp/vim-fsharp:_BASIC
|
||||
git:tpope/vim-git
|
||||
gmpl:maelvalais/gmpl.vim
|
||||
glsl:tikhomirov/vim-glsl
|
||||
gnuplot:vim-scripts/gnuplot-syntax-highlighting
|
||||
go:fatih/vim-go:_BASIC
|
||||
groovy:vim-scripts/groovy.vim
|
||||
haml:sheerun/vim-haml
|
||||
@@ -136,10 +149,11 @@ PACKS="
|
||||
i3:PotatoesMaster/i3-vim-syntax
|
||||
jasmine:glanotte/vim-jasmine
|
||||
javascript:pangloss/vim-javascript:_JAVASCRIPT
|
||||
jenkins:martinda/Jenkinsfile-vim-syntax
|
||||
json:elzr/vim-json
|
||||
jst:briancollins/vim-jst
|
||||
jsx:mxw/vim-jsx:_ALL
|
||||
julia:dcjones/julia-minimalist-vim
|
||||
julia:JuliaEditorSupport/julia-vim
|
||||
kotlin:udalov/kotlin-vim
|
||||
latex:LaTeX-Box-Team/LaTeX-Box
|
||||
less:groenewege/vim-less
|
||||
@@ -148,9 +162,10 @@ PACKS="
|
||||
lua:tbastos/vim-lua
|
||||
mako:sophacles/vim-bundle-mako
|
||||
markdown:plasticboy/vim-markdown:_SYNTAX
|
||||
nginx:othree/nginx-contrib-vim
|
||||
mathematica:rsmenon/vim-mathematica
|
||||
nginx:chr4/nginx.vim
|
||||
nim:zah/nim.vim:_BASIC
|
||||
nix:spwhitt/vim-nix
|
||||
nix:LnL7/vim-nix
|
||||
objc:b4winckler/vim-objc
|
||||
ocaml:jrk/vim-ocaml
|
||||
octave:vim-scripts/octave.vim--
|
||||
@@ -163,11 +178,12 @@ PACKS="
|
||||
protobuf:uarun/vim-protobuf
|
||||
pug:digitaltoad/vim-pug
|
||||
puppet:voxpupuli/vim-puppet
|
||||
purescript:raichoo/purescript-vim
|
||||
purescript:purescript-contrib/purescript-vim
|
||||
python:mitsuhiko/vim-python-combined
|
||||
python-compiler:aliev/vim-compiler-python
|
||||
qml:peterhoeg/vim-qml
|
||||
r-lang:vim-scripts/R.vim
|
||||
racket:wlangstroth/vim-racket
|
||||
raml:IN3D/vim-raml
|
||||
ragel:jneen/ragel.vim
|
||||
rspec:sheerun/rspec.vim
|
||||
@@ -177,9 +193,11 @@ PACKS="
|
||||
scala:derekwyatt/vim-scala
|
||||
scss:cakebaker/scss-syntax.vim
|
||||
slim:slim-template/vim-slim
|
||||
solidity:ethereum/vim-solidity
|
||||
slime:slime-lang/vim-slime-syntax
|
||||
solidity:tomlion/vim-solidity
|
||||
stylus:wavded/vim-stylus
|
||||
swift:keith/swift.vim
|
||||
sxhkd:baskerville/vim-sxhkdrc
|
||||
systemd:kurayama/systemd-vim-syntax
|
||||
terraform:hashivim/vim-terraform
|
||||
textile:timcharper/textile.vim
|
||||
@@ -192,10 +210,10 @@ PACKS="
|
||||
vala:arrufat/vala.vim
|
||||
vbnet:vim-scripts/vbnet.vim
|
||||
vcl:smerrill/vcl-vim-plugin
|
||||
vifm:vifm/vifm.vim
|
||||
vue:posva/vim-vue
|
||||
vm:lepture/vim-velocity
|
||||
xls:vim-scripts/XSLT-syntax
|
||||
yaml:stephpy/vim-yaml
|
||||
yard:sheerun/vim-yardoc
|
||||
"
|
||||
|
||||
@@ -206,7 +224,6 @@ mkdir tmp
|
||||
printf "Downloading packs..."
|
||||
download "$PACKS"
|
||||
extract "$PACKS"
|
||||
concat_ftdetect
|
||||
update_readme
|
||||
|
||||
rm -rf tmp
|
||||
|
||||
@@ -4,6 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
" Compiler: Cargo Compiler
|
||||
" Maintainer: Damien Radtke <damienradtke@gmail.com>
|
||||
" Latest Revision: 2014 Sep 24
|
||||
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
|
||||
|
||||
if exists('current_compiler')
|
||||
finish
|
||||
@@ -11,6 +12,9 @@ endif
|
||||
runtime compiler/rustc.vim
|
||||
let current_compiler = "cargo"
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists(':CompilerSet') != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
@@ -27,6 +31,11 @@ CompilerSet errorformat+=
|
||||
\%-G%\\s%#Compiling%.%#,
|
||||
\%-G%\\s%#Finished%.%#,
|
||||
\%-G%\\s%#error:\ Could\ not\ compile\ %.%#,
|
||||
\%-G%\\s%#To\ learn\ more\\,%.%#
|
||||
\%-G%\\s%#To\ learn\ more\\,%.%#,
|
||||
\%-Gnote:\ Run\ with\ \`RUST_BACKTRACE=%.%#,
|
||||
\%.%#panicked\ at\ \\'%m\\'\\,\ %f:%l
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1
|
||||
|
||||
" Vim compiler plugin
|
||||
" Language: JavaScript
|
||||
" Maintainer: vim-javascript community
|
||||
" URL: https://github.com/pangloss/vim-javascript
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
endif
|
||||
|
||||
@@ -6,10 +6,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
|
||||
"
|
||||
" compiler/go.vim: Vim compiler file for Go.
|
||||
|
||||
if exists("current_compiler")
|
||||
if exists("g:current_compiler")
|
||||
finish
|
||||
endif
|
||||
let current_compiler = "go"
|
||||
let g:current_compiler = "go"
|
||||
|
||||
if exists(":CompilerSet") != 2
|
||||
command -nargs=* CompilerSet setlocal <args>
|
||||
|
||||
@@ -24,10 +24,10 @@ CompilerSet errorformat=
|
||||
\%D(in\ %f),
|
||||
\%\\s%#from\ %f:%l:%m,
|
||||
\%\\s%#from\ %f:%l:,
|
||||
\%\\s%##\ %f:%l:%m,
|
||||
\%\\s%##\ %f:%l,
|
||||
\%\\s%#[%f:%l:\ %#%m,
|
||||
\%\\s%#%f:%l:\ %#%m,
|
||||
\%\\s%##\ %f:%l:%m%\\&%.%#%\\D:%\\d%#:%.%#,
|
||||
\%\\s%##\ %f:%l%\\&%.%#%\\D:%\\d%#,
|
||||
\%\\s%#[%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%#:%.%#,
|
||||
\%\\s%#%f:%l:\ %#%m%\\&%.%#%\\D:%\\d%#:%.%#,
|
||||
\%\\s%#%f:%l:,
|
||||
\%m\ [%f:%l]:,
|
||||
\%+Erake\ aborted!,
|
||||
|
||||
@@ -4,6 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
" Compiler: Rust Compiler
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Latest Revision: 2013 Jul 12
|
||||
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
|
||||
|
||||
if exists("current_compiler")
|
||||
finish
|
||||
|
||||
@@ -17,8 +17,18 @@ if exists(":CompilerSet") != 2
|
||||
command! -nargs=* CompilerSet setlocal <args>
|
||||
endif
|
||||
|
||||
let &l:makeprg = g:typescript_compiler_binary . ' ' . g:typescript_compiler_options . ' $* %'
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
execute 'CompilerSet makeprg='
|
||||
\ . escape(g:typescript_compiler_binary, ' ')
|
||||
\ . '\ '
|
||||
\ . escape(g:typescript_compiler_options, ' ')
|
||||
\ . '\ $*\ %'
|
||||
|
||||
CompilerSet errorformat=%+A\ %#%f\ %#(%l\\\,%c):\ %m,%C%m
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
endif
|
||||
|
||||
@@ -9,3 +9,7 @@ if !exists('g:vim_json_syntax_conceal')
|
||||
endif
|
||||
|
||||
let g:filetype_euphoria = 'elixir'
|
||||
|
||||
augroup filetypedetect
|
||||
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
||||
augroup END
|
||||
|
||||
@@ -2,9 +2,10 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') ==
|
||||
|
||||
syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen
|
||||
syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\|=>\@!\)\@=/ contains=@jsFlowCluster
|
||||
syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster
|
||||
syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster
|
||||
syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster
|
||||
syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster,jsComment fold
|
||||
syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster,jsComment fold
|
||||
syntax region jsFlowExactObject contained matchgroup=jsFlowNoise start=/{|/ end=/|}/ contains=@jsFlowCluster,jsComment fold
|
||||
syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster keepend fold
|
||||
syntax match jsFlowNoise contained /[:;,<>]/
|
||||
syntax keyword jsFlowType contained boolean number string null void any mixed JSON array Function object array bool class
|
||||
syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType
|
||||
@@ -12,18 +13,18 @@ syntax match jsFlowTypeCustom contained /[0-9a-zA-Z_.]*/ skipwhite skipemp
|
||||
syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster
|
||||
syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster
|
||||
syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens
|
||||
syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject
|
||||
syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject
|
||||
syntax match jsFlowOrOperator contained /|/ skipwhite skipempty nextgroup=@jsFlowCluster
|
||||
syntax keyword jsFlowImportType contained type skipwhite skipempty nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup
|
||||
syntax match jsFlowWildcard contained /*/
|
||||
|
||||
syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster
|
||||
syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp
|
||||
syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp
|
||||
syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp
|
||||
syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster,jsFlowArrow,jsFlowReturnParens
|
||||
syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold
|
||||
syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold
|
||||
syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp,jsFlowReturnArrow fold
|
||||
syntax match jsFlowReturnArrow contained /=>/ skipwhite skipempty nextgroup=@jsFlowReturnCluster
|
||||
syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock,jsFlowReturnOrOp
|
||||
syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword
|
||||
syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword,jsFlowReturnObject
|
||||
syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp
|
||||
syntax match jsFlowReturnOrOp contained /\s*|\s*/ skipwhite skipempty nextgroup=@jsFlowReturnCluster
|
||||
syntax match jsFlowWildcardReturn contained /*/ skipwhite skipempty nextgroup=jsFuncBlock
|
||||
@@ -32,7 +33,8 @@ syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=/</ e
|
||||
syntax region jsFlowClassGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock
|
||||
|
||||
syntax region jsFlowTypeStatement start=/type\%(\s\+\k\)\@=/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend
|
||||
syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression,jsFlowGroup,jsFlowMaybe
|
||||
syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/=/ end=/[\n;]/ contains=@jsFlowCluster,jsFlowGroup,jsFlowMaybe
|
||||
syntax match jsFlowTypeOperator contained /=/ containedin=jsFlowTypeValue
|
||||
syntax match jsFlowTypeOperator contained /=/
|
||||
syntax keyword jsFlowTypeKeyword contained type
|
||||
|
||||
@@ -42,12 +44,18 @@ syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\)
|
||||
|
||||
syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString
|
||||
syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster
|
||||
syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise
|
||||
syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise fold
|
||||
|
||||
syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend
|
||||
" NOTE: It appears the nextgroup was causing a ton of breakages... testing it
|
||||
" witout a nextgroup, but keeping this arround for reference incase something breaks
|
||||
" syntax match jsFlowMaybe contained /?/ nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject extend keepend
|
||||
syntax match jsFlowMaybe contained /?/
|
||||
syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend fold
|
||||
|
||||
syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn
|
||||
syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard
|
||||
syntax region jsFlowParenAnnotation contained start=/:/ end=/[,=)]\@=/ containedin=jsParen contains=@jsFlowCluster
|
||||
|
||||
syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn,jsFlowReturnArrow
|
||||
syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowExactObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard
|
||||
|
||||
if version >= 508 || !exists("did_javascript_syn_inits")
|
||||
if version < 508
|
||||
@@ -64,9 +72,11 @@ if version >= 508 || !exists("did_javascript_syn_inits")
|
||||
HiLink jsFlowTypeof PreProc
|
||||
HiLink jsFlowArray PreProc
|
||||
HiLink jsFlowObject PreProc
|
||||
HiLink jsFlowExactObject PreProc
|
||||
HiLink jsFlowParens PreProc
|
||||
HiLink jsFlowGroup PreProc
|
||||
HiLink jsFlowReturn PreProc
|
||||
HiLink jsFlowParenAnnotation PreProc
|
||||
HiLink jsFlowReturnObject jsFlowReturn
|
||||
HiLink jsFlowReturnArray jsFlowArray
|
||||
HiLink jsFlowReturnParens jsFlowParens
|
||||
@@ -75,9 +85,10 @@ if version >= 508 || !exists("did_javascript_syn_inits")
|
||||
HiLink jsFlowClassGroup PreProc
|
||||
HiLink jsFlowArrowArguments PreProc
|
||||
HiLink jsFlowArrow PreProc
|
||||
HiLink jsFlowReturnArrow PreProc
|
||||
HiLink jsFlowTypeStatement PreProc
|
||||
HiLink jsFlowTypeKeyword PreProc
|
||||
HiLink jsFlowTypeOperator PreProc
|
||||
HiLink jsFlowTypeOperator Operator
|
||||
HiLink jsFlowMaybe PreProc
|
||||
HiLink jsFlowReturnMaybe PreProc
|
||||
HiLink jsFlowClassProperty jsClassProperty
|
||||
@@ -86,10 +97,12 @@ if version >= 508 || !exists("did_javascript_syn_inits")
|
||||
HiLink jsFlowInterface PreProc
|
||||
HiLink jsFlowNoise Noise
|
||||
HiLink jsFlowObjectKey jsObjectKey
|
||||
HiLink jsFlowOrOperator PreProc
|
||||
HiLink jsFlowOrOperator jsOperator
|
||||
HiLink jsFlowReturnOrOp jsFlowOrOperator
|
||||
HiLink jsFlowWildcard PreProc
|
||||
HiLink jsFlowWildcardReturn PreProc
|
||||
HiLink jsFlowImportType PreProc
|
||||
HiLink jsFlowTypeValue PreProc
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|
|
||||
" tags containing references
|
||||
syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag
|
||||
" other tags (no extra syntax)
|
||||
syntax match jsDocTags contained "@\(abstract\|access\|accessor\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>"
|
||||
syntax match jsDocTags contained "@\(abstract\|access\|accessor\|async\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>"
|
||||
|
||||
syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam
|
||||
syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,8 @@ 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\)\>' .
|
||||
\ '@\%(section\s*([^\,]*)\|if\|unless\|foreach\|forelse\|for\|while\|push\|can\|cannot\|hasSection\|' .
|
||||
\ 'php\s*(\@!\|verbatim\|component\|slot\|prepend\)' .
|
||||
\ ':' .
|
||||
\ '@\%(else\|elseif\|empty\|break\|continue\|elsecan\|elsecannot\)\>' .
|
||||
\ ':' .
|
||||
|
||||
28
ftplugin/caddyfile.vim
Normal file
28
ftplugin/caddyfile.vim
Normal file
@@ -0,0 +1,28 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1
|
||||
|
||||
" Language: Caddyfile
|
||||
" Author: Josh Glendenning <josh@isobit.io>
|
||||
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
" Add NERDCommenter delimiters
|
||||
let s:delimiters = {'left': '#'}
|
||||
if exists('g:NERDDelimiterMap')
|
||||
if !has_key(g:NERDDelimiterMap, 'caddyfile')
|
||||
let g:NERDDelimiterMap.caddyfile = s:delimiters
|
||||
endif
|
||||
elseif exists('g:NERDCustomDelimiters')
|
||||
if !has_key(g:NERDCustomDelimiters, 'caddyfile')
|
||||
let g:NERDDelimiterMap.caddyfile = s:delimiters
|
||||
endif
|
||||
else
|
||||
let g:NERDCustomDelimiters = {'caddyfile': s:delimiters}
|
||||
endif
|
||||
unlet s:delimiters
|
||||
|
||||
endif
|
||||
@@ -25,7 +25,9 @@ let &l:errorformat =
|
||||
\ '%m'
|
||||
\ ], ',')
|
||||
|
||||
setlocal includeexpr=dart#resolveUri(v:fname)
|
||||
setlocal isfname+=:
|
||||
|
||||
let b:undo_ftplugin = 'setl et< fo< sw< sts< com< cms<'
|
||||
let b:undo_ftplugin = 'setl et< fo< sw< sts< com< cms< inex< isf<'
|
||||
|
||||
endif
|
||||
|
||||
@@ -16,7 +16,7 @@ if !exists("g:eelixir_default_subtype")
|
||||
endif
|
||||
|
||||
if !exists("b:eelixir_subtype")
|
||||
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
|
||||
let s:lines = join(getline(1, 5) + [getline('$')], "\n")
|
||||
let b:eelixir_subtype = matchstr(s:lines,'eelixir_subtype=\zs\w\+')
|
||||
if b:eelixir_subtype == ''
|
||||
let b:eelixir_subtype = matchstr(&filetype,'^eex\.\zs\w\+')
|
||||
@@ -100,7 +100,7 @@ endif
|
||||
setlocal comments=:<%#
|
||||
setlocal commentstring=<%#\ %s\ %>
|
||||
|
||||
let b:undo_ftplugin = "setl cms< "
|
||||
let b:undo_ftplugin = "setl cms< " .
|
||||
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
@@ -17,45 +17,24 @@ if exists("loaded_matchit") && !exists("b:match_words")
|
||||
\ ',{:},\[:\],(:)'
|
||||
endif
|
||||
|
||||
setlocal shiftwidth=2 softtabstop=2 expandtab iskeyword+=!,?
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
function! GetElixirFilename(word)
|
||||
let word = a:word
|
||||
|
||||
" get first thing that starts uppercase, until the first space or end of line
|
||||
let word = substitute(word,'^\s*\(\u[^ ]\+\).*$','\1','g')
|
||||
|
||||
" remove any trailing characters that don't look like a nested module
|
||||
let word = substitute(word,'\.\U.*$','','g')
|
||||
|
||||
" replace module dots with slash
|
||||
let word = substitute(word,'\.','/','g')
|
||||
|
||||
" remove any special chars
|
||||
let word = substitute(word,'[^A-z0-9-_/]','','g')
|
||||
|
||||
" convert to snake_case
|
||||
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
||||
let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g')
|
||||
let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g')
|
||||
let word = substitute(word,'-','_','g')
|
||||
let word = tolower(word)
|
||||
|
||||
return word
|
||||
endfunction
|
||||
|
||||
let &l:path =
|
||||
\ join([
|
||||
\ getcwd().'/lib',
|
||||
\ getcwd().'/src',
|
||||
\ getcwd().'/deps/**/lib',
|
||||
\ getcwd().'/deps/**/src',
|
||||
\ 'lib',
|
||||
\ 'src',
|
||||
\ 'deps/**/lib',
|
||||
\ 'deps/**/src',
|
||||
\ &g:path
|
||||
\ ], ',')
|
||||
setlocal includeexpr=GetElixirFilename(v:fname)
|
||||
setlocal includeexpr=elixir#util#get_filename(v:fname)
|
||||
setlocal suffixesadd=.ex,.exs,.eex,.erl,.yrl,.hrl
|
||||
|
||||
silent! setlocal formatoptions-=t formatoptions+=croqlj
|
||||
|
||||
let b:undo_ftplugin = 'setlocal sw< sts< et< isk< com< cms< path< inex< sua< '.
|
||||
\ '| unlet! b:match_ignorecase b:match_words'
|
||||
|
||||
endif
|
||||
|
||||
149
ftplugin/elm.vim
149
ftplugin/elm.vim
@@ -1,86 +1,101 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" elm.vim - Plugin for the Elm programming language
|
||||
" Maintainer: Alexander Noriega <http://lambdatoast.com/>
|
||||
" Version: 0.4.3
|
||||
" plugin for Elm (http://elm-lang.org/)
|
||||
|
||||
" Plugin setup stuff
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
if exists('b:did_ftplugin')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Compilation
|
||||
" Settings
|
||||
if !exists('g:elm_jump_to_error')
|
||||
let g:elm_jump_to_error = 0
|
||||
endif
|
||||
|
||||
function! ElmMake(file)
|
||||
let args = a:file
|
||||
return elm#io#system("elm-make", args)
|
||||
endfunction
|
||||
if !exists('g:elm_make_output_file')
|
||||
let g:elm_make_output_file = 'elm.js'
|
||||
endif
|
||||
|
||||
function! ElmMakeCurrentFile()
|
||||
echo ElmMake(expand("%"))
|
||||
endfunction
|
||||
if !exists('g:elm_make_show_warnings')
|
||||
let g:elm_make_show_warnings = 0
|
||||
endif
|
||||
|
||||
function! ElmMakeMain()
|
||||
echo ElmMake("Main.elm")
|
||||
endfunction
|
||||
if !exists('g:elm_syntastic_show_warnings')
|
||||
let g:elm_syntastic_show_warnings = 0
|
||||
endif
|
||||
|
||||
function! ElmMakeFile(file)
|
||||
echo ElmMake(a:file)
|
||||
endfunction
|
||||
if !exists('g:elm_format_autosave')
|
||||
let g:elm_format_autosave = 1
|
||||
endif
|
||||
|
||||
" REPL
|
||||
if !exists('g:elm_format_fail_silently')
|
||||
let g:elm_format_fail_silently = 0
|
||||
endif
|
||||
|
||||
function! ElmRepl()
|
||||
!elm-repl
|
||||
endfunction
|
||||
if !exists('g:elm_setup_keybindings')
|
||||
let g:elm_setup_keybindings = 1
|
||||
endif
|
||||
|
||||
" Evaluation
|
||||
|
||||
function! ElmEvalLine()
|
||||
return ElmEval(getline("."))
|
||||
endfunction
|
||||
|
||||
function! ElmEvalSelection()
|
||||
let savedReg = @z
|
||||
normal! `<v`>"zy
|
||||
let res = ElmEval(substitute(getreg("z"), "\n", "\\\n", "g"))
|
||||
let @z = savedReg
|
||||
normal! gv
|
||||
endfunction
|
||||
|
||||
function! ElmEval(sourceCode)
|
||||
let currentLine = a:sourceCode
|
||||
let args = "echo '" . currentLine . "' | elm-repl"
|
||||
let result = elm#io#system("echo", args)
|
||||
let cleanResult = "-- " . join(s:Filtered(function("s:IsUsefulReplOutput"), split(result, "\n")), "")
|
||||
put =cleanResult
|
||||
endfunction
|
||||
|
||||
function! s:IsUsefulReplOutput(str)
|
||||
return a:str !~ "^Elm REPL" && a:str !~ "Type :help" && a:str !~ ">\\s*$"
|
||||
endfunction
|
||||
|
||||
" List processing
|
||||
|
||||
function! s:Filtered(fn, l)
|
||||
let new_list = deepcopy(a:l)
|
||||
call filter(new_list, string(a:fn) . '(v:val)')
|
||||
return new_list
|
||||
endfunction
|
||||
|
||||
command -buffer ElmEvalLine call ElmEvalLine()
|
||||
command -buffer ElmEvalSelection call ElmEvalSelection()
|
||||
command -buffer ElmMakeMain call ElmMakeMain()
|
||||
command -buffer -nargs=1 ElmMakeFile call ElmMakeFile <args>
|
||||
command -buffer ElmMakeCurrentFile call ElmMakeCurrentFile()
|
||||
command -buffer ElmRepl call ElmRepl()
|
||||
|
||||
" Define comment convention
|
||||
setlocal omnifunc=elm#Complete
|
||||
|
||||
setlocal comments=:--
|
||||
setlocal commentstring=--%s
|
||||
setlocal commentstring=--\ %s
|
||||
|
||||
" Commands
|
||||
command -buffer -nargs=? -complete=file ElmMake call elm#Make(<f-args>)
|
||||
command -buffer ElmMakeMain call elm#Make("Main.elm")
|
||||
command -buffer -nargs=? -complete=file ElmTest call elm#Test(<f-args>)
|
||||
command -buffer ElmRepl call elm#Repl()
|
||||
command -buffer ElmErrorDetail call elm#ErrorDetail()
|
||||
command -buffer ElmShowDocs call elm#ShowDocs()
|
||||
command -buffer ElmBrowseDocs call elm#BrowseDocs()
|
||||
command -buffer ElmFormat call elm#Format()
|
||||
|
||||
if get(g:, 'elm_setup_keybindings', 1)
|
||||
nmap <buffer> <LocalLeader>m <Plug>(elm-make)
|
||||
nmap <buffer> <LocalLeader>b <Plug>(elm-make-main)
|
||||
nmap <buffer> <LocalLeader>t <Plug>(elm-test)
|
||||
nmap <buffer> <LocalLeader>r <Plug>(elm-repl)
|
||||
nmap <buffer> <LocalLeader>e <Plug>(elm-error-detail)
|
||||
nmap <buffer> <LocalLeader>d <Plug>(elm-show-docs)
|
||||
nmap <buffer> <LocalLeader>w <Plug>(elm-browse-docs)
|
||||
endif
|
||||
|
||||
" Better gf command
|
||||
nmap <buffer> gf :call elm#util#GoToModule(expand('<cfile>'))<CR>
|
||||
|
||||
" Elm code formatting on save
|
||||
if get(g:, 'elm_format_autosave', 1)
|
||||
augroup elmFormat
|
||||
autocmd!
|
||||
autocmd BufWritePre *.elm call elm#Format()
|
||||
autocmd BufWritePost *.elm call elm#util#EchoStored()
|
||||
augroup END
|
||||
endif
|
||||
if has('win32')
|
||||
set viewdir=$HOME/vimfiles/views/
|
||||
endif
|
||||
|
||||
" Enable go to file under cursor from module name
|
||||
" Based on: https://github.com/elixir-lang/vim-elixir/blob/bd66ed134319d1e390f3331e8c4d525109f762e8/ftplugin/elixir.vim#L22-L56
|
||||
function! GetElmFilename(word)
|
||||
let l:word = a:word
|
||||
|
||||
" replace module dots with slash
|
||||
let l:word = substitute(l:word,'\.','/','g')
|
||||
|
||||
return l:word
|
||||
endfunction
|
||||
|
||||
let &l:path =
|
||||
\ join([
|
||||
\ elm#FindRootDirectory().'/src',
|
||||
\ elm#FindRootDirectory().'/elm-stuff/packages/**/src',
|
||||
\ &g:path
|
||||
\ ], ',')
|
||||
setlocal includeexpr=GetElmFilename(v:fname)
|
||||
setlocal include=^\\s*import\\s\\+
|
||||
setlocal suffixesadd=.elm
|
||||
|
||||
endif
|
||||
|
||||
24
ftplugin/elm/tagbar.vim
Normal file
24
ftplugin/elm/tagbar.vim
Normal file
@@ -0,0 +1,24 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
if !executable('ctags')
|
||||
finish
|
||||
elseif globpath(&runtimepath, 'plugin/tagbar.vim') ==? ''
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:SetTagbar()
|
||||
if !exists('g:tagbar_type_elm')
|
||||
let g:tagbar_type_elm = {
|
||||
\ 'ctagstype' : 'elm',
|
||||
\ 'kinds' : [
|
||||
\ 'c:constants',
|
||||
\ 'f:functions',
|
||||
\ 'p:ports'
|
||||
\ ]
|
||||
\ }
|
||||
endif
|
||||
endfunction
|
||||
|
||||
call s:SetTagbar()
|
||||
|
||||
endif
|
||||
@@ -29,7 +29,7 @@ elseif !exists("b:eruby_subtype")
|
||||
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
|
||||
let b:eruby_subtype = matchstr(s:lines,'eruby_subtype=\zs\w\+')
|
||||
if b:eruby_subtype == ''
|
||||
let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
|
||||
let b:eruby_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.erb\|\.eruby\|\.erubis\|\.example\)\+$','',''),'\.\zs\w\+\%(\ze+\w\+\)\=$')
|
||||
endif
|
||||
if b:eruby_subtype == 'rhtml'
|
||||
let b:eruby_subtype = 'html'
|
||||
@@ -47,7 +47,7 @@ elseif !exists("b:eruby_subtype")
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists("b:eruby_subtype") && b:eruby_subtype != ''
|
||||
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=? 'eruby'
|
||||
exe "runtime! ftplugin/".b:eruby_subtype.".vim ftplugin/".b:eruby_subtype."_*.vim ftplugin/".b:eruby_subtype."/*.vim"
|
||||
else
|
||||
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
||||
|
||||
@@ -31,7 +31,7 @@ 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'
|
||||
execute 'setlocal keywordprg=fish\ '.fnameescape(expand('<sfile>:p:h:h').'/bin/man.fish')
|
||||
|
||||
let b:match_words =
|
||||
\ escape('<%(begin|function|if|switch|while|for)>:<end>', '<>%|)')
|
||||
|
||||
@@ -28,11 +28,12 @@ function! s:cycle()
|
||||
call s:choose(get({'s':'edit','p':'squash','e':'reword','r':'fixup'},getline('.')[0],'pick'))
|
||||
endfunction
|
||||
|
||||
command! -buffer -bar Pick :call s:choose('pick')
|
||||
command! -buffer -bar Squash :call s:choose('squash')
|
||||
command! -buffer -bar Edit :call s:choose('edit')
|
||||
command! -buffer -bar Reword :call s:choose('reword')
|
||||
command! -buffer -bar Fixup :call s:choose('fixup')
|
||||
command! -buffer -bar -range Pick :<line1>,<line2>call s:choose('pick')
|
||||
command! -buffer -bar -range Squash :<line1>,<line2>call s:choose('squash')
|
||||
command! -buffer -bar -range Edit :<line1>,<line2>call s:choose('edit')
|
||||
command! -buffer -bar -range Reword :<line1>,<line2>call s:choose('reword')
|
||||
command! -buffer -bar -range Fixup :<line1>,<line2>call s:choose('fixup')
|
||||
command! -buffer -bar -range Drop :<line1>,<line2>call s:choose('drop')
|
||||
command! -buffer -bar Cycle :call s:cycle()
|
||||
" The above are more useful when they are mapped; for example:
|
||||
"nnoremap <buffer> <silent> S :Cycle<CR>
|
||||
|
||||
99
ftplugin/julia.vim
Normal file
99
ftplugin/julia.vim
Normal file
@@ -0,0 +1,99 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'julia') == -1
|
||||
|
||||
" Vim filetype plugin file
|
||||
" Language: Julia
|
||||
" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
|
||||
" Last Change: 2014 may 29
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:save_cpo = &cpo
|
||||
set cpo-=C
|
||||
|
||||
setlocal include=^\\s*\\%(reload\\\|include\\)\\>
|
||||
setlocal suffixesadd=.jl
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#=%s=#
|
||||
setlocal cinoptions+=#1
|
||||
setlocal define=^\\s*macro\\>
|
||||
|
||||
let b:julia_vim_loaded = 1
|
||||
|
||||
let b:undo_ftplugin = "setlocal include< suffixesadd< comments< commentstring<"
|
||||
\ . " define< shiftwidth< expandtab< indentexpr< indentkeys< cinoptions< omnifunc<"
|
||||
\ . " | unlet! b:julia_vim_loaded"
|
||||
|
||||
" MatchIt plugin support
|
||||
if exists("loaded_matchit")
|
||||
let b:match_ignorecase = 0
|
||||
|
||||
" note: begin_keywords must contain all blocks in order
|
||||
" for nested-structures-skipping to work properly
|
||||
let b:julia_begin_keywords = '\%(\%(\.\s*\)\@<!\|\%(@\s*.\s*\)\@<=\)\<\%(\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|\%(\(abstract\|primitive\)\s\+\)\@<!type\|immutable\|let\|do\|\%(bare\)\?module\|quote\|if\|for\|while\|try\)\>'
|
||||
let s:macro_regex = '@\%(#\@!\S\)\+\s\+'
|
||||
let s:nomacro = '\%(' . s:macro_regex . '\)\@<!'
|
||||
let s:yesmacro = s:nomacro . '\%('. s:macro_regex . '\)\+'
|
||||
let b:julia_begin_keywordsm = '\%(' . s:yesmacro . b:julia_begin_keywords . '\)\|'
|
||||
\ . '\%(' . s:nomacro . b:julia_begin_keywords . '\)'
|
||||
let b:julia_end_keywords = '\<end\>'
|
||||
|
||||
" note: this function relies heavily on the syntax file
|
||||
function! JuliaGetMatchWords()
|
||||
let [l,c] = [line('.'),col('.')]
|
||||
let attr = synIDattr(synID(l, c, 1),"name")
|
||||
let c1 = c
|
||||
while attr == 'juliaMacro'
|
||||
normal! W
|
||||
if line('.') > l || col('.') == c1
|
||||
call cursor(l, c)
|
||||
return ''
|
||||
endif
|
||||
let attr = synIDattr(synID(l, col('.'), 1),"name")
|
||||
let c1 = col('.')
|
||||
endwhile
|
||||
call cursor(l, c)
|
||||
if attr == 'juliaConditional'
|
||||
return b:julia_begin_keywordsm . ':\<\%(elseif\|else\)\>:' . b:julia_end_keywords
|
||||
elseif attr =~ '\<\%(juliaRepeat\|juliaRepKeyword\)\>'
|
||||
return b:julia_begin_keywordsm . ':\<\%(break\|continue\)\>:' . b:julia_end_keywords
|
||||
elseif attr == 'juliaBlKeyword'
|
||||
return b:julia_begin_keywordsm . ':' . b:julia_end_keywords
|
||||
elseif attr == 'juliaException'
|
||||
return b:julia_begin_keywordsm . ':\<\%(catch\|finally\)\>:' . b:julia_end_keywords
|
||||
endif
|
||||
return '\<\>:\<\>'
|
||||
endfunction
|
||||
|
||||
let b:match_words = 'JuliaGetMatchWords()'
|
||||
|
||||
" we need to skip everything within comments, strings and
|
||||
" the 'end' keyword when it is used as a range rather than as
|
||||
" the end of a block
|
||||
let b:match_skip = 'synIDattr(synID(line("."),col("."),1),"name") =~ '
|
||||
\ . '"\\<julia\\%(Comprehension\\%(For\\|If\\)\\|RangeEnd\\|SymbolS\\?\\|Comment[LM]\\|\\%([bv]\\|ip\\|MIME\\|Shell\\|Doc\\)\\?String\\|RegEx\\)\\>"'
|
||||
|
||||
let b:undo_ftplugin = b:undo_ftplugin
|
||||
\ . " | unlet! b:match_words b:match_skip b:match_ignorecase"
|
||||
\ . " | unlet! b:julia_begin_keywords b:julia_end_keywords"
|
||||
\ . " | delfunction JuliaGetMatchWords"
|
||||
\ . " | call julia_blocks#remove_mappings()"
|
||||
|
||||
if get(g:, "julia_blocks", 1)
|
||||
call julia_blocks#init_mappings()
|
||||
let b:undo_ftplugin .= " | call julia_blocks#remove_mappings()"
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
if has("gui_win32")
|
||||
let b:browsefilter = "Julia Source Files (*.jl)\t*.jl\n"
|
||||
let b:undo_ftplugin = b:undo_ftplugin . " | unlet! b:browsefilter"
|
||||
endif
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
||||
@@ -1,417 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box common functions
|
||||
|
||||
" Error Format {{{
|
||||
" Note: The error formats assume we're using the -file-line-error with
|
||||
" [pdf]latex.
|
||||
" Note: See |errorformat-LaTeX| for more info.
|
||||
|
||||
" Check for options
|
||||
if !exists("g:LatexBox_show_warnings")
|
||||
let g:LatexBox_show_warnings=1
|
||||
endif
|
||||
if !exists("g:LatexBox_ignore_warnings")
|
||||
let g:LatexBox_ignore_warnings =
|
||||
\['Underfull',
|
||||
\ 'Overfull',
|
||||
\ 'specifier changed to']
|
||||
endif
|
||||
|
||||
" Standard error message formats
|
||||
" Note: We consider statements that starts with "!" as errors
|
||||
setlocal efm=%E!\ LaTeX\ %trror:\ %m
|
||||
setlocal efm+=%E%f:%l:\ %m
|
||||
setlocal efm+=%E!\ %m
|
||||
|
||||
" More info for undefined control sequences
|
||||
setlocal efm+=%Z<argument>\ %m
|
||||
|
||||
" More info for some errors
|
||||
setlocal efm+=%Cl.%l\ %m
|
||||
|
||||
" Show or ignore warnings
|
||||
if g:LatexBox_show_warnings
|
||||
" Parse biblatex warnings
|
||||
setlocal efm+=%-C(biblatex)%.%#in\ t%.%#
|
||||
setlocal efm+=%-C(biblatex)%.%#Please\ v%.%#
|
||||
setlocal efm+=%-C(biblatex)%.%#LaTeX\ a%.%#
|
||||
setlocal efm+=%-Z(biblatex)%m
|
||||
|
||||
" Parse hyperref warnings
|
||||
setlocal efm+=%-C(hyperref)%.%#on\ input\ line\ %l.
|
||||
|
||||
for w in g:LatexBox_ignore_warnings
|
||||
let warning = escape(substitute(w, '[\,]', '%\\\\&', 'g'), ' ')
|
||||
exe 'setlocal efm+=%-G%.%#'. warning .'%.%#'
|
||||
endfor
|
||||
setlocal efm+=%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#
|
||||
setlocal efm+=%+W%.%#\ at\ lines\ %l--%*\\d
|
||||
setlocal efm+=%+WLaTeX\ %.%#Warning:\ %m
|
||||
setlocal efm+=%+W%.%#Warning:\ %m
|
||||
else
|
||||
setlocal efm+=%-WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#
|
||||
setlocal efm+=%-W%.%#\ at\ lines\ %l--%*\\d
|
||||
setlocal efm+=%-WLaTeX\ %.%#Warning:\ %m
|
||||
setlocal efm+=%-W%.%#Warning:\ %m
|
||||
endif
|
||||
|
||||
" Push file to file stack
|
||||
setlocal efm+=%+P**%f
|
||||
setlocal efm+=%+P**\"%f\"
|
||||
|
||||
" Ignore unmatched lines
|
||||
setlocal efm+=%-G%.%#
|
||||
" }}}
|
||||
|
||||
" Vim Windows {{{
|
||||
|
||||
" Type of split, "new" for horiz. "vnew" for vert.
|
||||
if !exists('g:LatexBox_split_type')
|
||||
let g:LatexBox_split_type = "vnew"
|
||||
endif
|
||||
|
||||
" Length of vertical splits
|
||||
if !exists('g:LatexBox_split_length')
|
||||
let g:LatexBox_split_length = 15
|
||||
endif
|
||||
|
||||
" Width of horizontal splits
|
||||
if !exists('g:LatexBox_split_width')
|
||||
let g:LatexBox_split_width = 30
|
||||
endif
|
||||
|
||||
" Where splits appear
|
||||
if !exists('g:LatexBox_split_side')
|
||||
let g:LatexBox_split_side = "aboveleft"
|
||||
endif
|
||||
|
||||
" Resize when split?
|
||||
if !exists('g:LatexBox_split_resize')
|
||||
let g:LatexBox_split_resize = 0
|
||||
endif
|
||||
|
||||
" Toggle help info
|
||||
if !exists('g:LatexBox_toc_hidehelp')
|
||||
let g:LatexBox_toc_hidehelp = 0
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Filename utilities {{{
|
||||
function! LatexBox_GetMainTexFile()
|
||||
|
||||
" 1. check for the b:main_tex_file variable
|
||||
if exists('b:main_tex_file') && filereadable(b:main_tex_file)
|
||||
return b:main_tex_file
|
||||
endif
|
||||
|
||||
|
||||
" 2. scan the first few lines of the file for root = filename
|
||||
for linenum in range(1,5)
|
||||
let linecontents = getline(linenum)
|
||||
if linecontents =~ 'root\s*='
|
||||
" Remove everything but the filename
|
||||
let b:main_tex_file = substitute(linecontents,
|
||||
\ '.*root\s*=\s*', "", "")
|
||||
let b:main_tex_file = substitute(b:main_tex_file, '\s*$', "", "")
|
||||
" Prepend current directory if this isn't an absolute path
|
||||
if b:main_tex_file !~ '^/'
|
||||
let b:main_tex_file = expand('%:p:h') . '/' . b:main_tex_file
|
||||
endif
|
||||
let b:main_tex_file = fnamemodify(b:main_tex_file, ":p")
|
||||
if b:main_tex_file !~ '\.tex$'
|
||||
let b:main_tex_file .= '.tex'
|
||||
endif
|
||||
return b:main_tex_file
|
||||
endif
|
||||
endfor
|
||||
|
||||
" 3. scan current file for "\begin{document}"
|
||||
if &filetype == 'tex' && search('\m\C\\begin\_\s*{document}', 'nw') != 0
|
||||
return expand('%:p')
|
||||
endif
|
||||
|
||||
" 4. use 'main.tex' if it exists in the same directory (and is readable)
|
||||
let s:main_dot_tex_file=expand('%:p:h') . '/main.tex'
|
||||
if filereadable(s:main_dot_tex_file)
|
||||
let b:main_tex_file=s:main_dot_tex_file
|
||||
return b:main_tex_file
|
||||
endif
|
||||
|
||||
" 5. borrow the Vim-Latex-Suite method of finding it
|
||||
if LatexBox_GetMainFileName() != expand('%:p')
|
||||
let b:main_tex_file = LatexBox_GetMainFileName()
|
||||
return b:main_tex_file
|
||||
endif
|
||||
|
||||
" 6. prompt for file with completion
|
||||
let b:main_tex_file = s:PromptForMainFile()
|
||||
return b:main_tex_file
|
||||
endfunction
|
||||
|
||||
function! s:PromptForMainFile()
|
||||
let saved_dir = getcwd()
|
||||
execute 'cd ' . fnameescape(expand('%:p:h'))
|
||||
|
||||
" Prompt for file
|
||||
let l:file = ''
|
||||
while !filereadable(l:file)
|
||||
let l:file = input('main LaTeX file: ', '', 'file')
|
||||
if l:file !~ '\.tex$'
|
||||
let l:file .= '.tex'
|
||||
endif
|
||||
endwhile
|
||||
let l:file = fnamemodify(l:file, ':p')
|
||||
|
||||
" Make persistent
|
||||
let l:persistent = ''
|
||||
while l:persistent !~ '\v^(y|n)'
|
||||
let l:persistent = input('make choice persistent? (y, n) ')
|
||||
if l:persistent == 'y'
|
||||
call writefile([], l:file . '.latexmain')
|
||||
endif
|
||||
endwhile
|
||||
|
||||
execute 'cd ' . fnameescape(saved_dir)
|
||||
return l:file
|
||||
endfunction
|
||||
|
||||
" Return the directory of the main tex file
|
||||
function! LatexBox_GetTexRoot()
|
||||
return fnamemodify(LatexBox_GetMainTexFile(), ':h')
|
||||
endfunction
|
||||
|
||||
function! LatexBox_GetBuildBasename(with_dir)
|
||||
" 1. Check for g:LatexBox_jobname
|
||||
if exists('g:LatexBox_jobname')
|
||||
return g:LatexBox_jobname
|
||||
endif
|
||||
|
||||
" 2. Get the basename from the main tex file
|
||||
if a:with_dir
|
||||
return fnamemodify(LatexBox_GetMainTexFile(), ':r')
|
||||
else
|
||||
return fnamemodify(LatexBox_GetMainTexFile(), ':t:r')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! LatexBox_GetAuxFile()
|
||||
" 1. check for b:build_dir variable
|
||||
if exists('b:build_dir') && isdirectory(b:build_dir)
|
||||
return b:build_dir . '/' . LatexBox_GetBuildBasename(0) . '.aux'
|
||||
endif
|
||||
|
||||
" 2. check for g:LatexBox_build_dir variable
|
||||
if exists('g:LatexBox_build_dir') && isdirectory(g:LatexBox_build_dir)
|
||||
return g:LatexBox_build_dir . '/' . LatexBox_GetBuildBasename(0) . '.aux'
|
||||
endif
|
||||
|
||||
" 3. use the base name of main tex file
|
||||
return LatexBox_GetBuildBasename(1) . '.aux'
|
||||
endfunction
|
||||
|
||||
function! LatexBox_GetLogFile()
|
||||
" 1. check for b:build_dir variable
|
||||
if exists('b:build_dir') && isdirectory(b:build_dir)
|
||||
return b:build_dir . '/' . LatexBox_GetBuildBasename(0) . '.log'
|
||||
endif
|
||||
|
||||
" 2. check for g:LatexBox_build_dir variable
|
||||
if exists('g:LatexBox_build_dir') && isdirectory(g:LatexBox_build_dir)
|
||||
return g:LatexBox_build_dir . '/' . LatexBox_GetBuildBasename(0) . '.log'
|
||||
endif
|
||||
|
||||
" 3. use the base name of main tex file
|
||||
return LatexBox_GetBuildBasename(1) . '.log'
|
||||
endfunction
|
||||
|
||||
function! LatexBox_GetOutputFile()
|
||||
" 1. check for b:build_dir variable
|
||||
if exists('b:build_dir') && isdirectory(b:build_dir)
|
||||
return b:build_dir . '/' . LatexBox_GetBuildBasename(0)
|
||||
\ . '.' . g:LatexBox_output_type
|
||||
endif
|
||||
|
||||
" 2. check for g:LatexBox_build_dir variable
|
||||
if exists('g:LatexBox_build_dir') && isdirectory(g:LatexBox_build_dir)
|
||||
return g:LatexBox_build_dir . '/' . LatexBox_GetBuildBasename(0)
|
||||
\ . '.' . g:LatexBox_output_type
|
||||
endif
|
||||
|
||||
" 3. use the base name of main tex file
|
||||
return LatexBox_GetBuildBasename(1) . '.' . g:LatexBox_output_type
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" View Output {{{
|
||||
|
||||
" Default pdf viewer
|
||||
if !exists('g:LatexBox_viewer')
|
||||
" On windows, 'running' a file will open it with the default program
|
||||
let s:viewer = ''
|
||||
if has('unix')
|
||||
" echo -n necessary as uname -s will append \n otherwise
|
||||
let s:uname = system('echo -n $(uname -s)')
|
||||
if s:uname == "Darwin"
|
||||
let s:viewer = 'open'
|
||||
else
|
||||
let s:viewer = 'xdg-open'
|
||||
endif
|
||||
endif
|
||||
let g:LatexBox_viewer = s:viewer
|
||||
endif
|
||||
|
||||
function! LatexBox_View(...)
|
||||
let lvargs = join(a:000, ' ')
|
||||
let outfile = LatexBox_GetOutputFile()
|
||||
if !filereadable(outfile)
|
||||
echomsg fnamemodify(outfile, ':.') . ' is not readable'
|
||||
return
|
||||
endif
|
||||
let cmd = g:LatexBox_viewer . ' ' . lvargs . ' ' . shellescape(outfile)
|
||||
if has('win32')
|
||||
let cmd = '!start /b ' . cmd . ' >nul'
|
||||
else
|
||||
let cmd = '!' . cmd . ' '
|
||||
if fnamemodify(&shell, ':t') ==# 'fish'
|
||||
let cmd .= ' >/dev/null ^/dev/null &'
|
||||
else
|
||||
let cmd .= ' &>/dev/null &'
|
||||
endif
|
||||
endif
|
||||
silent execute cmd
|
||||
if !has("gui_running")
|
||||
redraw!
|
||||
endif
|
||||
endfunction
|
||||
|
||||
command! -nargs=* LatexView call LatexBox_View('<args>')
|
||||
" }}}
|
||||
|
||||
" In Comment {{{
|
||||
|
||||
" LatexBox_InComment([line], [col])
|
||||
" return true if inside comment
|
||||
function! LatexBox_InComment(...)
|
||||
let line = a:0 >= 1 ? a:1 : line('.')
|
||||
let col = a:0 >= 2 ? a:2 : col('.')
|
||||
return synIDattr(synID(line, col, 0), "name") =~# '^texComment'
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Get Current Environment {{{
|
||||
|
||||
" LatexBox_GetCurrentEnvironment([with_pos])
|
||||
" Returns:
|
||||
" - environment
|
||||
" if with_pos is not given
|
||||
" - [envirnoment, lnum_begin, cnum_begin, lnum_end, cnum_end]
|
||||
" if with_pos is nonzero
|
||||
function! LatexBox_GetCurrentEnvironment(...)
|
||||
if a:0 > 0
|
||||
let with_pos = a:1
|
||||
else
|
||||
let with_pos = 0
|
||||
endif
|
||||
|
||||
let begin_pat = '\C\\begin\_\s*{[^}]*}\|\\\@<!\\\[\|\\\@<!\\('
|
||||
let end_pat = '\C\\end\_\s*{[^}]*}\|\\\@<!\\\]\|\\\@<!\\)'
|
||||
let saved_pos = getpos('.')
|
||||
|
||||
" move to the left until on a backslash
|
||||
let [bufnum, lnum, cnum, off] = getpos('.')
|
||||
let line = getline(lnum)
|
||||
while cnum > 1 && line[cnum - 1] != '\'
|
||||
let cnum -= 1
|
||||
endwhile
|
||||
call cursor(lnum, cnum)
|
||||
|
||||
" match begin/end pairs but skip comments
|
||||
let flags = 'bnW'
|
||||
if strpart(getline('.'), col('.') - 1) =~ '^\%(' . begin_pat . '\)'
|
||||
let flags .= 'c'
|
||||
endif
|
||||
let [lnum1, cnum1] = searchpairpos(begin_pat, '', end_pat, flags,
|
||||
\ 'LatexBox_InComment()')
|
||||
|
||||
let env = ''
|
||||
|
||||
if lnum1
|
||||
let line = strpart(getline(lnum1), cnum1 - 1)
|
||||
|
||||
if empty(env)
|
||||
let env = matchstr(line, '^\C\\begin\_\s*{\zs[^}]*\ze}')
|
||||
endif
|
||||
if empty(env)
|
||||
let env = matchstr(line, '^\\\[')
|
||||
endif
|
||||
if empty(env)
|
||||
let env = matchstr(line, '^\\(')
|
||||
endif
|
||||
endif
|
||||
|
||||
if with_pos == 1
|
||||
let flags = 'nW'
|
||||
if !(lnum1 == lnum && cnum1 == cnum)
|
||||
let flags .= 'c'
|
||||
endif
|
||||
|
||||
let [lnum2, cnum2] = searchpairpos(begin_pat, '', end_pat, flags,
|
||||
\ 'LatexBox_InComment()')
|
||||
|
||||
call setpos('.', saved_pos)
|
||||
return [env, lnum1, cnum1, lnum2, cnum2]
|
||||
else
|
||||
call setpos('.', saved_pos)
|
||||
return env
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Tex To Tree {{{
|
||||
" stores nested braces in a tree structure
|
||||
function! LatexBox_TexToTree(str)
|
||||
let tree = []
|
||||
let i1 = 0
|
||||
let i2 = -1
|
||||
let depth = 0
|
||||
while i2 < len(a:str)
|
||||
let i2 = match(a:str, '[{}]', i2 + 1)
|
||||
if i2 < 0
|
||||
let i2 = len(a:str)
|
||||
endif
|
||||
if i2 >= len(a:str) || a:str[i2] == '{'
|
||||
if depth == 0
|
||||
let item = substitute(strpart(a:str, i1, i2 - i1),
|
||||
\ '^\s*\|\s*$', '', 'g')
|
||||
if !empty(item)
|
||||
call add(tree, item)
|
||||
endif
|
||||
let i1 = i2 + 1
|
||||
endif
|
||||
let depth += 1
|
||||
else
|
||||
let depth -= 1
|
||||
if depth == 0
|
||||
call add(tree, LatexBox_TexToTree(strpart(a:str, i1, i2 - i1)))
|
||||
let i1 = i2 + 1
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
return tree
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Tree To Tex {{{
|
||||
function! LatexBox_TreeToTex(tree)
|
||||
if type(a:tree) == type('')
|
||||
return a:tree
|
||||
else
|
||||
return '{' . join(map(a:tree, 'LatexBox_TreeToTex(v:val)'), '') . '}'
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,936 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box completion
|
||||
|
||||
setlocal omnifunc=LatexBox_Complete
|
||||
|
||||
" <SID> Wrap {{{
|
||||
function! s:GetSID()
|
||||
return matchstr(expand('<sfile>'), '\zs<SNR>\d\+_\ze.*$')
|
||||
endfunction
|
||||
let s:SID = s:GetSID()
|
||||
function! s:SIDWrap(func)
|
||||
return s:SID . a:func
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Completion {{{
|
||||
if !exists('g:LatexBox_completion_close_braces')
|
||||
let g:LatexBox_completion_close_braces = 1
|
||||
endif
|
||||
if !exists('g:LatexBox_bibtex_wild_spaces')
|
||||
let g:LatexBox_bibtex_wild_spaces = 1
|
||||
endif
|
||||
|
||||
if !exists('g:LatexBox_cite_pattern')
|
||||
let g:LatexBox_cite_pattern = '\C\\\a*cite\a*\*\?\(\[[^\]]*\]\)*\_\s*{'
|
||||
endif
|
||||
if !exists('g:LatexBox_ref_pattern')
|
||||
let g:LatexBox_ref_pattern = '\C\\v\?\(eq\|page\|[cC]\|labelc\|name\|auto\)\?ref\*\?\_\s*{'
|
||||
endif
|
||||
|
||||
if !exists('g:LatexBox_completion_environments')
|
||||
let g:LatexBox_completion_environments = [
|
||||
\ {'word': 'itemize', 'menu': 'bullet list' },
|
||||
\ {'word': 'enumerate', 'menu': 'numbered list' },
|
||||
\ {'word': 'description', 'menu': 'description' },
|
||||
\ {'word': 'center', 'menu': 'centered text' },
|
||||
\ {'word': 'figure', 'menu': 'floating figure' },
|
||||
\ {'word': 'table', 'menu': 'floating table' },
|
||||
\ {'word': 'equation', 'menu': 'equation (numbered)' },
|
||||
\ {'word': 'align', 'menu': 'aligned equations (numbered)' },
|
||||
\ {'word': 'align*', 'menu': 'aligned equations' },
|
||||
\ {'word': 'document' },
|
||||
\ {'word': 'abstract' },
|
||||
\ ]
|
||||
endif
|
||||
|
||||
if !exists('g:LatexBox_completion_commands')
|
||||
let g:LatexBox_completion_commands = [
|
||||
\ {'word': '\begin{' },
|
||||
\ {'word': '\end{' },
|
||||
\ {'word': '\item' },
|
||||
\ {'word': '\label{' },
|
||||
\ {'word': '\ref{' },
|
||||
\ {'word': '\eqref{eq:' },
|
||||
\ {'word': '\cite{' },
|
||||
\ {'word': '\chapter{' },
|
||||
\ {'word': '\section{' },
|
||||
\ {'word': '\subsection{' },
|
||||
\ {'word': '\subsubsection{' },
|
||||
\ {'word': '\paragraph{' },
|
||||
\ {'word': '\nonumber' },
|
||||
\ {'word': '\bibliography' },
|
||||
\ {'word': '\bibliographystyle' },
|
||||
\ ]
|
||||
endif
|
||||
|
||||
if !exists('g:LatexBox_complete_inlineMath')
|
||||
let g:LatexBox_complete_inlineMath = 0
|
||||
endif
|
||||
|
||||
if !exists('g:LatexBox_eq_env_patterns')
|
||||
let g:LatexBox_eq_env_patterns = 'equation\|gather\|multiline\|align\|flalign\|alignat\|eqnarray'
|
||||
endif
|
||||
|
||||
" }}}
|
||||
|
||||
"LatexBox_kpsewhich {{{
|
||||
function! LatexBox_kpsewhich(file)
|
||||
let old_dir = getcwd()
|
||||
execute 'lcd ' . fnameescape(LatexBox_GetTexRoot())
|
||||
let out = system('kpsewhich "' . a:file . '"')
|
||||
|
||||
" If kpsewhich has found something, it returns a non-empty string with a
|
||||
" newline at the end; otherwise the string is empty
|
||||
if len(out)
|
||||
" Remove the trailing newline
|
||||
let out = fnamemodify(out[:-2], ':p')
|
||||
endif
|
||||
|
||||
execute 'lcd ' . fnameescape(old_dir)
|
||||
|
||||
return out
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" Omni Completion {{{
|
||||
|
||||
let s:completion_type = ''
|
||||
|
||||
function! LatexBox_Complete(findstart, base)
|
||||
if a:findstart
|
||||
" return the starting position of the word
|
||||
let line = getline('.')
|
||||
let pos = col('.') - 1
|
||||
while pos > 0 && line[pos - 1] !~ '\\\|{'
|
||||
let pos -= 1
|
||||
endwhile
|
||||
|
||||
let line_start = line[:pos-1]
|
||||
if line_start =~ '\m\C\\begin\_\s*{$'
|
||||
let s:completion_type = 'begin'
|
||||
elseif line_start =~ '\m\C\\end\_\s*{$'
|
||||
let s:completion_type = 'end'
|
||||
elseif line_start =~ '\m' . g:LatexBox_ref_pattern . '$'
|
||||
let s:completion_type = 'ref'
|
||||
elseif line_start =~ '\m' . g:LatexBox_cite_pattern . '$'
|
||||
let s:completion_type = 'bib'
|
||||
" check for multiple citations
|
||||
let pos = col('.') - 1
|
||||
while pos > 0 && line[pos - 1] !~ '{\|,'
|
||||
let pos -= 1
|
||||
endwhile
|
||||
elseif s:LatexBox_complete_inlineMath_or_not()
|
||||
let s:completion_type = 'inlineMath'
|
||||
let pos = s:eq_pos
|
||||
else
|
||||
let s:completion_type = 'command'
|
||||
if line[pos - 1] == '\'
|
||||
let pos -= 1
|
||||
endif
|
||||
endif
|
||||
return pos
|
||||
else
|
||||
" return suggestions in an array
|
||||
let suggestions = []
|
||||
|
||||
if s:completion_type == 'begin'
|
||||
" suggest known environments
|
||||
for entry in g:LatexBox_completion_environments
|
||||
if entry.word =~ '^' . escape(a:base, '\')
|
||||
if g:LatexBox_completion_close_braces && !s:NextCharsMatch('^}')
|
||||
" add trailing '}'
|
||||
let entry = copy(entry)
|
||||
let entry.abbr = entry.word
|
||||
let entry.word = entry.word . '}'
|
||||
endif
|
||||
call add(suggestions, entry)
|
||||
endif
|
||||
endfor
|
||||
elseif s:completion_type == 'end'
|
||||
" suggest known environments
|
||||
let env = LatexBox_GetCurrentEnvironment()
|
||||
if env != ''
|
||||
if g:LatexBox_completion_close_braces && !s:NextCharsMatch('^\s*[,}]')
|
||||
call add(suggestions, {'word': env . '}', 'abbr': env})
|
||||
else
|
||||
call add(suggestions, env)
|
||||
endif
|
||||
endif
|
||||
elseif s:completion_type == 'command'
|
||||
" suggest known commands
|
||||
for entry in g:LatexBox_completion_commands
|
||||
if entry.word =~ '^' . escape(a:base, '\')
|
||||
" do not display trailing '{'
|
||||
if entry.word =~ '{'
|
||||
let entry.abbr = entry.word[0:-2]
|
||||
endif
|
||||
call add(suggestions, entry)
|
||||
endif
|
||||
endfor
|
||||
elseif s:completion_type == 'ref'
|
||||
let suggestions = s:CompleteLabels(a:base)
|
||||
elseif s:completion_type == 'bib'
|
||||
" suggest BibTeX entries
|
||||
let suggestions = LatexBox_BibComplete(a:base)
|
||||
elseif s:completion_type == 'inlineMath'
|
||||
let suggestions = s:LatexBox_inlineMath_completion(a:base)
|
||||
endif
|
||||
if !has('gui_running')
|
||||
redraw!
|
||||
endif
|
||||
return suggestions
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" BibTeX search {{{
|
||||
|
||||
" find the \bibliography{...} commands
|
||||
" the optional argument is the file name to be searched
|
||||
|
||||
function! s:FindBibData(...)
|
||||
if a:0 == 0
|
||||
let file = LatexBox_GetMainTexFile()
|
||||
else
|
||||
let file = a:1
|
||||
endif
|
||||
|
||||
if !filereadable(file)
|
||||
return []
|
||||
endif
|
||||
let lines = readfile(file)
|
||||
let bibdata_list = []
|
||||
|
||||
"
|
||||
" Search for added bibliographies
|
||||
"
|
||||
let bibliography_cmds = [
|
||||
\ '\\bibliography',
|
||||
\ '\\addbibresource',
|
||||
\ '\\addglobalbib',
|
||||
\ '\\addsectionbib',
|
||||
\ ]
|
||||
for cmd in bibliography_cmds
|
||||
let filtered = filter(copy(lines),
|
||||
\ 'v:val =~ ''\C' . cmd . '\s*{[^}]\+}''')
|
||||
let files = map(filtered,
|
||||
\ 'matchstr(v:val, ''\C' . cmd . '\s*{\zs[^}]\+\ze}'')')
|
||||
for file in files
|
||||
let bibdata_list += map(split(file, ','),
|
||||
\ 'fnamemodify(v:val, '':r'')')
|
||||
endfor
|
||||
endfor
|
||||
|
||||
"
|
||||
" Also search included files
|
||||
"
|
||||
for input in filter(lines,
|
||||
\ 'v:val =~ ''\C\\\%(input\|include\)\s*{[^}]\+}''')
|
||||
let bibdata_list += s:FindBibData(LatexBox_kpsewhich(
|
||||
\ matchstr(input,
|
||||
\ '\C\\\%(input\|include\)\s*{\zs[^}]\+\ze}')))
|
||||
endfor
|
||||
|
||||
return bibdata_list
|
||||
endfunction
|
||||
|
||||
let s:bstfile = expand('<sfile>:p:h') . '/vimcomplete'
|
||||
|
||||
function! LatexBox_BibSearch(regexp)
|
||||
let res = []
|
||||
|
||||
" Find data from bib files
|
||||
let bibdata = join(s:FindBibData(), ',')
|
||||
if bibdata != ''
|
||||
|
||||
" write temporary aux file
|
||||
let tmpbase = LatexBox_GetTexRoot() . '/_LatexBox_BibComplete'
|
||||
let auxfile = tmpbase . '.aux'
|
||||
let bblfile = tmpbase . '.bbl'
|
||||
let blgfile = tmpbase . '.blg'
|
||||
|
||||
call writefile(['\citation{*}', '\bibstyle{' . s:bstfile . '}',
|
||||
\ '\bibdata{' . bibdata . '}'], auxfile)
|
||||
|
||||
if has('win32')
|
||||
let l:old_shellslash = &l:shellslash
|
||||
setlocal noshellslash
|
||||
call system('cd ' . shellescape(LatexBox_GetTexRoot()) .
|
||||
\ ' & bibtex -terse '
|
||||
\ . fnamemodify(auxfile, ':t') . ' >nul')
|
||||
let &l:shellslash = l:old_shellslash
|
||||
else
|
||||
call system('cd ' . shellescape(LatexBox_GetTexRoot()) .
|
||||
\ ' ; bibtex -terse '
|
||||
\ . fnamemodify(auxfile, ':t') . ' >/dev/null')
|
||||
endif
|
||||
|
||||
let lines = split(substitute(join(readfile(bblfile), "\n"),
|
||||
\ '\n\n\@!\(\s\=\)\s*\|{\|}', '\1', 'g'), "\n")
|
||||
|
||||
for line in filter(lines, 'v:val =~ a:regexp')
|
||||
let matches = matchlist(line,
|
||||
\ '^\(.*\)||\(.*\)||\(.*\)||\(.*\)||\(.*\)')
|
||||
if !empty(matches) && !empty(matches[1])
|
||||
let s:type_length = max([s:type_length,
|
||||
\ len(matches[2]) + 3])
|
||||
call add(res, {
|
||||
\ 'key': matches[1],
|
||||
\ 'type': matches[2],
|
||||
\ 'author': matches[3],
|
||||
\ 'year': matches[4],
|
||||
\ 'title': matches[5],
|
||||
\ })
|
||||
endif
|
||||
endfor
|
||||
|
||||
call delete(auxfile)
|
||||
call delete(bblfile)
|
||||
call delete(blgfile)
|
||||
endif
|
||||
|
||||
" Find data from 'thebibliography' environments
|
||||
let lines = readfile(LatexBox_GetMainTexFile())
|
||||
if match(lines, '\C\\begin{thebibliography}') >= 0
|
||||
for line in filter(filter(lines, 'v:val =~ ''\C\\bibitem'''),
|
||||
\ 'v:val =~ a:regexp')
|
||||
let match = matchlist(line, '\\bibitem{\([^}]*\)')[1]
|
||||
call add(res, {
|
||||
\ 'key': match,
|
||||
\ 'type': '',
|
||||
\ 'author': '',
|
||||
\ 'year': '',
|
||||
\ 'title': match,
|
||||
\ })
|
||||
endfor
|
||||
endif
|
||||
|
||||
return res
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" BibTeX completion {{{
|
||||
let s:type_length=0
|
||||
function! LatexBox_BibComplete(regexp)
|
||||
|
||||
" treat spaces as '.*' if needed
|
||||
if g:LatexBox_bibtex_wild_spaces
|
||||
"let regexp = substitute(a:regexp, '\s\+', '.*', 'g')
|
||||
let regexp = '.*' . substitute(a:regexp, '\s\+', '\\\&.*', 'g')
|
||||
else
|
||||
let regexp = a:regexp
|
||||
endif
|
||||
|
||||
let res = []
|
||||
let s:type_length = 4
|
||||
for m in LatexBox_BibSearch(regexp)
|
||||
let type = m['type'] == '' ? '[-]' : '[' . m['type'] . '] '
|
||||
let type = printf('%-' . s:type_length . 's', type)
|
||||
let auth = m['author'] == '' ? '' : m['author'][:20] . ' '
|
||||
let auth = substitute(auth, '\~', ' ', 'g')
|
||||
let auth = substitute(auth, ',.*\ze', ' et al. ', '')
|
||||
let year = m['year'] == '' ? '' : '(' . m['year'] . ')'
|
||||
let w = { 'word': m['key'],
|
||||
\ 'abbr': type . auth . year,
|
||||
\ 'menu': m['title'] }
|
||||
|
||||
" close braces if needed
|
||||
if g:LatexBox_completion_close_braces && !s:NextCharsMatch('^\s*[,}]')
|
||||
let w.word = w.word . '}'
|
||||
endif
|
||||
|
||||
call add(res, w)
|
||||
endfor
|
||||
return res
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" ExtractLabels {{{
|
||||
" Generate list of \newlabel commands in current buffer.
|
||||
"
|
||||
" Searches the current buffer for commands of the form
|
||||
" \newlabel{name}{{number}{page}.*
|
||||
" and returns list of [ name, number, page ] tuples.
|
||||
function! s:ExtractLabels()
|
||||
call cursor(1,1)
|
||||
|
||||
let matches = []
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
|
||||
while [lblline, lblbegin] != [0,0]
|
||||
let [nln, nameend] = searchpairpos( '{', '', '}', 'W' )
|
||||
if nln != lblline
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
let curname = strpart( getline( lblline ), lblbegin, nameend - lblbegin - 1 )
|
||||
|
||||
" Ignore cref entries (because they are duplicates)
|
||||
if curname =~# "@cref$"
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
|
||||
if 0 == search( '\m{\w*{', 'ce', lblline )
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
|
||||
let numberbegin = getpos('.')[2]
|
||||
let [nln, numberend] = searchpairpos( '{', '', '}', 'W' )
|
||||
if nln != lblline
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
let curnumber = strpart( getline( lblline ), numberbegin, numberend - numberbegin - 1 )
|
||||
|
||||
if 0 == search( '\m\w*{', 'ce', lblline )
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
|
||||
let pagebegin = getpos('.')[2]
|
||||
let [nln, pageend] = searchpairpos( '{', '', '}', 'W' )
|
||||
if nln != lblline
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
let curpage = strpart( getline( lblline ), pagebegin, pageend - pagebegin - 1 )
|
||||
|
||||
let matches += [ [ curname, curnumber, curpage ] ]
|
||||
|
||||
let [lblline, lblbegin] = searchpos( '\\newlabel{', 'ecW' )
|
||||
endwhile
|
||||
|
||||
return matches
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" ExtractInputs {{{
|
||||
" Generate list of \@input commands in current buffer.
|
||||
"
|
||||
" Searches the current buffer for \@input{file} entries and
|
||||
" returns list of all files.
|
||||
function! s:ExtractInputs()
|
||||
call cursor(1,1)
|
||||
|
||||
let matches = []
|
||||
let [inline, inbegin] = searchpos( '\\@input{', 'ecW' )
|
||||
|
||||
while [inline, inbegin] != [0,0]
|
||||
let [nln, inend] = searchpairpos( '{', '', '}', 'W' )
|
||||
if nln != inline
|
||||
let [inline, inbegin] = searchpos( '\\@input{', 'ecW' )
|
||||
continue
|
||||
endif
|
||||
let matches += [ LatexBox_kpsewhich(strpart( getline( inline ), inbegin, inend - inbegin - 1 )) ]
|
||||
|
||||
let [inline, inbegin] = searchpos( '\\@input{', 'ecW' )
|
||||
endwhile
|
||||
|
||||
" Remove empty strings for nonexistant .aux files
|
||||
return filter(matches, 'v:val != ""')
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" LabelCache {{{
|
||||
" Cache of all labels.
|
||||
"
|
||||
" LabelCache is a dictionary mapping filenames to tuples
|
||||
" [ time, labels, inputs ]
|
||||
" where
|
||||
" * time is modification time of the cache entry
|
||||
" * labels is a list like returned by ExtractLabels
|
||||
" * inputs is a list like returned by ExtractInputs
|
||||
let s:LabelCache = {}
|
||||
"}}}
|
||||
|
||||
" GetLabelCache {{{
|
||||
" Extract labels from LabelCache and update it.
|
||||
"
|
||||
" Compares modification time of each entry in the label
|
||||
" cache and updates it, if necessary. During traversal of
|
||||
" the LabelCache, all current labels are collected and
|
||||
" returned.
|
||||
function! s:GetLabelCache(file)
|
||||
if !filereadable(a:file)
|
||||
return []
|
||||
endif
|
||||
|
||||
if !has_key(s:LabelCache , a:file) || s:LabelCache[a:file][0] != getftime(a:file)
|
||||
" Open file in temporary split window for label extraction.
|
||||
let main_tex_file = LatexBox_GetMainTexFile()
|
||||
silent execute '1sp +let\ b:main_tex_file=main_tex_file|let\ labels=s:ExtractLabels()|let\ inputs=s:ExtractInputs()|quit! ' . fnameescape(a:file)
|
||||
let s:LabelCache[a:file] = [ getftime(a:file), labels, inputs ]
|
||||
endif
|
||||
|
||||
" We need to create a copy of s:LabelCache[fid][1], otherwise all inputs'
|
||||
" labels would be added to the current file's label cache upon each
|
||||
" completion call, leading to duplicates/triplicates/etc. and decreased
|
||||
" performance.
|
||||
" Also, because we don't anything with the list besides matching copies,
|
||||
" we can get away with a shallow copy for now.
|
||||
let labels = copy(s:LabelCache[a:file][1])
|
||||
|
||||
for input in s:LabelCache[a:file][2]
|
||||
let labels += s:GetLabelCache(input)
|
||||
endfor
|
||||
|
||||
return labels
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" Complete Labels {{{
|
||||
function! s:CompleteLabels(regex)
|
||||
let labels = s:GetLabelCache(LatexBox_GetAuxFile())
|
||||
|
||||
let matches = filter( copy(labels), 'match(v:val[0], "' . a:regex . '") != -1' )
|
||||
if empty(matches)
|
||||
" also try to match label and number
|
||||
let regex_split = split(a:regex)
|
||||
if len(regex_split) > 1
|
||||
let base = regex_split[0]
|
||||
let number = escape(join(regex_split[1:], ' '), '.')
|
||||
let matches = filter( copy(labels), 'match(v:val[0], "' . base . '") != -1 && match(v:val[1], "' . number . '") != -1' )
|
||||
endif
|
||||
endif
|
||||
if empty(matches)
|
||||
" also try to match number
|
||||
let matches = filter( copy(labels), 'match(v:val[1], "' . a:regex . '") != -1' )
|
||||
endif
|
||||
|
||||
let suggestions = []
|
||||
for m in matches
|
||||
let entry = {'word': m[0], 'menu': printf("%7s [p. %s]", '('.m[1].')', m[2])}
|
||||
if g:LatexBox_completion_close_braces && !s:NextCharsMatch('^\s*[,}]')
|
||||
" add trailing '}'
|
||||
let entry = copy(entry)
|
||||
let entry.abbr = entry.word
|
||||
let entry.word = entry.word . '}'
|
||||
endif
|
||||
call add(suggestions, entry)
|
||||
endfor
|
||||
|
||||
return suggestions
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Complete Inline Math Or Not {{{
|
||||
" Return 1, when cursor is in a math env:
|
||||
" 1, there is a single $ in the current line on the left of cursor
|
||||
" 2, there is an open-eq-env on/above the current line
|
||||
" (open-eq-env : \(, \[, and \begin{eq-env} )
|
||||
" Return 0, when cursor is not in a math env
|
||||
function! s:LatexBox_complete_inlineMath_or_not()
|
||||
|
||||
" switch of inline math completion feature
|
||||
if g:LatexBox_complete_inlineMath == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" env names that can't appear in an eq env
|
||||
if !exists('s:LatexBox_doc_structure_patterns')
|
||||
let s:LatexBox_doc_structure_patterns = '\%(' . '\\begin\s*{document}\|' .
|
||||
\ '\\\%(chapter\|section\|subsection\|subsubsection\)\*\?\s*{' . '\)'
|
||||
endif
|
||||
|
||||
if !exists('s:LatexBox_eq_env_open_patterns')
|
||||
let s:LatexBox_eq_env_open_patterns = ['\\(','\\\[']
|
||||
endif
|
||||
if !exists('s:LatexBox_eq_env_close_patterns')
|
||||
let s:LatexBox_eq_env_close_patterns = ['\\)','\\\]']
|
||||
endif
|
||||
|
||||
let notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
|
||||
let lnum_saved = line('.')
|
||||
let cnum_saved = col('.') -1
|
||||
|
||||
let line = getline('.')
|
||||
let line_start_2_cnum_saved = line[:cnum_saved]
|
||||
|
||||
" determine whether there is a single $ before cursor
|
||||
let cursor_dollar_pair = 0
|
||||
while matchend(line_start_2_cnum_saved, '\$[^$]\+\$', cursor_dollar_pair) >= 0
|
||||
" find the end of dollar pair
|
||||
let cursor_dollar_pair = matchend(line_start_2_cnum_saved, '\$[^$]\+\$', cursor_dollar_pair)
|
||||
endwhile
|
||||
" find single $ after cursor_dollar_pair
|
||||
let cursor_single_dollar = matchend(line_start_2_cnum_saved, '\$', cursor_dollar_pair)
|
||||
|
||||
" if single $ is found
|
||||
if cursor_single_dollar >= 0
|
||||
" check whether $ is in \(...\), \[...\], or \begin{eq}...\end{eq}
|
||||
|
||||
" check current line,
|
||||
" search for LatexBox_eq_env_close_patterns: \[ and \(
|
||||
let lnum = line('.')
|
||||
for i in range(0, (len(s:LatexBox_eq_env_open_patterns)-1))
|
||||
call cursor(lnum_saved, cnum_saved)
|
||||
let cnum_close = searchpos(''. s:LatexBox_eq_env_close_patterns[i].'', 'cbW', lnum_saved)[1]
|
||||
let cnum_open = matchend(line_start_2_cnum_saved, s:LatexBox_eq_env_open_patterns[i], cnum_close)
|
||||
if cnum_open >= 0
|
||||
let s:eq_dollar_parenthesis_bracket_empty = ''
|
||||
let s:eq_pos = cursor_single_dollar - 1
|
||||
return 1
|
||||
end
|
||||
endfor
|
||||
|
||||
" check the lines above
|
||||
" search for s:LatexBox_doc_structure_patterns, and end-of-math-env
|
||||
let lnum -= 1
|
||||
while lnum > 0
|
||||
let line = getline(lnum)
|
||||
if line =~ notcomment . '\(' . s:LatexBox_doc_structure_patterns .
|
||||
\ '\|' . '\\end\s*{\(' . g:LatexBox_eq_env_patterns . '\)\*\?}\)'
|
||||
" when s:LatexBox_doc_structure_patterns or g:LatexBox_eq_env_patterns
|
||||
" are found first, complete math, leave with $ at both sides
|
||||
let s:eq_dollar_parenthesis_bracket_empty = '$'
|
||||
let s:eq_pos = cursor_single_dollar
|
||||
break
|
||||
elseif line =~ notcomment . '\\begin\s*{\(' . g:LatexBox_eq_env_patterns . '\)\*\?}'
|
||||
" g:LatexBox_eq_env_patterns is found, complete math, remove $
|
||||
let s:eq_dollar_parenthesis_bracket_empty = ''
|
||||
let s:eq_pos = cursor_single_dollar - 1
|
||||
break
|
||||
endif
|
||||
let lnum -= 1
|
||||
endwhile
|
||||
|
||||
return 1
|
||||
else
|
||||
" no $ is found, then search for \( or \[ in current line
|
||||
" 1, whether there is \(
|
||||
call cursor(lnum_saved, cnum_saved)
|
||||
let cnum_parenthesis_close = searchpos('\\)', 'cbW', lnum_saved)[1]
|
||||
let cnum_parenthesis_open = matchend(line_start_2_cnum_saved, '\\(', cnum_parenthesis_close)
|
||||
if cnum_parenthesis_open >= 0
|
||||
let s:eq_dollar_parenthesis_bracket_empty = '\)'
|
||||
let s:eq_pos = cnum_parenthesis_open
|
||||
return 1
|
||||
end
|
||||
|
||||
" 2, whether there is \[
|
||||
call cursor(lnum_saved, cnum_saved)
|
||||
let cnum_bracket_close = searchpos('\\\]', 'cbW', lnum_saved)[1]
|
||||
let cnum_bracket_open = matchend(line_start_2_cnum_saved, '\\\[', cnum_bracket_close)
|
||||
if cnum_bracket_open >= 0
|
||||
let s:eq_dollar_parenthesis_bracket_empty = '\]'
|
||||
let s:eq_pos = cnum_bracket_open
|
||||
return 1
|
||||
end
|
||||
|
||||
" not inline math completion
|
||||
return 0
|
||||
endif
|
||||
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Complete inline euqation{{{
|
||||
function! s:LatexBox_inlineMath_completion(regex, ...)
|
||||
|
||||
if a:0 == 0
|
||||
let file = LatexBox_GetMainTexFile()
|
||||
else
|
||||
let file = a:1
|
||||
endif
|
||||
|
||||
if empty(glob(file, 1))
|
||||
return ''
|
||||
endif
|
||||
|
||||
if empty(s:eq_dollar_parenthesis_bracket_empty)
|
||||
let inline_pattern1 = '\$\s*\(' . escape(substitute(a:regex[1:], '^\s\+', '', ""), '\.*^') . '[^$]*\)\s*\$'
|
||||
let inline_pattern2 = '\\(\s*\(' . escape(substitute(a:regex[1:], '^\s\+', '', ""), '\.*^') . '.*\)\s*\\)'
|
||||
else
|
||||
let inline_pattern1 = '\$\s*\(' . escape(substitute(a:regex, '^\s\+', '', ""), '\.*^') . '[^$]*\)\s*\$'
|
||||
let inline_pattern2 = '\\(\s*\(' . escape(substitute(a:regex, '^\s\+', '', ""), '\.*^') . '.*\)\s*\\)'
|
||||
endif
|
||||
|
||||
|
||||
let suggestions = []
|
||||
let line_num = 0
|
||||
for line in readfile(file)
|
||||
let line_num = line_num + 1
|
||||
|
||||
let suggestions += s:LatexBox_inlineMath_mathlist(line,inline_pattern1 , line_num) + s:LatexBox_inlineMath_mathlist( line,inline_pattern2, line_num)
|
||||
|
||||
" search for included files
|
||||
let included_file = matchstr(line, '^\\@input{\zs[^}]*\ze}')
|
||||
if included_file != ''
|
||||
let included_file = LatexBox_kpsewhich(included_file)
|
||||
call extend(suggestions, s:LatexBox_inlineMath_completion(a:regex, included_file))
|
||||
endif
|
||||
endfor
|
||||
|
||||
return suggestions
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Search for inline maths {{{
|
||||
" search for $ ... $ and \( ... \) in each line
|
||||
function! s:LatexBox_inlineMath_mathlist(line,inline_pattern, line_num)
|
||||
let col_start = 0
|
||||
let suggestions = []
|
||||
while 1
|
||||
let matches = matchlist(a:line, a:inline_pattern, col_start)
|
||||
if !empty(matches)
|
||||
|
||||
" show line number of inline math
|
||||
let entry = {'word': matches[1], 'menu': '[' . a:line_num . ']'}
|
||||
|
||||
if s:eq_dollar_parenthesis_bracket_empty != ''
|
||||
let entry = copy(entry)
|
||||
let entry.abbr = entry.word
|
||||
let entry.word = entry.word . s:eq_dollar_parenthesis_bracket_empty
|
||||
endif
|
||||
call add(suggestions, entry)
|
||||
|
||||
" update col_start
|
||||
let col_start = matchend(a:line, a:inline_pattern, col_start)
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return suggestions
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Close Current Environment {{{
|
||||
function! s:CloseCurEnv()
|
||||
" first, try with \left/\right pairs
|
||||
let [lnum, cnum] = searchpairpos('\C\\left\>', '', '\C\\right\>', 'bnW', 'LatexBox_InComment()')
|
||||
if lnum
|
||||
let line = strpart(getline(lnum), cnum - 1)
|
||||
let bracket = matchstr(line, '^\\left\zs\((\|\[\|\\{\||\|\.\)\ze')
|
||||
for [open, close] in [['(', ')'], ['\[', '\]'], ['\\{', '\\}'], ['|', '|'], ['\.', '|']]
|
||||
let bracket = substitute(bracket, open, close, 'g')
|
||||
endfor
|
||||
return '\right' . bracket
|
||||
endif
|
||||
|
||||
" second, try with environments
|
||||
let env = LatexBox_GetCurrentEnvironment()
|
||||
if env == '\['
|
||||
return '\]'
|
||||
elseif env == '\('
|
||||
return '\)'
|
||||
elseif env != ''
|
||||
return '\end{' . env . '}'
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Wrap Selection {{{
|
||||
function! s:WrapSelection(wrapper)
|
||||
keepjumps normal! `>a}
|
||||
execute 'keepjumps normal! `<i\' . a:wrapper . '{'
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Wrap Selection in Environment with Prompt {{{
|
||||
function! s:PromptEnvWrapSelection(...)
|
||||
let env = input('environment: ', '', 'customlist,' . s:SIDWrap('GetEnvironmentList'))
|
||||
if empty(env)
|
||||
return
|
||||
endif
|
||||
" LaTeXBox's custom indentation can interfere with environment
|
||||
" insertion when environments are indented (common for nested
|
||||
" environments). Temporarily disable it for this operation:
|
||||
let ieOld = &indentexpr
|
||||
setlocal indentexpr=""
|
||||
if visualmode() ==# 'V'
|
||||
execute 'keepjumps normal! `>o\end{' . env . '}'
|
||||
execute 'keepjumps normal! `<O\begin{' . env . '}'
|
||||
" indent and format, if requested.
|
||||
if a:0 && a:1
|
||||
normal! gv>
|
||||
normal! gvgq
|
||||
endif
|
||||
else
|
||||
execute 'keepjumps normal! `>a\end{' . env . '}'
|
||||
execute 'keepjumps normal! `<i\begin{' . env . '}'
|
||||
endif
|
||||
exe "setlocal indentexpr=" . ieOld
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" List Labels with Prompt {{{
|
||||
function! s:PromptLabelList(...)
|
||||
" Check if window already exists
|
||||
let winnr = bufwinnr(bufnr('LaTeX Labels'))
|
||||
if winnr >= 0
|
||||
if a:0 == 0
|
||||
silent execute winnr . 'wincmd w'
|
||||
else
|
||||
" Supplying an argument to this function causes toggling instead
|
||||
" of jumping to the labels window
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns-=" . g:LatexBox_split_width
|
||||
endif
|
||||
silent execute 'bwipeout' . bufnr('LaTeX Labels')
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
" Get label suggestions
|
||||
let regexp = input('filter labels with regexp: ', '')
|
||||
let labels = s:CompleteLabels(regexp)
|
||||
|
||||
let calling_buf = bufnr('%')
|
||||
|
||||
" Create labels window and set local settings
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns+=" . g:LatexBox_split_width
|
||||
endif
|
||||
silent exe g:LatexBox_split_side g:LatexBox_split_width . 'vnew LaTeX\ Labels'
|
||||
let b:toc = []
|
||||
let b:toc_numbers = 1
|
||||
let b:calling_win = bufwinnr(calling_buf)
|
||||
setlocal filetype=latextoc
|
||||
|
||||
" Add label entries and jump to the closest section
|
||||
for entry in labels
|
||||
let number = matchstr(entry['menu'], '^\s*(\zs[^)]\+\ze)')
|
||||
let page = matchstr(entry['menu'], '^[^)]*)\s*\[\zs[^]]\+\ze\]')
|
||||
let e = {'file': bufname(calling_buf),
|
||||
\ 'level': 'label',
|
||||
\ 'number': number,
|
||||
\ 'text': entry['abbr'],
|
||||
\ 'page': page}
|
||||
call add(b:toc, e)
|
||||
if b:toc_numbers
|
||||
call append('$', e['number'] . "\t" . e['text'])
|
||||
else
|
||||
call append('$', e['text'])
|
||||
endif
|
||||
endfor
|
||||
if !g:LatexBox_toc_hidehelp
|
||||
call append('$', "")
|
||||
call append('$', "<Esc>/q: close")
|
||||
call append('$', "<Space>: jump")
|
||||
call append('$', "<Enter>: jump and close")
|
||||
call append('$', "s: hide numbering")
|
||||
endif
|
||||
0delete _
|
||||
|
||||
" Lock buffer
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Change Environment {{{
|
||||
function! s:ChangeEnvPrompt()
|
||||
|
||||
let [env, lnum, cnum, lnum2, cnum2] = LatexBox_GetCurrentEnvironment(1)
|
||||
|
||||
let new_env = input('change ' . env . ' for: ', '', 'customlist,' . s:SIDWrap('GetEnvironmentList'))
|
||||
if empty(new_env)
|
||||
return
|
||||
endif
|
||||
|
||||
if new_env == '\[' || new_env == '['
|
||||
let begin = '\['
|
||||
let end = '\]'
|
||||
elseif new_env == '\(' || new_env == '('
|
||||
let begin = '\('
|
||||
let end = '\)'
|
||||
else
|
||||
let l:begin = '\begin{' . new_env . '}'
|
||||
let l:end = '\end{' . new_env . '}'
|
||||
endif
|
||||
|
||||
if env == '\[' || env == '\('
|
||||
let line = getline(lnum2)
|
||||
let line = strpart(line, 0, cnum2 - 1) . l:end . strpart(line, cnum2 + 1)
|
||||
call setline(lnum2, line)
|
||||
|
||||
let line = getline(lnum)
|
||||
let line = strpart(line, 0, cnum - 1) . l:begin . strpart(line, cnum + 1)
|
||||
call setline(lnum, line)
|
||||
else
|
||||
let line = getline(lnum2)
|
||||
let line = strpart(line, 0, cnum2 - 1) . l:end . strpart(line, cnum2 + len(env) + 5)
|
||||
call setline(lnum2, line)
|
||||
|
||||
let line = getline(lnum)
|
||||
let line = strpart(line, 0, cnum - 1) . l:begin . strpart(line, cnum + len(env) + 7)
|
||||
call setline(lnum, line)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GetEnvironmentList(lead, cmdline, pos)
|
||||
let suggestions = []
|
||||
for entry in g:LatexBox_completion_environments
|
||||
let env = entry.word
|
||||
if env =~ '^' . a:lead
|
||||
call add(suggestions, env)
|
||||
endif
|
||||
endfor
|
||||
return suggestions
|
||||
endfunction
|
||||
|
||||
function! s:LatexToggleStarEnv()
|
||||
let [env, lnum, cnum, lnum2, cnum2] = LatexBox_GetCurrentEnvironment(1)
|
||||
|
||||
if env == '\('
|
||||
return
|
||||
elseif env == '\['
|
||||
let begin = '\begin{equation}'
|
||||
let end = '\end{equation}'
|
||||
elseif env[-1:] == '*'
|
||||
let begin = '\begin{' . env[:-2] . '}'
|
||||
let end = '\end{' . env[:-2] . '}'
|
||||
else
|
||||
let begin = '\begin{' . env . '*}'
|
||||
let end = '\end{' . env . '*}'
|
||||
endif
|
||||
|
||||
if env == '\['
|
||||
let line = getline(lnum2)
|
||||
let line = strpart(line, 0, cnum2 - 1) . l:end . strpart(line, cnum2 + 1)
|
||||
call setline(lnum2, line)
|
||||
|
||||
let line = getline(lnum)
|
||||
let line = strpart(line, 0, cnum - 1) . l:begin . strpart(line, cnum + 1)
|
||||
call setline(lnum, line)
|
||||
else
|
||||
let line = getline(lnum2)
|
||||
let line = strpart(line, 0, cnum2 - 1) . l:end . strpart(line, cnum2 + len(env) + 5)
|
||||
call setline(lnum2, line)
|
||||
|
||||
let line = getline(lnum)
|
||||
let line = strpart(line, 0, cnum - 1) . l:begin . strpart(line, cnum + len(env) + 7)
|
||||
call setline(lnum, line)
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Next Charaters Match {{{
|
||||
function! s:NextCharsMatch(regex)
|
||||
let rest_of_line = strpart(getline('.'), col('.') - 1)
|
||||
return rest_of_line =~ a:regex
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Mappings {{{
|
||||
inoremap <silent> <Plug>LatexCloseCurEnv <C-R>=<SID>CloseCurEnv()<CR>
|
||||
vnoremap <silent> <Plug>LatexWrapSelection :<c-u>call <SID>WrapSelection('')<CR>i
|
||||
vnoremap <silent> <Plug>LatexEnvWrapSelection :<c-u>call <SID>PromptEnvWrapSelection()<CR>
|
||||
vnoremap <silent> <Plug>LatexEnvWrapFmtSelection :<c-u>call <SID>PromptEnvWrapSelection(1)<CR>
|
||||
nnoremap <silent> <Plug>LatexChangeEnv :call <SID>ChangeEnvPrompt()<CR>
|
||||
nnoremap <silent> <Plug>LatexToggleStarEnv :call <SID>LatexToggleStarEnv()<CR>
|
||||
" }}}
|
||||
|
||||
" Commands {{{
|
||||
command! LatexLabels call <SID>PromptLabelList()
|
||||
" }}}
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,66 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LatexBox_GetMainFileName: gets the name of the main file being compiled. {{{
|
||||
" Description: returns the full path name of the main file.
|
||||
" This function checks for the existence of a .latexmain file
|
||||
" which might point to the location of a "main" latex file.
|
||||
" If .latexmain exists, then return the full path name of the
|
||||
" file being pointed to by it.
|
||||
"
|
||||
" Otherwise, return the full path name of the current buffer.
|
||||
"
|
||||
" You can supply an optional "modifier" argument to the
|
||||
" function, which will optionally modify the file name before
|
||||
" returning.
|
||||
" NOTE: From version 1.6 onwards, this function always trims
|
||||
" away the .latexmain part of the file name before applying the
|
||||
" modifier argument.
|
||||
" NOTE: This function is copied from the Latex-Suite project!
|
||||
function! LatexBox_GetMainFileName(...)
|
||||
if a:0 > 0
|
||||
let modifier = a:1
|
||||
else
|
||||
let modifier = ':p'
|
||||
endif
|
||||
|
||||
let s:origdir = fnameescape(getcwd())
|
||||
|
||||
let dirmodifier = '%:p:h'
|
||||
let dirLast = fnameescape(expand(dirmodifier))
|
||||
exe 'cd '.dirLast
|
||||
|
||||
" move up the directory tree until we find a .latexmain file.
|
||||
" TODO: Should we be doing this recursion by default, or should there be a
|
||||
" setting?
|
||||
while glob('*.latexmain',1) == ''
|
||||
let dirmodifier = dirmodifier.':h'
|
||||
let dirNew = fnameescape(expand(dirmodifier))
|
||||
" break from the loop if we cannot go up any further.
|
||||
if dirNew == dirLast
|
||||
break
|
||||
endif
|
||||
let dirLast = dirNew
|
||||
exe 'cd '.dirLast
|
||||
endwhile
|
||||
|
||||
let lheadfile = glob('*.latexmain',1)
|
||||
if lheadfile != ''
|
||||
" Remove the trailing .latexmain part of the filename... We never want
|
||||
" that.
|
||||
let lheadfile = fnamemodify(substitute(lheadfile, '\.latexmain$', '', ''), modifier)
|
||||
else
|
||||
" If we cannot find any main file, just modify the filename of the
|
||||
" current buffer.
|
||||
let lheadfile = expand('%'.modifier)
|
||||
endif
|
||||
|
||||
exe 'cd '.s:origdir
|
||||
|
||||
" NOTE: The caller of this function needs to escape the file name with
|
||||
" fnameescape() . The reason its not done here is that escaping is not
|
||||
" safe if this file is to be used as part of an external command on
|
||||
" certain platforms.
|
||||
return lheadfile
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -1,382 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" Folding support for LaTeX
|
||||
|
||||
"
|
||||
" Options
|
||||
" g:LatexBox_Folding - Turn on/off folding
|
||||
" g:LatexBox_fold_text - Turn on/off LatexBox fold text function
|
||||
" g:LatexBox_fold_preamble - Turn on/off folding of preamble
|
||||
" g:LatexBox_fold_parts - Define parts (eq. appendix, frontmatter) to fold
|
||||
" g:LatexBox_fold_sections - Define section levels to fold
|
||||
" g:LatexBox_fold_envs - Turn on/off folding of environments
|
||||
" g:LatexBox_fold_toc - Turn on/off folding of TOC
|
||||
" g:LatexBox_fold_toc_levels - Set max TOC fold level
|
||||
"
|
||||
" {{{1 Initialize options to default values.
|
||||
if !exists('g:LatexBox_Folding')
|
||||
let g:LatexBox_Folding=0
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_text')
|
||||
let g:LatexBox_fold_text=1
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_preamble')
|
||||
let g:LatexBox_fold_preamble=1
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_envs')
|
||||
let g:LatexBox_fold_envs=1
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_envs_force')
|
||||
let g:LatexBox_fold_envs_force = []
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_parts')
|
||||
let g:LatexBox_fold_parts=[
|
||||
\ "appendix",
|
||||
\ "frontmatter",
|
||||
\ "mainmatter",
|
||||
\ "backmatter"
|
||||
\ ]
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_sections')
|
||||
let g:LatexBox_fold_sections=[
|
||||
\ "part",
|
||||
\ "chapter",
|
||||
\ "section",
|
||||
\ "subsection",
|
||||
\ "subsubsection"
|
||||
\ ]
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_toc')
|
||||
let g:LatexBox_fold_toc=0
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_toc_levels')
|
||||
let g:LatexBox_fold_toc_levels=1
|
||||
endif
|
||||
if !exists('g:LatexBox_fold_automatic')
|
||||
let g:LatexBox_fold_automatic=1
|
||||
endif
|
||||
" }}}1
|
||||
|
||||
if g:LatexBox_Folding == 0
|
||||
finish
|
||||
endif
|
||||
|
||||
" {{{1 Set folding options for vim
|
||||
setl foldexpr=LatexBox_FoldLevel(v:lnum)
|
||||
if g:LatexBox_fold_text == 1
|
||||
setl foldtext=LatexBox_FoldText()
|
||||
endif
|
||||
if g:LatexBox_fold_automatic == 1
|
||||
setl foldmethod=expr
|
||||
|
||||
"
|
||||
" The foldexpr function returns "=" for most lines, which means it can become
|
||||
" slow for large files. The following is a hack that is based on this reply to
|
||||
" a discussion on the Vim Developer list:
|
||||
" http://permalink.gmane.org/gmane.editors.vim.devel/14100
|
||||
"
|
||||
augroup FastFold
|
||||
autocmd!
|
||||
autocmd InsertEnter *.tex if !&diff | setlocal foldmethod=manual | endif
|
||||
autocmd InsertLeave *.tex if !&diff | setlocal foldmethod=expr | endif
|
||||
augroup end
|
||||
else
|
||||
setl foldmethod=manual
|
||||
endif
|
||||
|
||||
function! LatexBox_FoldOnDemand()
|
||||
setl foldmethod=expr
|
||||
normal! zx
|
||||
setl foldmethod=manual
|
||||
endfunction
|
||||
|
||||
command! LatexFold call LatexBox_FoldOnDemand()
|
||||
|
||||
" {{{1 LatexBox_FoldLevel help functions
|
||||
|
||||
" This function parses the tex file to find the sections that are to be folded
|
||||
" and their levels, and then predefines the patterns for optimized folding.
|
||||
function! s:FoldSectionLevels()
|
||||
" Initialize
|
||||
let level = 1
|
||||
let foldsections = []
|
||||
|
||||
" If we use two or more of the *matter commands, we need one more foldlevel
|
||||
let nparts = 0
|
||||
for part in g:LatexBox_fold_parts
|
||||
let i = 1
|
||||
while i < line("$")
|
||||
if getline(i) =~ '^\s*\\' . part . '\>'
|
||||
let nparts += 1
|
||||
break
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
if nparts > 1
|
||||
let level = 2
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Combine sections and levels, but ignore unused section commands: If we
|
||||
" don't use the part command, then chapter should have the highest
|
||||
" level. If we don't use the chapter command, then section should be the
|
||||
" highest level. And so on.
|
||||
let ignore = 1
|
||||
for part in g:LatexBox_fold_sections
|
||||
" For each part, check if it is used in the file. We start adding the
|
||||
" part patterns to the fold sections array whenever we find one.
|
||||
let partpattern = '^\s*\(\\\|% Fake\)' . part . '\>'
|
||||
if ignore
|
||||
let i = 1
|
||||
while i < line("$")
|
||||
if getline(i) =~# partpattern
|
||||
call insert(foldsections, [partpattern, level])
|
||||
let level += 1
|
||||
let ignore = 0
|
||||
break
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
else
|
||||
call insert(foldsections, [partpattern, level])
|
||||
let level += 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return foldsections
|
||||
endfunction
|
||||
|
||||
" {{{1 LatexBox_FoldLevel
|
||||
|
||||
" Parse file to dynamically set the sectioning fold levels
|
||||
let b:LatexBox_FoldSections = s:FoldSectionLevels()
|
||||
|
||||
" Optimize by predefine common patterns
|
||||
let s:notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
|
||||
let s:notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
let s:envbeginpattern = s:notcomment . s:notbslash . '\\begin\s*{.\{-}}'
|
||||
let s:envendpattern = s:notcomment . s:notbslash . '\\end\s*{.\{-}}'
|
||||
let s:foldparts = '^\s*\\\%(' . join(g:LatexBox_fold_parts, '\|') . '\)'
|
||||
let s:folded = '\(% Fake\|\\\(document\|begin\|end\|paragraph\|'
|
||||
\ . 'front\|main\|back\|app\|sub\|section\|chapter\|part\)\)'
|
||||
|
||||
function! LatexBox_FoldLevel(lnum)
|
||||
" Check for normal lines first (optimization)
|
||||
let line = getline(a:lnum)
|
||||
if line !~ s:folded
|
||||
return "="
|
||||
endif
|
||||
|
||||
" Fold preamble
|
||||
if g:LatexBox_fold_preamble == 1
|
||||
if line =~# s:notcomment . s:notbslash . '\s*\\documentclass'
|
||||
return ">1"
|
||||
elseif line =~# s:notcomment . s:notbslash . '\s*\\begin\s*{\s*document\s*}'
|
||||
return "0"
|
||||
endif
|
||||
endif
|
||||
|
||||
" Fold parts (\frontmatter, \mainmatter, \backmatter, and \appendix)
|
||||
if line =~# s:foldparts
|
||||
return ">1"
|
||||
endif
|
||||
|
||||
" Fold chapters and sections
|
||||
for [part, level] in b:LatexBox_FoldSections
|
||||
if line =~# part
|
||||
return ">" . level
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Never fold \end{document}
|
||||
if line =~# '^\s*\\end{document}'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Fold environments
|
||||
if line =~# s:envbeginpattern && line =~# s:envendpattern
|
||||
" If the begin and end pattern are on the same line , do not fold
|
||||
return "="
|
||||
else
|
||||
if line =~# s:envbeginpattern
|
||||
if g:LatexBox_fold_envs == 1
|
||||
return "a1"
|
||||
else
|
||||
let env = matchstr(line,'\\begin\*\?{\zs\w*\*\?\ze}')
|
||||
if index(g:LatexBox_fold_envs_force, env) >= 0
|
||||
return "a1"
|
||||
else
|
||||
return "="
|
||||
endif
|
||||
endif
|
||||
elseif line =~# s:envendpattern
|
||||
if g:LatexBox_fold_envs == 1
|
||||
return "s1"
|
||||
else
|
||||
let env = matchstr(line,'\\end\*\?{\zs\w*\*\?\ze}')
|
||||
if index(g:LatexBox_fold_envs_force, env) >= 0
|
||||
return "s1"
|
||||
else
|
||||
return "="
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" Return foldlevel of previous line
|
||||
return "="
|
||||
endfunction
|
||||
|
||||
" {{{1 LatexBox_FoldText help functions
|
||||
function! s:LabelEnv()
|
||||
let i = v:foldend
|
||||
while i >= v:foldstart
|
||||
if getline(i) =~ '^\s*\\label'
|
||||
return matchstr(getline(i), '^\s*\\label{\zs.*\ze}')
|
||||
end
|
||||
let i -= 1
|
||||
endwhile
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! s:CaptionEnv()
|
||||
let i = v:foldend
|
||||
while i >= v:foldstart
|
||||
if getline(i) =~ '^\s*\\caption'
|
||||
return matchstr(getline(i), '^\s*\\caption\(\[.*\]\)\?{\zs.\+')
|
||||
end
|
||||
let i -= 1
|
||||
endwhile
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! s:CaptionTable()
|
||||
let i = v:foldstart
|
||||
while i <= v:foldend
|
||||
if getline(i) =~ '^\s*\\caption'
|
||||
return matchstr(getline(i), '^\s*\\caption\(\[.*\]\)\?{\zs.\+')
|
||||
end
|
||||
let i += 1
|
||||
endwhile
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! s:CaptionFrame(line)
|
||||
" Test simple variants first
|
||||
let caption1 = matchstr(a:line,'\\begin\*\?{.*}{\zs.\+\ze}')
|
||||
let caption2 = matchstr(a:line,'\\begin\*\?{.*}{\zs.\+')
|
||||
|
||||
if len(caption1) > 0
|
||||
return caption1
|
||||
elseif len(caption2) > 0
|
||||
return caption2
|
||||
else
|
||||
let i = v:foldstart
|
||||
while i <= v:foldend
|
||||
if getline(i) =~ '^\s*\\frametitle'
|
||||
return matchstr(getline(i),
|
||||
\ '^\s*\\frametitle\(\[.*\]\)\?{\zs.\+')
|
||||
end
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
return ""
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! LatexBox_FoldText_title()
|
||||
let line = getline(v:foldstart)
|
||||
let title = 'Not defined'
|
||||
|
||||
" Preamble
|
||||
if line =~ '\s*\\documentclass'
|
||||
return "Preamble"
|
||||
endif
|
||||
|
||||
" Parts, sections and fakesections
|
||||
let sections = '\(\(sub\)*\(section\|paragraph\)\|part\|chapter\)'
|
||||
let secpat1 = '^\s*\\' . sections . '\*\?\s*{'
|
||||
let secpat2 = '^\s*\\' . sections . '\*\?\s*\['
|
||||
if line =~ '\\frontmatter'
|
||||
let title = "Frontmatter"
|
||||
elseif line =~ '\\mainmatter'
|
||||
let title = "Mainmatter"
|
||||
elseif line =~ '\\backmatter'
|
||||
let title = "Backmatter"
|
||||
elseif line =~ '\\appendix'
|
||||
let title = "Appendix"
|
||||
elseif line =~ secpat1 . '.*}'
|
||||
let title = matchstr(line, secpat1 . '\zs.\{-}\ze}')
|
||||
elseif line =~ secpat1
|
||||
let title = matchstr(line, secpat1 . '\zs.*')
|
||||
elseif line =~ secpat2 . '.*\]'
|
||||
let title = matchstr(line, secpat2 . '\zs.\{-}\ze\]')
|
||||
elseif line =~ secpat2
|
||||
let title = matchstr(line, secpat2 . '\zs.*')
|
||||
elseif line =~ 'Fake' . sections . ':'
|
||||
let title = matchstr(line,'Fake' . sections . ':\s*\zs.*')
|
||||
elseif line =~ 'Fake' . sections
|
||||
let title = matchstr(line, 'Fake' . sections)
|
||||
endif
|
||||
|
||||
" Environments
|
||||
if line =~ '\\begin'
|
||||
" Capture environment name
|
||||
let env = matchstr(line,'\\begin\*\?{\zs\w*\*\?\ze}')
|
||||
|
||||
" Set caption based on type of environment
|
||||
if env == 'frame'
|
||||
let label = ''
|
||||
let caption = s:CaptionFrame(line)
|
||||
elseif env == 'table'
|
||||
let label = s:LabelEnv()
|
||||
let caption = s:CaptionTable()
|
||||
else
|
||||
let label = s:LabelEnv()
|
||||
let caption = s:CaptionEnv()
|
||||
endif
|
||||
|
||||
" If no caption found, check for a caption comment
|
||||
if caption == ''
|
||||
let caption = matchstr(line,'\\begin\*\?{.*}\s*%\s*\zs.*')
|
||||
endif
|
||||
|
||||
" Create title based on caption and label
|
||||
if caption . label == ''
|
||||
let title = env
|
||||
elseif label == ''
|
||||
let title = printf('%-12s%s', env . ':',
|
||||
\ substitute(caption, '}\s*$', '',''))
|
||||
elseif caption == ''
|
||||
let title = printf('%-12s%56s', env, '(' . label . ')')
|
||||
else
|
||||
let title = printf('%-12s%-30s %21s', env . ':',
|
||||
\ strpart(substitute(caption, '}\s*$', '',''),0,34),
|
||||
\ '(' . label . ')')
|
||||
endif
|
||||
endif
|
||||
|
||||
return title
|
||||
endfunction
|
||||
|
||||
" {{{1 LatexBox_FoldText
|
||||
function! LatexBox_FoldText()
|
||||
let nlines = v:foldend - v:foldstart + 1
|
||||
let title = strpart(LatexBox_FoldText_title(), 0, 68)
|
||||
let level = ''
|
||||
|
||||
" Fold level
|
||||
let level = strpart(repeat('-', v:foldlevel-1) . '*',0,3)
|
||||
if v:foldlevel > 3
|
||||
let level = strpart(level, 1) . v:foldlevel
|
||||
endif
|
||||
let level = printf('%-3s', level)
|
||||
|
||||
return printf('%-3s %-68s #%5d', level, title, nlines)
|
||||
endfunction
|
||||
|
||||
" {{{1 Footer
|
||||
" vim:fdm=marker:ff=unix:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,558 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box latexmk functions
|
||||
|
||||
" Options and variables {{{
|
||||
|
||||
if !exists('g:LatexBox_latexmk_options')
|
||||
let g:LatexBox_latexmk_options = ''
|
||||
endif
|
||||
if !exists('g:LatexBox_latexmk_env')
|
||||
let g:LatexBox_latexmk_env = ''
|
||||
endif
|
||||
if !exists('g:LatexBox_latexmk_async')
|
||||
let g:LatexBox_latexmk_async = 0
|
||||
endif
|
||||
if !exists('g:LatexBox_latexmk_preview_continuously')
|
||||
let g:LatexBox_latexmk_preview_continuously = 0
|
||||
endif
|
||||
if !exists('g:LatexBox_output_type')
|
||||
let g:LatexBox_output_type = 'pdf'
|
||||
endif
|
||||
if !exists('g:LatexBox_autojump')
|
||||
let g:LatexBox_autojump = 0
|
||||
endif
|
||||
if ! exists('g:LatexBox_quickfix')
|
||||
let g:LatexBox_quickfix = 1
|
||||
endif
|
||||
if ! exists('g:LatexBox_personal_latexmkrc')
|
||||
let g:LatexBox_personal_latexmkrc = 0
|
||||
endif
|
||||
|
||||
" }}}
|
||||
|
||||
" Process ID management (used for asynchronous and continuous mode) {{{
|
||||
|
||||
" A dictionary of latexmk PID's (basename: pid)
|
||||
if !exists('g:latexmk_running_pids')
|
||||
let g:latexmk_running_pids = {}
|
||||
endif
|
||||
|
||||
" Set PID {{{
|
||||
function! s:LatexmkSetPID(basename, pid)
|
||||
let g:latexmk_running_pids[a:basename] = a:pid
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" kill_latexmk_process {{{
|
||||
function! s:kill_latexmk_process(pid)
|
||||
if has('win32')
|
||||
silent execute '!taskkill /PID ' . a:pid . ' /T /F'
|
||||
else
|
||||
if g:LatexBox_latexmk_async
|
||||
" vim-server mode
|
||||
let pids = []
|
||||
let tmpfile = tempname()
|
||||
silent execute '!ps x -o pgid,pid > ' . tmpfile
|
||||
for line in readfile(tmpfile)
|
||||
let new_pid = matchstr(line, '^\s*' . a:pid . '\s\+\zs\d\+\ze')
|
||||
if !empty(new_pid)
|
||||
call add(pids, new_pid)
|
||||
endif
|
||||
endfor
|
||||
call delete(tmpfile)
|
||||
if !empty(pids)
|
||||
silent execute '!kill ' . join(pids)
|
||||
endif
|
||||
else
|
||||
" single background process
|
||||
silent execute '!kill ' . a:pid
|
||||
endif
|
||||
endif
|
||||
if !has('gui_running')
|
||||
redraw!
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" kill_all_latexmk_processes {{{
|
||||
function! s:kill_all_latexmk_processes()
|
||||
for pid in values(g:latexmk_running_pids)
|
||||
call s:kill_latexmk_process(pid)
|
||||
endfor
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" Setup for vim-server {{{
|
||||
function! s:SIDWrap(func)
|
||||
if !exists('s:SID')
|
||||
let s:SID = matchstr(expand('<sfile>'), '\zs<SNR>\d\+_\ze.*$')
|
||||
endif
|
||||
return s:SID . a:func
|
||||
endfunction
|
||||
|
||||
function! s:LatexmkCallback(basename, status)
|
||||
" Only remove the pid if not in continuous mode
|
||||
if !g:LatexBox_latexmk_preview_continuously
|
||||
call remove(g:latexmk_running_pids, a:basename)
|
||||
endif
|
||||
call LatexBox_LatexErrors(a:status, a:basename)
|
||||
endfunction
|
||||
|
||||
function! s:setup_vim_server()
|
||||
if !exists('g:vim_program')
|
||||
|
||||
" attempt autodetection of vim executable
|
||||
let g:vim_program = ''
|
||||
if has('win32')
|
||||
" Just drop through to the default for windows
|
||||
else
|
||||
if match(&shell, '\(bash\|zsh\)$') >= 0
|
||||
let ppid = '$PPID'
|
||||
else
|
||||
let ppid = '$$'
|
||||
endif
|
||||
|
||||
let tmpfile = tempname()
|
||||
silent execute '!ps -o command= -p ' . ppid . ' > ' . tmpfile
|
||||
for line in readfile(tmpfile)
|
||||
let line = matchstr(line, '^\S\+\>')
|
||||
if !empty(line) && executable(line)
|
||||
let g:vim_program = line . ' -g'
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
call delete(tmpfile)
|
||||
endif
|
||||
|
||||
if empty(g:vim_program)
|
||||
if has('gui_macvim')
|
||||
let g:vim_program
|
||||
\ = '/Applications/MacVim.app/Contents/MacOS/Vim -g'
|
||||
else
|
||||
let g:vim_program = v:progname
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Latexmk {{{
|
||||
|
||||
function! LatexBox_Latexmk(force)
|
||||
" Define often used names
|
||||
let basepath = LatexBox_GetBuildBasename(1)
|
||||
let basename = fnamemodify(basepath, ':t')
|
||||
let texroot = shellescape(LatexBox_GetTexRoot())
|
||||
let mainfile = fnameescape(fnamemodify(LatexBox_GetMainTexFile(), ':t'))
|
||||
|
||||
" Check if latexmk is installed
|
||||
if !executable('latexmk')
|
||||
echomsg "Error: LaTeX-Box relies on latexmk for compilation, but it" .
|
||||
\ " is not installed!"
|
||||
return
|
||||
endif
|
||||
|
||||
" Check if already running
|
||||
if has_key(g:latexmk_running_pids, basepath)
|
||||
echomsg "latexmk is already running for `" . basename . "'"
|
||||
return
|
||||
endif
|
||||
|
||||
" Set wrap width in log file
|
||||
let max_print_line = 2000
|
||||
if has('win32')
|
||||
let env = 'set max_print_line=' . max_print_line . ' & '
|
||||
elseif match(&shell, '/tcsh$') >= 0
|
||||
let env = 'setenv max_print_line ' . max_print_line . '; '
|
||||
else
|
||||
if fnamemodify(&shell, ':t') ==# 'fish'
|
||||
let env = 'set max_print_line ' . max_print_line . '; and '
|
||||
else
|
||||
let env = 'max_print_line=' . max_print_line
|
||||
endif
|
||||
endif
|
||||
|
||||
" Set environment options
|
||||
let env .= ' ' . g:LatexBox_latexmk_env . ' '
|
||||
|
||||
" Set latexmk command with options
|
||||
if has('win32')
|
||||
" Make sure to switch drive as well as directory
|
||||
let cmd = 'cd /D ' . texroot . ' && '
|
||||
else
|
||||
if fnamemodify(&shell, ':t') ==# 'fish'
|
||||
let cmd = 'cd ' . texroot . '; and '
|
||||
else
|
||||
let cmd = 'cd ' . texroot . ' && '
|
||||
endif
|
||||
endif
|
||||
let cmd .= env . ' latexmk'
|
||||
if ! g:LatexBox_personal_latexmkrc
|
||||
let cmd .= ' -' . g:LatexBox_output_type
|
||||
endif
|
||||
let cmd .= ' -quiet '
|
||||
let cmd .= g:LatexBox_latexmk_options
|
||||
if a:force
|
||||
let cmd .= ' -g'
|
||||
endif
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
let cmd .= ' -pvc'
|
||||
endif
|
||||
let cmd .= ' -e ' . shellescape('$pdflatex =~ s/ / -file-line-error /')
|
||||
let cmd .= ' -e ' . shellescape('$latex =~ s/ / -file-line-error /')
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
let cmd .= ' -e ' . shellescape('$success_cmd = $ENV{SUCCESSCMD}')
|
||||
let cmd .= ' -e ' . shellescape('$failure_cmd = $ENV{FAILURECMD}')
|
||||
endif
|
||||
let cmd .= ' ' . mainfile
|
||||
|
||||
" Redirect output to null
|
||||
if has('win32')
|
||||
let cmd .= ' >nul'
|
||||
else
|
||||
if fnamemodify(&shell, ':t') ==# 'fish'
|
||||
let cmd .= ' >/dev/null ^/dev/null'
|
||||
else
|
||||
let cmd .= ' &>/dev/null'
|
||||
endif
|
||||
endif
|
||||
|
||||
if g:LatexBox_latexmk_async
|
||||
" Check if VIM server exists
|
||||
if empty(v:servername)
|
||||
echoerr "cannot run latexmk in background without a VIM server"
|
||||
echoerr "set g:LatexBox_latexmk_async to 0 to change compiling mode"
|
||||
return
|
||||
endif
|
||||
|
||||
" Start vim server if necessary
|
||||
call s:setup_vim_server()
|
||||
|
||||
let setpidfunc = s:SIDWrap('LatexmkSetPID')
|
||||
let callbackfunc = s:SIDWrap('LatexmkCallback')
|
||||
if has('win32')
|
||||
let vim_program = substitute(g:vim_program,
|
||||
\ 'gvim\.exe$', 'vim.exe', '')
|
||||
|
||||
" Define callback to set the pid
|
||||
let callsetpid = setpidfunc . '(''' . basepath . ''', %CMDPID%)'
|
||||
let vimsetpid = vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . shellescape(callsetpid)
|
||||
|
||||
" Define callback after latexmk is finished
|
||||
let callback = callbackfunc . '(''' . basepath . ''', %LATEXERR%)'
|
||||
let vimcmd = vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . shellescape(callback)
|
||||
let scallback = callbackfunc . '(''' . basepath . ''', 0)'
|
||||
let svimcmd = vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . shellescape(scallback)
|
||||
let fcallback = callbackfunc . '(''' . basepath . ''', 1)'
|
||||
let fvimcmd = vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . shellescape(fcallback)
|
||||
|
||||
let asyncbat = tempname() . '.bat'
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
call writefile(['setlocal',
|
||||
\ 'set T=%TEMP%\sthUnique.tmp',
|
||||
\ 'wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") '
|
||||
\ . 'get ParentProcessId /value | find "ParentProcessId" >%T%',
|
||||
\ 'set /P A=<%T%',
|
||||
\ 'set CMDPID=%A:~16% & del %T%',
|
||||
\ vimsetpid,
|
||||
\ 'set SUCCESSCMD='.svimcmd,
|
||||
\ 'set FAILURECMD='.fvimcmd,
|
||||
\ cmd,
|
||||
\ 'endlocal'], asyncbat)
|
||||
else
|
||||
call writefile(['setlocal',
|
||||
\ 'set T=%TEMP%\sthUnique.tmp',
|
||||
\ 'wmic process where (Name="WMIC.exe" AND CommandLine LIKE "%%%TIME%%%") '
|
||||
\ . 'get ParentProcessId /value | find "ParentProcessId" >%T%',
|
||||
\ 'set /P A=<%T%',
|
||||
\ 'set CMDPID=%A:~16% & del %T%',
|
||||
\ vimsetpid,
|
||||
\ cmd,
|
||||
\ 'set LATEXERR=%ERRORLEVEL%',
|
||||
\ vimcmd,
|
||||
\ 'endlocal'], asyncbat)
|
||||
endif
|
||||
|
||||
" Define command
|
||||
let cmd = '!start /b ' . asyncbat . ' & del ' . asyncbat
|
||||
else
|
||||
" Define callback to set the pid
|
||||
let callsetpid = shellescape(setpidfunc).'"(\"'.basepath.'\",$$)"'
|
||||
let vimsetpid = g:vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . callsetpid
|
||||
|
||||
" Define callback after latexmk is finished
|
||||
let callback = shellescape(callbackfunc).'"(\"'.basepath.'\",$?)"'
|
||||
let vimcmd = g:vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . callback
|
||||
let scallback = shellescape(callbackfunc).'"(\"'.basepath.'\",0)"'
|
||||
let svimcmd = g:vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . scallback
|
||||
let fcallback = shellescape(callbackfunc).'"(\"'.basepath.'\",1)"'
|
||||
let fvimcmd = g:vim_program . ' --servername ' . v:servername
|
||||
\ . ' --remote-expr ' . fcallback
|
||||
|
||||
" Define command
|
||||
" Note: Here we escape '%' because it may be given as a user option
|
||||
" through g:LatexBox_latexmk_options, for instance with
|
||||
" g:Latex..._options = "-pdflatex='pdflatex -synctex=1 \%O \%S'"
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
let cmd = vimsetpid . ' ; '
|
||||
\ . 'export SUCCESSCMD=' . shellescape(svimcmd) . ' '
|
||||
\ . ' FAILURECMD=' . shellescape(fvimcmd) . ' ; '
|
||||
\ . escape(cmd, '%')
|
||||
else
|
||||
let cmd = vimsetpid . ' ; ' . escape(cmd, '%') . ' ; ' . vimcmd
|
||||
endif
|
||||
let cmd = '! (' . cmd . ') >/dev/null &'
|
||||
endif
|
||||
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
echo 'Compiling to ' . g:LatexBox_output_type
|
||||
\ . ' with continuous preview.'
|
||||
else
|
||||
echo 'Compiling to ' . g:LatexBox_output_type . ' ...'
|
||||
endif
|
||||
silent execute cmd
|
||||
else
|
||||
if g:LatexBox_latexmk_preview_continuously
|
||||
if has('win32')
|
||||
let cmd = '!start /b cmd /s /c "' . cmd . '"'
|
||||
else
|
||||
let cmd = '!' . cmd . ' &'
|
||||
endif
|
||||
echo 'Compiling to ' . g:LatexBox_output_type . ' ...'
|
||||
silent execute cmd
|
||||
|
||||
" Save PID in order to be able to kill the process when wanted.
|
||||
if has('win32')
|
||||
let tmpfile = tempname()
|
||||
let pidcmd = 'cmd /c "wmic process where '
|
||||
\ . '(CommandLine LIKE "latexmk\%'.mainfile.'\%") '
|
||||
\ . 'get ProcessId /value | find "ProcessId" '
|
||||
\ . '>'.tmpfile.' "'
|
||||
silent execute '! ' . pidcmd
|
||||
let pids = readfile(tmpfile)
|
||||
let pid = strpart(pids[0], 10)
|
||||
let g:latexmk_running_pids[basepath] = pid
|
||||
else
|
||||
let pid = substitute(system('pgrep -f "perl.*'
|
||||
\ . mainfile . '" | head -n 1'),'\D','','')
|
||||
let g:latexmk_running_pids[basepath] = pid
|
||||
endif
|
||||
else
|
||||
" Execute command and check for errors
|
||||
echo 'Compiling to ' . g:LatexBox_output_type . ' ... (async off!)'
|
||||
call system(cmd)
|
||||
call LatexBox_LatexErrors(v:shell_error)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Redraw screen if necessary
|
||||
if !has("gui_running")
|
||||
redraw!
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" LatexmkClean {{{
|
||||
function! LatexBox_LatexmkClean(cleanall)
|
||||
" Check if latexmk is installed
|
||||
if !executable('latexmk')
|
||||
echomsg "Error: LaTeX-Box relies on latexmk for compilation, but it" .
|
||||
\ " is not installed!"
|
||||
return
|
||||
endif
|
||||
|
||||
let basename = LatexBox_GetBuildBasename(1)
|
||||
|
||||
if has_key(g:latexmk_running_pids, basename)
|
||||
echomsg "don't clean when latexmk is running"
|
||||
return
|
||||
endif
|
||||
|
||||
if has('win32')
|
||||
let cmd = 'cd /D ' . shellescape(LatexBox_GetTexRoot()) . ' & '
|
||||
else
|
||||
let cmd = 'cd ' . shellescape(LatexBox_GetTexRoot()) . ';'
|
||||
endif
|
||||
if a:cleanall
|
||||
let cmd .= 'latexmk -C '
|
||||
else
|
||||
let cmd .= 'latexmk -c '
|
||||
endif
|
||||
let cmd .= shellescape(LatexBox_GetMainTexFile())
|
||||
if has('win32')
|
||||
let cmd .= ' >nul'
|
||||
else
|
||||
let cmd .= ' >&/dev/null'
|
||||
endif
|
||||
|
||||
call system(cmd)
|
||||
if !has('gui_running')
|
||||
redraw!
|
||||
endif
|
||||
|
||||
echomsg "latexmk clean finished"
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" LatexErrors {{{
|
||||
function! LatexBox_LatexErrors(status, ...)
|
||||
if a:0 >= 1
|
||||
let log = a:1 . '.log'
|
||||
else
|
||||
let log = LatexBox_GetLogFile()
|
||||
endif
|
||||
|
||||
cclose
|
||||
|
||||
" set cwd to expand error file correctly
|
||||
let l:cwd = fnamemodify(getcwd(), ':p')
|
||||
execute 'lcd ' . fnameescape(LatexBox_GetTexRoot())
|
||||
try
|
||||
if g:LatexBox_autojump
|
||||
execute 'cfile ' . fnameescape(log)
|
||||
else
|
||||
execute 'cgetfile ' . fnameescape(log)
|
||||
endif
|
||||
finally
|
||||
" restore cwd
|
||||
execute 'lcd ' . fnameescape(l:cwd)
|
||||
endtry
|
||||
|
||||
" Always open window if started by LatexErrors command
|
||||
if a:status < 0
|
||||
botright copen
|
||||
else
|
||||
" Only open window when an error/warning is detected
|
||||
if g:LatexBox_quickfix >= 3
|
||||
\ ? s:log_contains_error(log)
|
||||
\ : g:LatexBox_quickfix > 0
|
||||
belowright cw
|
||||
if g:LatexBox_quickfix == 2 || g:LatexBox_quickfix == 4
|
||||
wincmd p
|
||||
endif
|
||||
endif
|
||||
redraw
|
||||
|
||||
" Write status message to screen
|
||||
if a:status > 0 || len(getqflist())>1
|
||||
if s:log_contains_error(log)
|
||||
let l:status_msg = ' ... failed!'
|
||||
else
|
||||
let l:status_msg = ' ... there were warnings!'
|
||||
endif
|
||||
else
|
||||
let l:status_msg = ' ... success!'
|
||||
endif
|
||||
echomsg 'Compiling to ' . g:LatexBox_output_type . l:status_msg
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Redefine uniq() for compatibility with older Vim versions (< 7.4.218)
|
||||
function! s:uniq(list)
|
||||
if exists('*uniq')
|
||||
return uniq(a:list)
|
||||
elseif len(a:list) <= 1
|
||||
return a:list
|
||||
endif
|
||||
|
||||
let last_element = get(a:list,0)
|
||||
let uniq_list = [last_element]
|
||||
|
||||
for i in range(1, len(a:list)-1)
|
||||
let next_element = get(a:list, i)
|
||||
if last_element == next_element
|
||||
continue
|
||||
endif
|
||||
let last_element = next_element
|
||||
call add(uniq_list, next_element)
|
||||
endfor
|
||||
return uniq_list
|
||||
endfunction
|
||||
|
||||
function! s:log_contains_error(file)
|
||||
let lines = readfile(a:file)
|
||||
let lines = filter(lines, 'v:val =~ ''^.*:\d\+: ''')
|
||||
let lines = s:uniq(map(lines, 'matchstr(v:val, ''^.*\ze:\d\+:'')'))
|
||||
let lines = filter(lines, 'filereadable(fnameescape(v:val))')
|
||||
return len(lines) > 0
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" LatexmkStatus {{{
|
||||
function! LatexBox_LatexmkStatus(detailed)
|
||||
if a:detailed
|
||||
if empty(g:latexmk_running_pids)
|
||||
echo "latexmk is not running"
|
||||
else
|
||||
let plist = ""
|
||||
for [basename, pid] in items(g:latexmk_running_pids)
|
||||
if !empty(plist)
|
||||
let plist .= '; '
|
||||
endif
|
||||
let plist .= fnamemodify(basename, ':t') . ':' . pid
|
||||
endfor
|
||||
echo "latexmk is running (" . plist . ")"
|
||||
endif
|
||||
else
|
||||
let basename = LatexBox_GetBuildBasename(1)
|
||||
if has_key(g:latexmk_running_pids, basename)
|
||||
echo "latexmk is running"
|
||||
else
|
||||
echo "latexmk is not running"
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" LatexmkStop {{{
|
||||
function! LatexBox_LatexmkStop(silent)
|
||||
if empty(g:latexmk_running_pids)
|
||||
if !a:silent
|
||||
let basepath = LatexBox_GetBuildBasename(1)
|
||||
let basename = fnamemodify(basepath, ':t')
|
||||
echoerr "latexmk is not running for `" . basename . "'"
|
||||
endif
|
||||
else
|
||||
let basepath = LatexBox_GetBuildBasename(1)
|
||||
let basename = fnamemodify(basepath, ':t')
|
||||
if has_key(g:latexmk_running_pids, basepath)
|
||||
call s:kill_latexmk_process(g:latexmk_running_pids[basepath])
|
||||
call remove(g:latexmk_running_pids, basepath)
|
||||
if !a:silent
|
||||
echomsg "latexmk stopped for `" . basename . "'"
|
||||
endif
|
||||
elseif !a:silent
|
||||
echoerr "latexmk is not running for `" . basename . "'"
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Commands {{{
|
||||
|
||||
command! -bang Latexmk call LatexBox_Latexmk(<q-bang> == "!")
|
||||
command! -bang LatexmkClean call LatexBox_LatexmkClean(<q-bang> == "!")
|
||||
command! -bang LatexmkStatus call LatexBox_LatexmkStatus(<q-bang> == "!")
|
||||
command! LatexmkStop call LatexBox_LatexmkStop(0)
|
||||
command! LatexErrors call LatexBox_LatexErrors(-1)
|
||||
|
||||
if g:LatexBox_latexmk_async || g:LatexBox_latexmk_preview_continuously
|
||||
autocmd BufUnload <buffer> call LatexBox_LatexmkStop(1)
|
||||
autocmd VimLeave * call <SID>kill_all_latexmk_processes()
|
||||
endif
|
||||
|
||||
" }}}
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,110 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box mappings
|
||||
|
||||
if exists("g:LatexBox_no_mappings")
|
||||
finish
|
||||
endif
|
||||
|
||||
" latexmk {{{
|
||||
noremap <buffer> <LocalLeader>ll :Latexmk<CR>
|
||||
noremap <buffer> <LocalLeader>lL :Latexmk!<CR>
|
||||
noremap <buffer> <LocalLeader>lc :LatexmkClean<CR>
|
||||
noremap <buffer> <LocalLeader>lC :LatexmkClean!<CR>
|
||||
noremap <buffer> <LocalLeader>lg :LatexmkStatus<CR>
|
||||
noremap <buffer> <LocalLeader>lG :LatexmkStatus!<CR>
|
||||
noremap <buffer> <LocalLeader>lk :LatexmkStop<CR>
|
||||
noremap <buffer> <LocalLeader>le :LatexErrors<CR>
|
||||
" }}}
|
||||
|
||||
" View {{{
|
||||
noremap <buffer> <LocalLeader>lv :LatexView<CR>
|
||||
" }}}
|
||||
|
||||
" TOC {{{
|
||||
noremap <silent> <buffer> <LocalLeader>lt :LatexTOC<CR>
|
||||
" }}}
|
||||
|
||||
" List of labels {{{
|
||||
noremap <silent> <buffer> <LocalLeader>lj :LatexLabels<CR>
|
||||
" }}}
|
||||
|
||||
" Folding {{{
|
||||
if g:LatexBox_Folding == 1
|
||||
noremap <buffer> <LocalLeader>lf :LatexFold<CR>
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Jump to match {{{
|
||||
if !exists('g:LatexBox_loaded_matchparen')
|
||||
nmap <buffer> % <Plug>LatexBox_JumpToMatch
|
||||
vmap <buffer> % <Plug>LatexBox_JumpToMatch
|
||||
omap <buffer> % <Plug>LatexBox_JumpToMatch
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Define text objects {{{
|
||||
vmap <buffer> ie <Plug>LatexBox_SelectCurrentEnvInner
|
||||
vmap <buffer> ae <Plug>LatexBox_SelectCurrentEnvOuter
|
||||
onoremap <buffer> ie :normal vie<CR>
|
||||
onoremap <buffer> ae :normal vae<CR>
|
||||
vmap <buffer> i$ <Plug>LatexBox_SelectInlineMathInner
|
||||
vmap <buffer> a$ <Plug>LatexBox_SelectInlineMathOuter
|
||||
onoremap <buffer> i$ :normal vi$<CR>
|
||||
onoremap <buffer> a$ :normal va$<CR>
|
||||
" }}}
|
||||
|
||||
" Jump between sections {{{
|
||||
function! s:LatexBoxNextSection(type, backwards, visual)
|
||||
" Restore visual mode if desired
|
||||
if a:visual
|
||||
normal! gv
|
||||
endif
|
||||
|
||||
" For the [] and ][ commands we move up or down before the search
|
||||
if a:type == 1
|
||||
if a:backwards
|
||||
normal! k
|
||||
else
|
||||
normal! j
|
||||
endif
|
||||
endif
|
||||
|
||||
" Define search pattern and do the search while preserving "/
|
||||
let save_search = @/
|
||||
let flags = 'W'
|
||||
if a:backwards
|
||||
let flags = 'b' . flags
|
||||
endif
|
||||
let notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
let pattern = notcomment . '\v\s*\\(' . join([
|
||||
\ '(sub)*section',
|
||||
\ 'chapter',
|
||||
\ 'part',
|
||||
\ 'appendix',
|
||||
\ '(front|back|main)matter'], '|') . ')>'
|
||||
call search(pattern, flags)
|
||||
let @/ = save_search
|
||||
|
||||
" For the [] and ][ commands we move down or up after the search
|
||||
if a:type == 1
|
||||
if a:backwards
|
||||
normal! j
|
||||
else
|
||||
normal! k
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
noremap <buffer> <silent> ]] :call <SID>LatexBoxNextSection(0,0,0)<CR>
|
||||
noremap <buffer> <silent> ][ :call <SID>LatexBoxNextSection(1,0,0)<CR>
|
||||
noremap <buffer> <silent> [] :call <SID>LatexBoxNextSection(1,1,0)<CR>
|
||||
noremap <buffer> <silent> [[ :call <SID>LatexBoxNextSection(0,1,0)<CR>
|
||||
vnoremap <buffer> <silent> ]] :<c-u>call <SID>LatexBoxNextSection(0,0,1)<CR>
|
||||
vnoremap <buffer> <silent> ][ :<c-u>call <SID>LatexBoxNextSection(1,0,1)<CR>
|
||||
vnoremap <buffer> <silent> [] :<c-u>call <SID>LatexBoxNextSection(1,1,1)<CR>
|
||||
vnoremap <buffer> <silent> [[ :<c-u>call <SID>LatexBoxNextSection(0,1,1)<CR>
|
||||
" }}}
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,548 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box motion functions
|
||||
|
||||
" Motion options {{{
|
||||
" Opening and closing patterns
|
||||
if !exists('g:LatexBox_open_pats')
|
||||
let g:LatexBox_open_pats = [ '\\{','{','\\(','(','\\\[','\[',
|
||||
\ '\\begin\s*{.\{-}}', '\\left\s*\%([^\\]\|\\.\|\\\a*\)']
|
||||
let g:LatexBox_close_pats = [ '\\}','}','\\)',')','\\\]','\]',
|
||||
\ '\\end\s*{.\{-}}', '\\right\s*\%([^\\]\|\\.\|\\\a*\)']
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" HasSyntax {{{
|
||||
" s:HasSyntax(syntaxName, [line], [col])
|
||||
function! s:HasSyntax(syntaxName, ...)
|
||||
let line = a:0 >= 1 ? a:1 : line('.')
|
||||
let col = a:0 >= 2 ? a:2 : col('.')
|
||||
return index(map(synstack(line, col),
|
||||
\ 'synIDattr(v:val, "name") == "' . a:syntaxName . '"'),
|
||||
\ 1) >= 0
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Search and Skip Comments {{{
|
||||
" s:SearchAndSkipComments(pattern, [flags], [stopline])
|
||||
function! s:SearchAndSkipComments(pat, ...)
|
||||
let flags = a:0 >= 1 ? a:1 : ''
|
||||
let stopline = a:0 >= 2 ? a:2 : 0
|
||||
let saved_pos = getpos('.')
|
||||
|
||||
" search once
|
||||
let ret = search(a:pat, flags, stopline)
|
||||
|
||||
if ret
|
||||
" do not match at current position if inside comment
|
||||
let flags = substitute(flags, 'c', '', 'g')
|
||||
|
||||
" keep searching while in comment
|
||||
while LatexBox_InComment()
|
||||
let ret = search(a:pat, flags, stopline)
|
||||
if !ret
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
endif
|
||||
|
||||
if !ret
|
||||
" if no match found, restore position
|
||||
call setpos('.', saved_pos)
|
||||
endif
|
||||
|
||||
return ret
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Finding Matching Pair {{{
|
||||
function! s:FindMatchingPair(mode)
|
||||
|
||||
if a:mode =~ 'h\|i'
|
||||
2match none
|
||||
elseif a:mode == 'v'
|
||||
normal! gv
|
||||
endif
|
||||
|
||||
if LatexBox_InComment() | return | endif
|
||||
|
||||
" open/close pairs (dollars signs are treated apart)
|
||||
let dollar_pat = '\$'
|
||||
let notbslash = '\%(\\\@<!\%(\\\\\)*\)\@<='
|
||||
let notcomment = '\%(\%(\\\@<!\%(\\\\\)*\)\@<=%.*\)\@<!'
|
||||
let anymatch = '\('
|
||||
\ . join(g:LatexBox_open_pats + g:LatexBox_close_pats, '\|')
|
||||
\ . '\|' . dollar_pat . '\)'
|
||||
|
||||
let lnum = line('.')
|
||||
let cnum = searchpos('\A', 'cbnW', lnum)[1]
|
||||
" if the previous char is a backslash
|
||||
if strpart(getline(lnum), cnum-2, 1) == '\'
|
||||
let cnum = cnum-1
|
||||
endif
|
||||
let delim = matchstr(getline(lnum), '\C^'. anymatch , cnum - 1)
|
||||
|
||||
if empty(delim) || strlen(delim)+cnum-1< col('.')
|
||||
if a:mode =~ 'n\|v\|o'
|
||||
" if not found, search forward
|
||||
let cnum = match(getline(lnum), '\C'. anymatch , col('.') - 1) + 1
|
||||
if cnum == 0 | return | endif
|
||||
call cursor(lnum, cnum)
|
||||
let delim = matchstr(getline(lnum), '\C^'. anymatch , cnum - 1)
|
||||
elseif a:mode =~ 'i'
|
||||
" if not found, move one char bacward and search
|
||||
let cnum = searchpos('\A', 'bnW', lnum)[1]
|
||||
" if the previous char is a backslash
|
||||
if strpart(getline(lnum), cnum-2, 1) == '\'
|
||||
let cnum = cnum-1
|
||||
endif
|
||||
let delim = matchstr(getline(lnum), '\C^'. anymatch , cnum - 1)
|
||||
if empty(delim) || strlen(delim)+cnum< col('.') | return | endif
|
||||
elseif a:mode =~ 'h'
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
if delim =~ '^\$'
|
||||
|
||||
" match $-pairs
|
||||
" check if next character is in inline math
|
||||
let [lnum0, cnum0] = searchpos('.', 'nW')
|
||||
if lnum0 && s:HasSyntax('texMathZoneX', lnum0, cnum0)
|
||||
let [lnum2, cnum2] = searchpos(notcomment . notbslash. dollar_pat, 'nW', line('w$')*(a:mode =~ 'h\|i') , 200)
|
||||
else
|
||||
let [lnum2, cnum2] = searchpos('\%(\%'. lnum . 'l\%' . cnum . 'c\)\@!'. notcomment . notbslash . dollar_pat, 'bnW', line('w0')*(a:mode =~ 'h\|i') , 200)
|
||||
endif
|
||||
|
||||
if a:mode =~ 'h\|i'
|
||||
execute '2match MatchParen /\%(\%' . lnum . 'l\%' . cnum . 'c\$' . '\|\%' . lnum2 . 'l\%' . cnum2 . 'c\$\)/'
|
||||
elseif a:mode =~ 'n\|v\|o'
|
||||
call cursor(lnum2,cnum2)
|
||||
endif
|
||||
|
||||
else
|
||||
" match other pairs
|
||||
for i in range(len(g:LatexBox_open_pats))
|
||||
let open_pat = notbslash . g:LatexBox_open_pats[i]
|
||||
let close_pat = notbslash . g:LatexBox_close_pats[i]
|
||||
|
||||
if delim =~# '^' . open_pat
|
||||
" if on opening pattern, search for closing pattern
|
||||
let [lnum2, cnum2] = searchpairpos('\C' . open_pat, '', '\C'
|
||||
\ . close_pat, 'nW', 'LatexBox_InComment()',
|
||||
\ line('w$')*(a:mode =~ 'h\|i') , 200)
|
||||
if a:mode =~ 'h\|i'
|
||||
execute '2match MatchParen /\%(\%' . lnum . 'l\%' . cnum
|
||||
\ . 'c' . g:LatexBox_open_pats[i] . '\|\%'
|
||||
\ . lnum2 . 'l\%' . cnum2 . 'c'
|
||||
\ . g:LatexBox_close_pats[i] . '\)/'
|
||||
elseif a:mode =~ 'n\|v\|o'
|
||||
call cursor(lnum2,cnum2)
|
||||
if strlen(close_pat)>1 && a:mode =~ 'o'
|
||||
call cursor(lnum2, matchend(getline('.'), '\C'
|
||||
\ . close_pat, col('.')-1))
|
||||
endif
|
||||
endif
|
||||
break
|
||||
elseif delim =~# '^' . close_pat
|
||||
" if on closing pattern, search for opening pattern
|
||||
let [lnum2, cnum2] = searchpairpos('\C' . open_pat, '',
|
||||
\ '\C\%(\%'. lnum . 'l\%' . cnum . 'c\)\@!'
|
||||
\ . close_pat, 'bnW', 'LatexBox_InComment()',
|
||||
\ line('w0')*(a:mode =~ 'h\|i') , 200)
|
||||
if a:mode =~ 'h\|i'
|
||||
execute '2match MatchParen /\%(\%' . lnum2 . 'l\%' . cnum2
|
||||
\ . 'c' . g:LatexBox_open_pats[i] . '\|\%'
|
||||
\ . lnum . 'l\%' . cnum . 'c'
|
||||
\ . g:LatexBox_close_pats[i] . '\)/'
|
||||
elseif a:mode =~ 'n\|v\|o'
|
||||
call cursor(lnum2,cnum2)
|
||||
endif
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Allow to disable functionality if desired
|
||||
if !exists('g:LatexBox_loaded_matchparen')
|
||||
" Disable matchparen autocommands
|
||||
augroup LatexBox_HighlightPairs
|
||||
autocmd BufEnter * if !exists("g:loaded_matchparen") || !g:loaded_matchparen | runtime plugin/matchparen.vim | endif
|
||||
autocmd BufEnter *.tex 3match none | unlet! g:loaded_matchparen | au! matchparen
|
||||
autocmd! CursorMoved *.tex call s:FindMatchingPair('h')
|
||||
autocmd! CursorMovedI *.tex call s:FindMatchingPair('i')
|
||||
augroup END
|
||||
endif
|
||||
|
||||
" Use LatexBox'es FindMatchingPair as '%' (enable jump between e.g. $'s)
|
||||
nnoremap <silent> <Plug>LatexBox_JumpToMatch :call <SID>FindMatchingPair('n')<CR>
|
||||
vnoremap <silent> <Plug>LatexBox_JumpToMatch :call <SID>FindMatchingPair('v')<CR>
|
||||
onoremap <silent> <Plug>LatexBox_JumpToMatch v:call <SID>FindMatchingPair('o')<CR>
|
||||
|
||||
" }}}
|
||||
|
||||
" select inline math {{{
|
||||
" s:SelectInlineMath(seltype)
|
||||
" where seltype is either 'inner' or 'outer'
|
||||
function! s:SelectInlineMath(seltype)
|
||||
|
||||
let dollar_pat = '\\\@<!\$'
|
||||
|
||||
if s:HasSyntax('texMathZoneX')
|
||||
call s:SearchAndSkipComments(dollar_pat, 'cbW')
|
||||
elseif getline('.')[col('.') - 1] == '$'
|
||||
call s:SearchAndSkipComments(dollar_pat, 'bW')
|
||||
else
|
||||
return
|
||||
endif
|
||||
|
||||
if a:seltype == 'inner'
|
||||
normal! l
|
||||
endif
|
||||
|
||||
if visualmode() ==# 'V'
|
||||
normal! V
|
||||
else
|
||||
normal! v
|
||||
endif
|
||||
|
||||
call s:SearchAndSkipComments(dollar_pat, 'W')
|
||||
|
||||
if a:seltype == 'inner'
|
||||
normal! h
|
||||
endif
|
||||
endfunction
|
||||
|
||||
vnoremap <silent> <Plug>LatexBox_SelectInlineMathInner
|
||||
\ :<C-U>call <SID>SelectInlineMath('inner')<CR>
|
||||
vnoremap <silent> <Plug>LatexBox_SelectInlineMathOuter
|
||||
\ :<C-U>call <SID>SelectInlineMath('outer')<CR>
|
||||
" }}}
|
||||
|
||||
" select current environment {{{
|
||||
function! s:SelectCurrentEnv(seltype)
|
||||
let [env, lnum, cnum, lnum2, cnum2] = LatexBox_GetCurrentEnvironment(1)
|
||||
call cursor(lnum, cnum)
|
||||
if a:seltype == 'inner'
|
||||
if env =~ '^\'
|
||||
call search('\\.\_\s*\S', 'eW')
|
||||
else
|
||||
call search('}\(\_\s*\[\_[^]]*\]\)\?\_\s*\S', 'eW')
|
||||
endif
|
||||
endif
|
||||
if visualmode() ==# 'V'
|
||||
normal! V
|
||||
else
|
||||
normal! v
|
||||
endif
|
||||
call cursor(lnum2, cnum2)
|
||||
if a:seltype == 'inner'
|
||||
call search('\S\_\s*', 'bW')
|
||||
else
|
||||
if env =~ '^\'
|
||||
normal! l
|
||||
else
|
||||
call search('}', 'eW')
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
vnoremap <silent> <Plug>LatexBox_SelectCurrentEnvInner :<C-U>call <SID>SelectCurrentEnv('inner')<CR>
|
||||
vnoremap <silent> <Plug>LatexBox_SelectCurrentEnvOuter :<C-U>call <SID>SelectCurrentEnv('outer')<CR>
|
||||
" }}}
|
||||
|
||||
" Jump to the next braces {{{
|
||||
"
|
||||
function! LatexBox_JumpToNextBraces(backward)
|
||||
let flags = ''
|
||||
if a:backward
|
||||
normal h
|
||||
let flags .= 'b'
|
||||
else
|
||||
let flags .= 'c'
|
||||
endif
|
||||
if search('[][}{]', flags) > 0
|
||||
normal l
|
||||
endif
|
||||
let prev = strpart(getline('.'), col('.') - 2, 1)
|
||||
let next = strpart(getline('.'), col('.') - 1, 1)
|
||||
if next =~ '[]}]' && prev !~ '[][{}]'
|
||||
return "\<Right>"
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" Table of Contents {{{
|
||||
|
||||
" Special UTF-8 conversion
|
||||
function! s:ConvertBack(line)
|
||||
let line = a:line
|
||||
if exists('g:LatexBox_plaintext_toc')
|
||||
"
|
||||
" Substitute stuff like '\IeC{\"u}' to plain 'u'
|
||||
"
|
||||
let line = substitute(line, '\\IeC\s*{\\.\(.\)}', '\1', 'g')
|
||||
else
|
||||
"
|
||||
" Substitute stuff like '\IeC{\"u}' to corresponding unicode symbols
|
||||
"
|
||||
for [pat, symbol] in s:ConvBackPats
|
||||
let line = substitute(line, pat, symbol, 'g')
|
||||
endfor
|
||||
endif
|
||||
return line
|
||||
endfunction
|
||||
|
||||
function! s:ReadTOC(auxfile, texfile, ...)
|
||||
let texfile = a:texfile
|
||||
let prefix = fnamemodify(a:auxfile, ':p:h')
|
||||
|
||||
if a:0 != 2
|
||||
let toc = []
|
||||
let fileindices = { texfile : [] }
|
||||
else
|
||||
let toc = a:1
|
||||
let fileindices = a:2
|
||||
let fileindices[ texfile ] = []
|
||||
endif
|
||||
|
||||
for line in readfile(a:auxfile)
|
||||
let included = matchstr(line, '^\\@input{\zs[^}]*\ze}')
|
||||
if included != ''
|
||||
" append the input TOX to `toc` and `fileindices`
|
||||
let newaux = prefix . '/' . included
|
||||
let newtex = fnamemodify(newaux, ':r') . '.tex'
|
||||
call s:ReadTOC(newaux, newtex, toc, fileindices)
|
||||
continue
|
||||
endif
|
||||
|
||||
" Parse statements like:
|
||||
" \@writefile{toc}{\contentsline {section}{\numberline {secnum}Section Title}{pagenumber}}
|
||||
" \@writefile{toc}{\contentsline {section}{\tocsection {}{1}{Section Title}}{pagenumber}}
|
||||
" \@writefile{toc}{\contentsline {section}{\numberline {secnum}Section Title}{pagenumber}{otherstuff}}
|
||||
|
||||
let line = matchstr(line,
|
||||
\ '\\@writefile{toc}{\\contentsline\s*\zs.*\ze}\s*$')
|
||||
if empty(line)
|
||||
continue
|
||||
endif
|
||||
|
||||
let tree = LatexBox_TexToTree(s:ConvertBack(line))
|
||||
|
||||
if len(tree) < 3
|
||||
" unknown entry type: just skip it
|
||||
continue
|
||||
endif
|
||||
|
||||
" parse level
|
||||
let level = tree[0][0]
|
||||
" parse page
|
||||
if !empty(tree[2])
|
||||
let page = tree[2][0]
|
||||
else
|
||||
let page = ''
|
||||
endif
|
||||
" parse section number
|
||||
let secnum = ''
|
||||
let tree = tree[1]
|
||||
if len(tree) > 3 && empty(tree[1])
|
||||
call remove(tree, 1)
|
||||
endif
|
||||
if len(tree) > 1 && type(tree[0]) == type("") && tree[0] =~ '^\\\(\(chapter\)\?numberline\|tocsection\)'
|
||||
let secnum = LatexBox_TreeToTex(tree[1])
|
||||
let secnum = substitute(secnum, '\\\S\+\s', '', 'g')
|
||||
let secnum = substitute(secnum, '\\\S\+{\(.\{-}\)}', '\1', 'g')
|
||||
let secnum = substitute(secnum, '^{\+\|}\+$', '', 'g')
|
||||
call remove(tree, 1)
|
||||
endif
|
||||
" parse section title
|
||||
let text = LatexBox_TreeToTex(tree)
|
||||
let text = substitute(text, '^{\+\|}\+$', '', 'g')
|
||||
let text = substitute(text, '\m^\\\(no\)\?\(chapter\)\?numberline\s*', '', '')
|
||||
let text = substitute(text, '\*', '', 'g')
|
||||
|
||||
" add TOC entry
|
||||
call add(fileindices[texfile], len(toc))
|
||||
call add(toc, {'file': texfile,
|
||||
\ 'level': level,
|
||||
\ 'number': secnum,
|
||||
\ 'text': text,
|
||||
\ 'page': page})
|
||||
endfor
|
||||
|
||||
return [toc, fileindices]
|
||||
|
||||
endfunction
|
||||
|
||||
function! LatexBox_TOC(...)
|
||||
|
||||
" Check if window already exists
|
||||
let winnr = bufwinnr(bufnr('LaTeX TOC'))
|
||||
" Two types of splits, horizontal and vertical
|
||||
let l:hori = "new"
|
||||
let l:vert = "vnew"
|
||||
|
||||
" Set General Vars and initialize size
|
||||
let l:type = g:LatexBox_split_type
|
||||
let l:size = 10
|
||||
|
||||
" Size detection
|
||||
if l:type == l:hori
|
||||
let l:size = g:LatexBox_split_length
|
||||
elseif l:type == l:vert
|
||||
let l:size = g:LatexBox_split_width
|
||||
endif
|
||||
|
||||
if winnr >= 0
|
||||
if a:0 == 0
|
||||
silent execute winnr . 'wincmd w'
|
||||
else
|
||||
" Supplying an argument to this function causes toggling instead
|
||||
" of jumping to the TOC window
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns-=" . l:size
|
||||
endif
|
||||
silent execute 'bwipeout' . bufnr('LaTeX TOC')
|
||||
endif
|
||||
return
|
||||
endif
|
||||
" Read TOC
|
||||
let [toc, fileindices] = s:ReadTOC(LatexBox_GetAuxFile(),
|
||||
\ LatexBox_GetMainTexFile())
|
||||
let calling_buf = bufnr('%')
|
||||
|
||||
" Find closest section in current buffer
|
||||
let closest_index = s:FindClosestSection(toc,fileindices)
|
||||
|
||||
" Create TOC window and set local settings
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns+=" . l:size
|
||||
endif
|
||||
silent exe g:LatexBox_split_side l:size . l:type . ' LaTeX\ TOC'
|
||||
|
||||
let b:toc = toc
|
||||
let b:toc_numbers = 1
|
||||
let b:calling_win = bufwinnr(calling_buf)
|
||||
setlocal filetype=latextoc
|
||||
|
||||
" Add TOC entries and jump to the closest section
|
||||
for entry in toc
|
||||
call append('$', entry['number'] . "\t" . entry['text'])
|
||||
endfor
|
||||
if !g:LatexBox_toc_hidehelp
|
||||
call append('$', "")
|
||||
call append('$', "<Esc>/q: close")
|
||||
call append('$', "<Space>: jump")
|
||||
call append('$', "<Enter>: jump and close")
|
||||
call append('$', "s: hide numbering")
|
||||
endif
|
||||
0delete _
|
||||
|
||||
execute 'normal! ' . (closest_index + 1) . 'G'
|
||||
|
||||
" Lock buffer
|
||||
setlocal nomodifiable
|
||||
endfunction
|
||||
|
||||
" Binary search for the closest section
|
||||
" return the index of the TOC entry
|
||||
function! s:FindClosestSection(toc, fileindices)
|
||||
let file = expand('%:p')
|
||||
if !has_key(a:fileindices, file)
|
||||
return 0
|
||||
endif
|
||||
|
||||
let imax = len(a:fileindices[file])
|
||||
if imax > 0
|
||||
let imin = 0
|
||||
while imin < imax - 1
|
||||
let i = (imax + imin) / 2
|
||||
let tocindex = a:fileindices[file][i]
|
||||
let entry = a:toc[tocindex]
|
||||
let titlestr = entry['text']
|
||||
let titlestr = escape(titlestr, '\')
|
||||
let titlestr = substitute(titlestr, ' ', '\\_\\s\\+', 'g')
|
||||
let [lnum, cnum] = searchpos('\\' . entry['level'] . '\_\s*{' . titlestr . '}', 'nW')
|
||||
if lnum
|
||||
let imax = i
|
||||
else
|
||||
let imin = i
|
||||
endif
|
||||
endwhile
|
||||
return a:fileindices[file][imin]
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:ConvBackPats = map([
|
||||
\ ['\\''A}' , 'Á'],
|
||||
\ ['\\`A}' , 'À'],
|
||||
\ ['\\^A}' , 'À'],
|
||||
\ ['\\¨A}' , 'Ä'],
|
||||
\ ['\\"A}' , 'Ä'],
|
||||
\ ['\\''a}' , 'á'],
|
||||
\ ['\\`a}' , 'à'],
|
||||
\ ['\\^a}' , 'à'],
|
||||
\ ['\\¨a}' , 'ä'],
|
||||
\ ['\\"a}' , 'ä'],
|
||||
\ ['\\''E}' , 'É'],
|
||||
\ ['\\`E}' , 'È'],
|
||||
\ ['\\^E}' , 'Ê'],
|
||||
\ ['\\¨E}' , 'Ë'],
|
||||
\ ['\\"E}' , 'Ë'],
|
||||
\ ['\\''e}' , 'é'],
|
||||
\ ['\\`e}' , 'è'],
|
||||
\ ['\\^e}' , 'ê'],
|
||||
\ ['\\¨e}' , 'ë'],
|
||||
\ ['\\"e}' , 'ë'],
|
||||
\ ['\\''I}' , 'Í'],
|
||||
\ ['\\`I}' , 'Î'],
|
||||
\ ['\\^I}' , 'Ì'],
|
||||
\ ['\\¨I}' , 'Ï'],
|
||||
\ ['\\"I}' , 'Ï'],
|
||||
\ ['\\''i}' , 'í'],
|
||||
\ ['\\`i}' , 'î'],
|
||||
\ ['\\^i}' , 'ì'],
|
||||
\ ['\\¨i}' , 'ï'],
|
||||
\ ['\\"i}' , 'ï'],
|
||||
\ ['\\''{\?\\i }' , 'í'],
|
||||
\ ['\\''O}' , 'Ó'],
|
||||
\ ['\\`O}' , 'Ò'],
|
||||
\ ['\\^O}' , 'Ô'],
|
||||
\ ['\\¨O}' , 'Ö'],
|
||||
\ ['\\"O}' , 'Ö'],
|
||||
\ ['\\''o}' , 'ó'],
|
||||
\ ['\\`o}' , 'ò'],
|
||||
\ ['\\^o}' , 'ô'],
|
||||
\ ['\\¨o}' , 'ö'],
|
||||
\ ['\\"o}' , 'ö'],
|
||||
\ ['\\''U}' , 'Ú'],
|
||||
\ ['\\`U}' , 'Ù'],
|
||||
\ ['\\^U}' , 'Û'],
|
||||
\ ['\\¨U}' , 'Ü'],
|
||||
\ ['\\"U}' , 'Ü'],
|
||||
\ ['\\''u}' , 'ú'],
|
||||
\ ['\\`u}' , 'ù'],
|
||||
\ ['\\^u}' , 'û'],
|
||||
\ ['\\¨u}' , 'ü'],
|
||||
\ ['\\"u}' , 'ü'],
|
||||
\ ['\\`N}' , 'Ǹ'],
|
||||
\ ['\\\~N}' , 'Ñ'],
|
||||
\ ['\\''n}' , 'ń'],
|
||||
\ ['\\`n}' , 'ǹ'],
|
||||
\ ['\\\~n}' , 'ñ'],
|
||||
\], '[''\C\(\\IeC\s*{\)\?'' . v:val[0], v:val[1]]')
|
||||
" }}}
|
||||
|
||||
" TOC Command {{{
|
||||
command! LatexTOC call LatexBox_TOC()
|
||||
command! LatexTOCToggle call LatexBox_TOC(1)
|
||||
" }}}
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -1,206 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" {{{1 Settings
|
||||
setlocal buftype=nofile
|
||||
setlocal bufhidden=wipe
|
||||
setlocal nobuflisted
|
||||
setlocal noswapfile
|
||||
setlocal nowrap
|
||||
setlocal nospell
|
||||
setlocal cursorline
|
||||
setlocal nonumber
|
||||
setlocal nolist
|
||||
setlocal tabstop=8
|
||||
setlocal cole=0
|
||||
setlocal cocu=nvic
|
||||
if g:LatexBox_fold_toc
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=TOCFoldLevel(v:lnum)
|
||||
setlocal foldtext=TOCFoldText()
|
||||
endif
|
||||
" }}}1
|
||||
|
||||
" {{{1 Functions
|
||||
" {{{2 TOCClose
|
||||
function! s:TOCClose()
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns-=" . g:LatexBox_split_width
|
||||
endif
|
||||
bwipeout
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCToggleNumbers
|
||||
function! s:TOCToggleNumbers()
|
||||
if b:toc_numbers
|
||||
setlocal conceallevel=3
|
||||
let b:toc_numbers = 0
|
||||
else
|
||||
setlocal conceallevel=0
|
||||
let b:toc_numbers = 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{2 EscapeTitle
|
||||
function! s:EscapeTitle(titlestr)
|
||||
let titlestr = substitute(a:titlestr, '\\[a-zA-Z@]*\>\s*{\?', '.*', 'g')
|
||||
let titlestr = substitute(titlestr, '}', '', 'g')
|
||||
let titlestr = substitute(titlestr, '\%(\.\*\s*\)\{2,}', '.*', 'g')
|
||||
return titlestr
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCActivate
|
||||
function! s:TOCActivate(close)
|
||||
let n = getpos('.')[1] - 1
|
||||
|
||||
if n >= len(b:toc)
|
||||
return
|
||||
endif
|
||||
|
||||
let entry = b:toc[n]
|
||||
|
||||
let titlestr = s:EscapeTitle(entry['text'])
|
||||
|
||||
" Search for duplicates
|
||||
"
|
||||
let i=0
|
||||
let entry_hash = entry['level'].titlestr
|
||||
let duplicates = 0
|
||||
while i<n
|
||||
let i_entry = b:toc[n]
|
||||
let i_hash = b:toc[i]['level'].s:EscapeTitle(b:toc[i]['text'])
|
||||
if i_hash == entry_hash
|
||||
let duplicates += 1
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
let toc_bnr = bufnr('%')
|
||||
let toc_wnr = winnr()
|
||||
|
||||
execute b:calling_win . 'wincmd w'
|
||||
|
||||
let root = fnamemodify(entry['file'], ':h') . '/'
|
||||
let files = [entry['file']]
|
||||
for line in filter(readfile(entry['file']), 'v:val =~ ''\\input{''')
|
||||
let file = matchstr(line, '{\zs.\{-}\ze\(\.tex\)\?}') . '.tex'
|
||||
if file[0] != '/'
|
||||
let file = root . file
|
||||
endif
|
||||
call add(files, file)
|
||||
endfor
|
||||
|
||||
" Find section in buffer (or inputted files)
|
||||
if entry['level'] == 'label'
|
||||
let re = '\(\\label\_\s*{\|label\s*=\s*\)' . titlestr . '\>'
|
||||
else
|
||||
let re = '\\' . entry['level'] . '\_\s*{' . titlestr . '}'
|
||||
endif
|
||||
call s:TOCFindMatch(re, duplicates, files)
|
||||
|
||||
if a:close
|
||||
if g:LatexBox_split_resize
|
||||
silent exe "set columns-=" . g:LatexBox_split_width
|
||||
endif
|
||||
execute 'bwipeout ' . toc_bnr
|
||||
else
|
||||
execute toc_wnr . 'wincmd w'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCFindMatch
|
||||
function! s:TOCFindMatch(strsearch,duplicates,files)
|
||||
if len(a:files) == 0
|
||||
echoerr "Could not find: " . a:strsearch
|
||||
return
|
||||
endif
|
||||
|
||||
call s:TOCOpenBuf(a:files[0])
|
||||
let dups = a:duplicates
|
||||
|
||||
" Skip duplicates
|
||||
while dups > 0
|
||||
if search(a:strsearch, 'w')
|
||||
let dups -= 1
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
|
||||
if search(a:strsearch, 'w')
|
||||
normal! zv
|
||||
return
|
||||
endif
|
||||
|
||||
call s:TOCFindMatch(a:strsearch,dups,a:files[1:])
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCFoldLevel
|
||||
function! TOCFoldLevel(lnum)
|
||||
let line = getline(a:lnum)
|
||||
let match_s1 = line =~# '^\w\+\s'
|
||||
let match_s2 = line =~# '^\w\+\.\w\+\s'
|
||||
let match_s3 = line =~# '^\w\+\.\w\+\.\w\+\s'
|
||||
|
||||
if g:LatexBox_fold_toc_levels >= 3
|
||||
if match_s3
|
||||
return ">3"
|
||||
endif
|
||||
endif
|
||||
|
||||
if g:LatexBox_fold_toc_levels >= 2
|
||||
if match_s2
|
||||
return ">2"
|
||||
endif
|
||||
endif
|
||||
|
||||
if match_s1
|
||||
return ">1"
|
||||
endif
|
||||
|
||||
" Don't fold options
|
||||
if line =~# '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Return previous fold level
|
||||
return "="
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCFoldText
|
||||
function! TOCFoldText()
|
||||
let parts = matchlist(getline(v:foldstart), '^\(.*\)\t\(.*\)$')
|
||||
return printf('%-8s%-72s', parts[1], parts[2])
|
||||
endfunction
|
||||
|
||||
" {{{2 TOCOpenBuf
|
||||
function! s:TOCOpenBuf(file)
|
||||
|
||||
let bnr = bufnr(a:file)
|
||||
if bnr == -1
|
||||
execute 'badd ' . a:file
|
||||
let bnr = bufnr(a:file)
|
||||
endif
|
||||
execute 'buffer! ' . bnr
|
||||
normal! gg
|
||||
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" {{{1 Mappings
|
||||
nnoremap <buffer> <silent> s :call <SID>TOCToggleNumbers()<CR>
|
||||
nnoremap <buffer> <silent> q :call <SID>TOCClose()<CR>
|
||||
nnoremap <buffer> <silent> <Esc> :call <SID>TOCClose()<CR>
|
||||
nnoremap <buffer> <silent> <Space> :call <SID>TOCActivate(0)<CR>
|
||||
nnoremap <buffer> <silent> <CR> :call <SID>TOCActivate(1)<CR>
|
||||
nnoremap <buffer> <silent> <leftrelease> :call <SID>TOCActivate(0)<cr>
|
||||
nnoremap <buffer> <silent> <2-leftmouse> :call <SID>TOCActivate(1)<cr>
|
||||
nnoremap <buffer> <silent> G G4k
|
||||
nnoremap <buffer> <silent> <Esc>OA k
|
||||
nnoremap <buffer> <silent> <Esc>OB j
|
||||
nnoremap <buffer> <silent> <Esc>OC l
|
||||
nnoremap <buffer> <silent> <Esc>OD h
|
||||
" }}}1
|
||||
|
||||
" vim:fdm=marker:ff=unix:et:ts=4:sw=4
|
||||
|
||||
endif
|
||||
5
ftplugin/litcoffee.vim
Normal file
5
ftplugin/litcoffee.vim
Normal file
@@ -0,0 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'coffee-script') == -1
|
||||
|
||||
runtime ftplugin/coffee.vim
|
||||
|
||||
endif
|
||||
66
ftplugin/mail_vifm.vim
Normal file
66
ftplugin/mail_vifm.vim
Normal file
@@ -0,0 +1,66 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" Mail file type extension to pick files for attachments via vifm
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: January 23, 2016
|
||||
|
||||
" Insert attachment picked via vifm after 'Subject' header
|
||||
function! s:AddMailAttacments()
|
||||
" TODO: reduce duplication between this file and plugins/vifm.vim
|
||||
let l:listf = tempname()
|
||||
|
||||
if !has('nvim')
|
||||
if has('gui_running')
|
||||
execute 'silent !' g:vifm_term g:vifm_exec
|
||||
\ '--choose-files' shellescape(l:listf, 1)
|
||||
\ g:vifm_exec_args
|
||||
else
|
||||
execute 'silent !' g:vifm_exec
|
||||
\ '--choose-files' shellescape(l:listf, 1)
|
||||
\ g:vifm_exec_args
|
||||
endif
|
||||
|
||||
redraw!
|
||||
|
||||
call s:HandleRunResults(v:shell_error, l:listf)
|
||||
else
|
||||
" Work around handicapped neovim...
|
||||
let callback = { 'listf': l:listf }
|
||||
function! callback.on_exit(id, code)
|
||||
buffer #
|
||||
silent! bdelete! #
|
||||
call s:HandleRunResults(a:code, self.listf)
|
||||
endfunction
|
||||
enew
|
||||
call termopen(g:vifm_exec . ' --choose-files ' . shellescape(l:listf, 1)
|
||||
\. ' ' . g:vifm_exec_args, callback)
|
||||
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HandleRunResults(exitcode, listf)
|
||||
if a:exitcode != 0
|
||||
echohl WarningMsg
|
||||
echo 'Got non-zero code from vifm: ' . a:exitcode
|
||||
echohl None
|
||||
call delete(a:listf)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:insert_pos = search('^Subject:', 'nw')
|
||||
|
||||
if filereadable(a:listf) && l:insert_pos != 0
|
||||
for line in readfile(a:listf)
|
||||
call append(l:insert_pos, 'Attach: '.line)
|
||||
let l:insert_pos += 1
|
||||
endfor
|
||||
endif
|
||||
call delete(a:listf)
|
||||
endfunction
|
||||
|
||||
nnoremap <buffer> <silent> <localleader>a :call <sid>AddMailAttacments()<cr>
|
||||
|
||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||
|
||||
endif
|
||||
63
ftplugin/mma.vim
Normal file
63
ftplugin/mma.vim
Normal file
@@ -0,0 +1,63 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mathematica') == -1
|
||||
|
||||
"Vim filetype plugin
|
||||
" Language: Mathematica
|
||||
" Maintainer: R. Menon <rsmenon@icloud.com>
|
||||
" Last Change: Feb 26, 2013
|
||||
|
||||
" Initialization {
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
"}
|
||||
|
||||
" Syntax completion function {
|
||||
if exists('&ofu')
|
||||
setlocal omnifunc=syntaxcomplete#Complete
|
||||
setlocal completefunc=syntaxcomplete#Complete
|
||||
endif
|
||||
"}
|
||||
|
||||
" Main functions {
|
||||
if has('python')
|
||||
" Random ID generator {
|
||||
function! RandomID()
|
||||
|
||||
"Python implementation follows; do not alter indentations/whitespace
|
||||
python << EOF
|
||||
import random, string, vim
|
||||
vim.command("let l:id = '" + (''.join(random.sample(string.ascii_uppercase + string.digits, 8))) + "'")
|
||||
EOF
|
||||
|
||||
return l:id
|
||||
endfunction
|
||||
"}
|
||||
|
||||
"Unit test template {
|
||||
function! Test()
|
||||
if exists("*strftime")
|
||||
let l:date = strftime("%Y%m%d") . "-"
|
||||
else
|
||||
let l:date = ""
|
||||
endif
|
||||
|
||||
let l:testid = expand("%:t") . "-" . l:date . RandomID()
|
||||
let l:template = "Test[\rtest\r,\rresult\r,\rTestID -> \"" . l:testid . "\"\r\b]"
|
||||
exe ":normal i" . l:template
|
||||
endfunction
|
||||
"}
|
||||
endif
|
||||
"}
|
||||
|
||||
" Cleanup {
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
"}
|
||||
|
||||
" vim: set foldmarker={,} foldlevel=0 foldmethod=marker:
|
||||
|
||||
endif
|
||||
@@ -1,17 +1,17 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
" Vim filetype plugin
|
||||
" Language: Nix
|
||||
" Maintainer: Daiderd Jordan <daiderd@gmail.com>
|
||||
" URL: https://github.com/LnL7/vim-nix
|
||||
|
||||
if (exists("b:did_ftplugin"))
|
||||
finish
|
||||
endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal comments=
|
||||
|
||||
setlocal comments=:#
|
||||
setlocal commentstring=#\ %s
|
||||
|
||||
" Nixpkgs indent settings
|
||||
setlocal tabstop=2
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
setlocal expandtab
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
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>
|
||||
" Version: 0.1
|
||||
|
||||
if exists("b:loaded_plantuml_plugin")
|
||||
if exists('b:loaded_plantuml_plugin')
|
||||
finish
|
||||
endif
|
||||
let b:loaded_plantuml_plugin = 1
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if !exists("g:plantuml_executable_script")
|
||||
let g:plantuml_executable_script="plantuml"
|
||||
if !exists('g:plantuml_executable_script')
|
||||
let g:plantuml_executable_script='plantuml'
|
||||
endif
|
||||
|
||||
if exists("loaded_matchit")
|
||||
if exists('loaded_matchit')
|
||||
let b:match_ignorecase = 0
|
||||
let b:match_words =
|
||||
\ '\(\<ref\>\|\<box\>\|\<opt\>\|\<alt\>\|\<group\>\|\<loop\>\|\<note\>\|\<legend\>\):\<else\>:\<end\>' .
|
||||
@@ -27,7 +22,7 @@ if exists("loaded_matchit")
|
||||
\ ',\<\while\>:\<endwhile\>'
|
||||
endif
|
||||
|
||||
let &l:makeprg=g:plantuml_executable_script . " " . fnameescape(expand("%"))
|
||||
let &l:makeprg=g:plantuml_executable_script . ' ' . fnameescape(expand('%'))
|
||||
|
||||
setlocal comments=s1:/',mb:',ex:'/,:' commentstring=/'%s'/ formatoptions-=t formatoptions+=croql
|
||||
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'purescript') == -1
|
||||
|
||||
setlocal comments=s1fl:{-,mb:\ \ ,ex:-},:--
|
||||
setlocal include=^import
|
||||
setlocal includeexpr=printf('%s.purs',substitute(v:fname,'\\.','/','g'))
|
||||
|
||||
let s:PS = []
|
||||
fun! InitPureScript()
|
||||
let dirs = map(
|
||||
\ findfile("psc-package.json", expand("%:p:h") . ";/", -1),
|
||||
\ { idx, val -> fnamemodify(val, ":p:h") }
|
||||
\ )
|
||||
if empty(dirs)
|
||||
let dirs = map(
|
||||
\ findfile("bower.json", expand("%:p:h") . ";/", -1),
|
||||
\ { idx, val -> fnamemodify(val, ":p:h") }
|
||||
\ )
|
||||
if empty(dirs)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let path = expand("%:p")
|
||||
for p in s:PS
|
||||
if stridx(path, p[0], 0) == 0
|
||||
let &l:path=p[1]
|
||||
return
|
||||
endif
|
||||
endfor
|
||||
|
||||
let dir = dirs[len(dirs) - 1]
|
||||
let gp = globpath(dir, "src/**/*.purs", v:true, v:true)
|
||||
if empty(gp)
|
||||
return
|
||||
endif
|
||||
|
||||
let &l:path=join([dir, dir . "/bower_components/**", dir . "/src/**"], ",")
|
||||
call add(s:PS, [dir, &l:path])
|
||||
endfun
|
||||
call InitPureScript()
|
||||
|
||||
endif
|
||||
|
||||
63
ftplugin/racket.vim
Normal file
63
ftplugin/racket.vim
Normal file
@@ -0,0 +1,63 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'racket') == -1
|
||||
|
||||
" Language: Racket
|
||||
" Maintainer: Will Langstroth <will@langstroth.com>
|
||||
" URL: http://github.com/wlangstroth/vim-racket
|
||||
|
||||
setl iskeyword+=#,%,^
|
||||
setl lispwords+=module,module*,module+,parameterize,let-values,let*-values,letrec-values,local
|
||||
setl lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse
|
||||
setl lispwords+=define-signature,unit,unit/sig,compund-unit/sig,define-values/invoke-unit/sig
|
||||
setl lispwords+=define-opt/c,define-syntax-rule
|
||||
setl lispwords+=struct
|
||||
|
||||
" Racket OOP
|
||||
setl lispwords+=class,define/public,define/private
|
||||
|
||||
" kanren
|
||||
setl lispwords+=fresh,run,run*,project,conde,condu
|
||||
|
||||
" loops
|
||||
setl lispwords+=for,for/list,for/fold,for*,for*/list,for*/fold,for/or,for/and
|
||||
setl lispwords+=for/hash,for/sum,for/flvector,for*/flvector,for/vector
|
||||
|
||||
setl lispwords+=match,match*,match/values,define/match,match-lambda,match-lambda*,match-lambda**
|
||||
setl lispwords+=match-let,match-let*,match-let-values,match-let*-values
|
||||
setl lispwords+=match-letrec,match-define,match-define-values
|
||||
setl lisp
|
||||
|
||||
" Enable auto begin new comment line when continuing from an old comment line
|
||||
setl comments+=:;
|
||||
setl formatoptions+=r
|
||||
|
||||
setl makeprg=raco\ make\ --\ %
|
||||
|
||||
" Simply setting keywordprg like this works:
|
||||
" setl keywordprg=raco\ docs
|
||||
" but then vim says:
|
||||
" "press ENTER or type a command to continue"
|
||||
" We avoid the annoyance of having to hit enter by remapping K directly.
|
||||
nnoremap <buffer> K :silent !raco docs <cword><cr>:redraw!<cr>
|
||||
|
||||
" For the visual mode K mapping, it's slightly more convoluted to get the
|
||||
" selected text:
|
||||
function! s:Racket_visual_doc()
|
||||
try
|
||||
let l:old_a = @a
|
||||
normal! gv"ay
|
||||
call system("raco docs '". @a . "'")
|
||||
redraw!
|
||||
return @a
|
||||
finally
|
||||
let @a = l:old_a
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
vnoremap <buffer> K :call <SID>Racket_visual_doc()<cr>
|
||||
|
||||
nnoremap <buffer> <f9> :!racket -t %<cr>
|
||||
|
||||
"setl commentstring=;;%s
|
||||
setl commentstring=#\|\ %s\ \|#
|
||||
|
||||
endif
|
||||
@@ -71,7 +71,7 @@ endif
|
||||
|
||||
function! s:query_path(root) abort
|
||||
let code = "print $:.join %q{,}"
|
||||
if &shell =~# 'sh'
|
||||
if &shell =~# 'sh' && empty(&shellxquote)
|
||||
let prefix = 'env PATH='.shellescape($PATH).' '
|
||||
else
|
||||
let prefix = ''
|
||||
@@ -164,23 +164,23 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
|
||||
nmap <buffer><script> <SID>: :<C-U>
|
||||
nmap <buffer><script> <SID>c: :<C-U><C-R>=v:count ? v:count : ''<CR>
|
||||
|
||||
nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','n')<CR>
|
||||
nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','n')<CR>
|
||||
xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>','rubyDefine','','v')<CR>
|
||||
xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>','rubyDefine','','v')<CR>
|
||||
nnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','n')<CR>
|
||||
nnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','n')<CR>
|
||||
xnoremap <silent> <buffer> [m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]m :<C-U>call <SID>searchsyn('\<def\>',['rubyDefine'],'','v')<CR>
|
||||
xnoremap <silent> <buffer> [M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]M :<C-U>call <SID>searchsyn('\<end\>',['rubyDefine'],'','v')<CR>
|
||||
|
||||
nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','n')<CR>
|
||||
nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','n')<CR>
|
||||
nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','n')<CR>
|
||||
xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>','rubyModule\<Bar>rubyClass','','v')<CR>
|
||||
xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','b','v')<CR>
|
||||
xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>','rubyModule\<Bar>rubyClass','','v')<CR>
|
||||
nnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','n')<CR>
|
||||
nnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','n')<CR>
|
||||
nnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','n')<CR>
|
||||
xnoremap <silent> <buffer> [[ :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ]] :<C-U>call <SID>searchsyn('\<\%(class\<Bar>module\)\>',['rubyModule','rubyClass'],'','v')<CR>
|
||||
xnoremap <silent> <buffer> [] :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'b','v')<CR>
|
||||
xnoremap <silent> <buffer> ][ :<C-U>call <SID>searchsyn('\<end\>',['rubyModule','rubyClass'],'','v')<CR>
|
||||
|
||||
let b:undo_ftplugin = b:undo_ftplugin
|
||||
\."| sil! exe 'unmap <buffer> [[' | sil! exe 'unmap <buffer> ]]' | sil! exe 'unmap <buffer> []' | sil! exe 'unmap <buffer> ]['"
|
||||
@@ -290,12 +290,13 @@ function! s:searchsyn(pattern, syn, flags, mode) abort
|
||||
norm! gv
|
||||
endif
|
||||
let i = 0
|
||||
call map(a:syn, 'hlID(v:val)')
|
||||
while i < cnt
|
||||
let i = i + 1
|
||||
let line = line('.')
|
||||
let col = col('.')
|
||||
let pos = search(a:pattern,'W'.a:flags)
|
||||
while pos != 0 && s:synname() !~# a:syn
|
||||
while pos != 0 && index(a:syn, s:synid()) < 0
|
||||
let pos = search(a:pattern,'W'.a:flags)
|
||||
endwhile
|
||||
if pos == 0
|
||||
@@ -305,8 +306,8 @@ function! s:searchsyn(pattern, syn, flags, mode) abort
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! s:synname() abort
|
||||
return synIDattr(synID(line('.'),col('.'),0),'name')
|
||||
function! s:synid() abort
|
||||
return synID(line('.'),col('.'),0)
|
||||
endfunction
|
||||
|
||||
function! s:wrap_i(back,forward) abort
|
||||
@@ -362,8 +363,9 @@ function! RubyCursorFile() abort
|
||||
let pre = matchstr(strpart(getline('.'), 0, col('.')-1), '.*\f\@<!')
|
||||
let post = matchstr(strpart(getline('.'), col('.')), '\f\@!.*')
|
||||
let ext = getline('.') =~# '^\s*\%(require\%(_relative\)\=\|autoload\)\>' && cfile !~# '\.rb$' ? '.rb' : ''
|
||||
if s:synname() ==# 'rubyConstant'
|
||||
if s:synid() ==# hlID('rubyConstant')
|
||||
let cfile = substitute(cfile,'\.\w\+[?!=]\=$','','')
|
||||
let cfile = substitute(cfile,'^::','','')
|
||||
let cfile = substitute(cfile,'::','/','g')
|
||||
let cfile = substitute(cfile,'\(\u\+\)\(\u\l\)','\1_\2', 'g')
|
||||
let cfile = substitute(cfile,'\(\l\|\d\)\(\u\)','\1_\2', 'g')
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||
|
||||
" Language: Rust
|
||||
" Description: Vim syntax file for Rust
|
||||
" Description: Vim ftplugin for Rust
|
||||
" Maintainer: Chris Morgan <me@chrismorgan.info>
|
||||
" Maintainer: Kevin Ballard <kevin@sb.org>
|
||||
" Last Change: June 08, 2016
|
||||
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
@@ -193,19 +194,13 @@ endif
|
||||
|
||||
augroup END
|
||||
|
||||
" %-matching. <:> is handy for generics.
|
||||
set matchpairs+=<:>
|
||||
" There are two minor issues with it; (a) comparison operators in expressions,
|
||||
" where a less-than may match a greater-than later on—this is deemed a trivial
|
||||
" issue—and (b) `Fn() -> X` syntax. This latter issue is irremediable from the
|
||||
" highlighting perspective (built into Vim), but the actual % functionality
|
||||
" can be fixed by this use of matchit.vim.
|
||||
" For matchit.vim (rustArrow stops `Fn() -> X` messing things up)
|
||||
let b:match_skip = 's:comment\|string\|rustArrow'
|
||||
source $VIMRUNTIME/macros/matchit.vim
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
" vim: set noet sw=4 ts=4:
|
||||
" vim: set noet sw=8 ts=8:
|
||||
|
||||
endif
|
||||
|
||||
5
ftplugin/solidity.vim
Normal file
5
ftplugin/solidity.vim
Normal file
@@ -0,0 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'solidity') == -1
|
||||
|
||||
setlocal commentstring=//\ %s
|
||||
|
||||
endif
|
||||
@@ -1,37 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||
|
||||
" LaTeX Box plugin for Vim
|
||||
" Maintainer: David Munger
|
||||
" Email: mungerd@gmail.com
|
||||
" Version: 0.9.6
|
||||
|
||||
if exists('*fnameescape')
|
||||
function! s:FNameEscape(s)
|
||||
return fnameescape(a:s)
|
||||
endfunction
|
||||
else
|
||||
function! s:FNameEscape(s)
|
||||
return a:s
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if !exists('b:LatexBox_loaded')
|
||||
|
||||
let prefix = expand('<sfile>:p:h') . '/latex-box/'
|
||||
|
||||
execute 'source ' . s:FNameEscape(prefix . 'common.vim')
|
||||
execute 'source ' . s:FNameEscape(prefix . 'complete.vim')
|
||||
execute 'source ' . s:FNameEscape(prefix . 'motion.vim')
|
||||
execute 'source ' . s:FNameEscape(prefix . 'latexmk.vim')
|
||||
execute 'source ' . s:FNameEscape(prefix . 'folding.vim')
|
||||
" added by AH to add main.tex file finder
|
||||
execute 'source ' . s:FNameEscape(prefix . 'findmain.vim')
|
||||
execute 'source ' . s:FNameEscape(prefix . 'mappings.vim')
|
||||
|
||||
let b:LatexBox_loaded = 1
|
||||
|
||||
endif
|
||||
|
||||
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||
|
||||
endif
|
||||
@@ -15,7 +15,7 @@ setlocal commentstring=//\ %s
|
||||
" " and insert the comment leader when hitting <CR> or using "o".
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
setlocal suffixesadd+=.ts
|
||||
setlocal suffixesadd+=.ts,.tsx
|
||||
|
||||
let b:undo_ftplugin = "setl fo< ofu< com< cms<"
|
||||
|
||||
|
||||
23
ftplugin/vifm-cmdedit.vim
Normal file
23
ftplugin/vifm-cmdedit.vim
Normal file
@@ -0,0 +1,23 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" vifm command-line editing buffer filetype plugin
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: August 18, 2013
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Behave as vifm script file
|
||||
runtime! ftplugin/vifm.vim
|
||||
|
||||
" Use vifm script highlighting
|
||||
set syntax=vifm
|
||||
|
||||
call vifm#edit#Init()
|
||||
|
||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||
|
||||
endif
|
||||
17
ftplugin/vifm-edit.vim
Normal file
17
ftplugin/vifm-edit.vim
Normal file
@@ -0,0 +1,17 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" vifm command-line editing buffer filetype plugin
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: August 18, 2013
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
call vifm#edit#Init()
|
||||
|
||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||
|
||||
endif
|
||||
62
ftplugin/vifm-rename.vim
Normal file
62
ftplugin/vifm-rename.vim
Normal file
@@ -0,0 +1,62 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" Filetype plugin for vifm rename buffer
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: October 05, 2014
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
" Copy list of original file names
|
||||
let s:files = getline(1, '$')
|
||||
|
||||
" Closes window/tab/Vim when buffer is left alone in there
|
||||
function! s:QuitIfOnlyWindow()
|
||||
" Boil out if there is more than one window
|
||||
if winbufnr(2) != -1
|
||||
return
|
||||
endif
|
||||
|
||||
" Just close tab with this single window or quit Vim with last tab
|
||||
if tabpagenr('$') == 1
|
||||
bdelete
|
||||
quit
|
||||
else
|
||||
close
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Create a vertical split window for original file names and configure it
|
||||
belowright vsplit __VifmRenameOrig__
|
||||
enew
|
||||
call setline(1, s:files)
|
||||
setlocal buftype=nofile
|
||||
setlocal bufhidden=hide
|
||||
setlocal noswapfile
|
||||
setlocal nobuflisted
|
||||
setlocal cursorbind
|
||||
setlocal scrollbind
|
||||
setlocal nocursorline
|
||||
|
||||
" Free now useless list of file names
|
||||
unlet s:files
|
||||
|
||||
" Setup a hook in auxiliary local window to do not leave it alone, when it's
|
||||
" useless
|
||||
augroup VifmRenameAutoCmds
|
||||
autocmd! * <buffer>
|
||||
autocmd BufEnter <buffer> call s:QuitIfOnlyWindow()
|
||||
augroup END
|
||||
|
||||
" Go back to the original window and ensure it will remain synchronized with
|
||||
" the auxiliary one
|
||||
wincmd w
|
||||
setlocal cursorbind
|
||||
setlocal scrollbind
|
||||
|
||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||
|
||||
endif
|
||||
50
ftplugin/vifm.vim
Normal file
50
ftplugin/vifm.vim
Normal file
@@ -0,0 +1,50 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||
|
||||
" vifmrc filetype plugin
|
||||
" Maintainer: xaizek <xaizek@posteo.net>
|
||||
" Last Change: July 08, 2016
|
||||
" Based On: Vim file type file by Bram Moolenaar
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
let b:undo_ftplugin = "setlocal formatoptions< comments< textwidth< commentstring<"
|
||||
|
||||
" Break comment lines but not other lines
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
|
||||
" Set comment character
|
||||
setlocal comments=:\"
|
||||
|
||||
" Format comments to be up to 78 characters long
|
||||
if &textwidth == 0
|
||||
setlocal textwidth=78
|
||||
endif
|
||||
|
||||
" Comments start with a double quote
|
||||
setlocal commentstring=\"%s
|
||||
|
||||
" Move around comments
|
||||
nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
|
||||
vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
|
||||
nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
|
||||
vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>
|
||||
|
||||
" Let the matchit plugin know what items can be matched.
|
||||
if exists("loaded_matchit")
|
||||
let b:match_ignorecase = 0
|
||||
let b:match_words = '\<if\>:\<el\%[seif]\>:\<en\%[dif]\>'
|
||||
endif
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||
|
||||
endif
|
||||
@@ -11,4 +11,13 @@ endif
|
||||
|
||||
runtime! ftplugin/html.vim
|
||||
|
||||
setlocal suffixesadd+=.vue
|
||||
|
||||
if exists('g:loaded_ale')
|
||||
let g:ale_linters = get(g:, 'ale_linters', {})
|
||||
let g:ale_linters.vue = get(g:ale_linters, 'vue', ['eslint'])
|
||||
let g:ale_linter_aliases = get(g:, 'ale_linter_aliases', {})
|
||||
let g:ale_linter_aliases.vue = get(g:ale_linter_aliases, 'vue', 'javascript')
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jenkins') == -1
|
||||
|
||||
setlocal suffixesadd+=.vue
|
||||
runtime indent/groovy.vim
|
||||
|
||||
endif
|
||||
@@ -29,6 +29,11 @@ function GetAnsibleIndent(lnum)
|
||||
if a:lnum == 1 || !prevnonblank(a:lnum-1)
|
||||
return 0
|
||||
endif
|
||||
if exists("g:ansible_unindent_after_newline")
|
||||
if (a:lnum -1) != prevnonblank(a:lnum - 1)
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
let prevlnum = prevnonblank(a:lnum - 1)
|
||||
let maintain = indent(prevlnum)
|
||||
let increase = maintain + &sw
|
||||
|
||||
223
indent/autohotkey.vim
Normal file
223
indent/autohotkey.vim
Normal file
@@ -0,0 +1,223 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'autohotkey') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: AutoHotkey
|
||||
" Maintainer: Hirotoshi Namikawa <hnamikaw1@gmail.com>
|
||||
" URL: http://github.com/hnamikaw/vim-autohotkey
|
||||
" License: Same as Vim.
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetAutoHotkeyIndent()
|
||||
setlocal indentkeys=!^F,o,O,0{,0},=if,=else,=return
|
||||
setlocal expandtab
|
||||
|
||||
let b:undo_indent = 'setlocal '.join([
|
||||
\ 'autoindent<',
|
||||
\ 'indentexpr<',
|
||||
\ 'indentkeys<',
|
||||
\ 'expandtab<',
|
||||
\ ])
|
||||
|
||||
let s:TRUE = !0
|
||||
let s:FALSE = 0
|
||||
|
||||
" Check BEGIN BLOCK
|
||||
" TRUE:
|
||||
" {
|
||||
" { ; with comment
|
||||
" if {
|
||||
" if { ; with comment
|
||||
"
|
||||
" FALSE:
|
||||
" ; if { comment
|
||||
" sleep 1000 ; {
|
||||
function! IsBeginBlockByStr(str)
|
||||
return a:str =~? '^[^;]*{\s*\(;.*\)\?$' ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
" Check END BLOCK
|
||||
" TRUE:
|
||||
" }
|
||||
" } ; with comment
|
||||
" } else {
|
||||
" } else { ; with comment
|
||||
"
|
||||
" FALSE:
|
||||
" ; } else {
|
||||
function! IsEndBlockByStr(str)
|
||||
return a:str =~? '^\s*}.*\(;.*\)\?$' ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
" Check DOUBLE CORON
|
||||
" TRUE:
|
||||
" LAlt up::
|
||||
" LAlt up:: ; with comment
|
||||
"
|
||||
" FALSE:
|
||||
" ; LAlt up::
|
||||
" sleep 1000 ; ::
|
||||
function! IsDoubleCoronByStr(str)
|
||||
return a:str =~? '^[^;]*::\s*\(;.*\)\?$' ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
" Check RETURN
|
||||
" TRUE:
|
||||
" return
|
||||
" return 1
|
||||
" return ; with comment
|
||||
"
|
||||
" FALSE:
|
||||
" ; return
|
||||
function! IsReturnByStr(str)
|
||||
return a:str =~? '^\s*return.*\(;.*\)\?$' ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
" Check IF STATEMENT(without BLOCK)
|
||||
" TRUE:
|
||||
" if
|
||||
" if ; with comment
|
||||
" else
|
||||
" else ; with comment
|
||||
"
|
||||
" FALSE:
|
||||
" if {
|
||||
" else {
|
||||
function! IsIfStatementByStr(str)
|
||||
return a:str =~? '^\s*\(if\|else\)[^{]*\(;.*\)\?$' ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
" Check inside of BLOCK.
|
||||
" TRUE:
|
||||
" if {
|
||||
" hogehoge
|
||||
" fugafuga <--- line_num
|
||||
" }
|
||||
"
|
||||
" FALSE:
|
||||
" foobar <--- line_num
|
||||
function! IsInsideOfBlockByNum(line_num)
|
||||
let block_indent_level = 0
|
||||
|
||||
for scan_line_num in range(1, a:line_num)
|
||||
if IsBeginBlockByStr(getline(scan_line_num)) == s:TRUE
|
||||
let block_indent_level += 1
|
||||
endif
|
||||
|
||||
if IsEndBlockByStr(getline(scan_line_num)) == s:TRUE
|
||||
let block_indent_level -= 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return block_indent_level >= 1 ? s:TRUE : s:FALSE
|
||||
endfunction
|
||||
|
||||
function! AddIndentByInd(indent)
|
||||
return a:indent + &l:shiftwidth
|
||||
endfunction
|
||||
|
||||
function! UnIndentByInd(indent)
|
||||
return a:indent - &l:shiftwidth
|
||||
endfunction
|
||||
|
||||
function! GetAutoHotkeyIndent()
|
||||
let l0_num = v:lnum
|
||||
let l1_num = v:lnum - 1
|
||||
let pl1_num = prevnonblank(l1_num)
|
||||
let pl2_num = prevnonblank(pl1_num - 1)
|
||||
|
||||
let l0_str = getline(l0_num)
|
||||
let pl1_str = getline(pl1_num)
|
||||
let pl2_str = getline(pl2_num)
|
||||
let pl1_ind = indent(pl1_num)
|
||||
let pl2_ind = indent(pl2_num)
|
||||
|
||||
" Case: Next line of IF STATEMENT(without BLOCK)
|
||||
" if bar = 1
|
||||
" callFunc1() <--- AddIndent
|
||||
"
|
||||
" if bar = 1
|
||||
" { <--- No! AddIndent
|
||||
if IsIfStatementByStr(pl1_str) == s:TRUE && IsBeginBlockByStr(l0_str) == s:FALSE
|
||||
return AddIndentByInd(pl1_ind)
|
||||
endif
|
||||
|
||||
" Case: End of IF STATEMENT(without BLOCK)
|
||||
" if bar = 1
|
||||
" callFunc1()
|
||||
" if bar = 2 <--- UnIndent
|
||||
"
|
||||
" Case: End of IF STATEMENT(without BLOCK) and END BLOCK(of outer block)
|
||||
" if foo
|
||||
" {
|
||||
" if bar = 3
|
||||
" callFunc3()
|
||||
" } <--- UnIndent (2level)
|
||||
if IsIfStatementByStr(pl2_str) == s:TRUE && IsBeginBlockByStr(pl1_str) == s:FALSE
|
||||
if IsEndBlockByStr(l0_str) == s:FALSE
|
||||
return UnIndentByInd(pl1_ind)
|
||||
else
|
||||
return UnIndentByInd(pl2_ind)
|
||||
endif
|
||||
endif
|
||||
|
||||
" Case: Next line of BEGIN BLOCK
|
||||
" Swap(ByRef Left, ByRef Right)
|
||||
" {
|
||||
" temp := Left <--- AddIndent
|
||||
" Left := Right
|
||||
" Right := temp
|
||||
" }
|
||||
if IsBeginBlockByStr(pl1_str) == s:TRUE
|
||||
return AddIndentByInd(pl1_ind)
|
||||
endif
|
||||
|
||||
" Case: END BLOCK
|
||||
" Swap(ByRef Left, ByRef Right)
|
||||
" {
|
||||
" temp := Left
|
||||
" Left := Right
|
||||
" Right := temp
|
||||
" } <--- UnIndent
|
||||
if IsEndBlockByStr(l0_str) == s:TRUE
|
||||
return UnIndentByInd(pl1_ind)
|
||||
endif
|
||||
|
||||
" Case: Next line of DOUBLE CORON
|
||||
" #n::
|
||||
" Run Notepad <--- AddIndent
|
||||
" return
|
||||
if IsDoubleCoronByStr(pl1_str) == s:TRUE
|
||||
return AddIndentByInd(pl1_ind)
|
||||
endif
|
||||
|
||||
" Case: RETURN
|
||||
" Note: It is not nothing if in the BLOCK.
|
||||
" #n::
|
||||
" Run Notepad
|
||||
" return <--- UnIndent
|
||||
" ~~~
|
||||
" if foo
|
||||
" {
|
||||
" callFunc1()
|
||||
" return <--- No! UnIndent
|
||||
" }
|
||||
if IsReturnByStr(l0_str) == s:TRUE && IsInsideOfBlockByNum(l0_num) == s:FALSE
|
||||
return UnIndentByInd(pl1_ind)
|
||||
endif
|
||||
|
||||
" Case: Top line.
|
||||
if pl1_num == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Case: It does not match anything.
|
||||
return pl1_ind
|
||||
endfunction
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
endif
|
||||
@@ -4,22 +4,22 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
||||
" Language: Blade (Laravel)
|
||||
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
||||
|
||||
if exists("b:did_indent")
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/html.vim
|
||||
let s:htmlindent = &indentexpr
|
||||
unlet! b:did_indent
|
||||
|
||||
unlet! b:did_indent
|
||||
runtime! indent/php.vim
|
||||
let s:phpindent = &indentexpr
|
||||
unlet! b:did_indent
|
||||
|
||||
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_start = 'if\|else\|unless\|for\|while\|empty\|push\|section\|can\|hasSection\|verbatim\|php\|' .
|
||||
\ 'component\|slot\|prepend\|auth\|guest'
|
||||
let s:directives_end = 'else\|end\|empty\|show\|stop\|append\|overwrite'
|
||||
|
||||
if exists('g:blade_custom_directives_pairs')
|
||||
@@ -29,55 +29,71 @@ endif
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetBladeIndent()
|
||||
exe "setlocal indentkeys=o,O,<>>,!^F,0=}},0=!!},=@" . substitute(s:directives_end, '\\|', ',=@', 'g')
|
||||
exe 'setlocal indentkeys=o,O,<>>,!^F,0=}},0=!!},=@' . substitute(s:directives_end, '\\|', ',=@', 'g')
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetBladeIndent")
|
||||
if exists('*GetBladeIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:IsStartingDelimiter(lnum)
|
||||
let line = getline(a:lnum)
|
||||
return line =~# '\%(\w\|@\)\@<!@\%(' . s:directives_start . '\)\%(.*@end\|.*@stop\)\@!'
|
||||
\ || line =~# '{{\%(.*}}\)\@!'
|
||||
\ || line =~# '{!!\%(.*!!}\)\@!'
|
||||
\ || line =~# '<?\%(.*?>\)\@!'
|
||||
endfunction
|
||||
|
||||
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 line = getline(lnum)
|
||||
let cline = getline(v:lnum)
|
||||
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
|
||||
|
||||
" 1. Check for special directives
|
||||
" @section is a single-line directive if it has a second argument.
|
||||
" @php is a single-line directive if it is followed by parentheses.
|
||||
if (line =~# '@section\%(.*@end\)\@!' && line !~# '@section\s*([^,]*)')
|
||||
\ || line =~# '@php\s*('
|
||||
return indent
|
||||
endif
|
||||
|
||||
" 2. When the current line is an ending delimiter: decrease indentation
|
||||
" if the previous line wasn't a starting delimiter.
|
||||
if cline =~# '^\s*@\%(' . s:directives_end . '\)'
|
||||
\ || cline =~# '\%(<?.*\)\@<!?>'
|
||||
\ || cline =~# '\%({{.*\)\@<!}}'
|
||||
\ || cline =~# '\%({!!.*\)\@<!!!}'
|
||||
return s:IsStartingDelimiter(lnum) ? indent : indent - &sw
|
||||
endif
|
||||
|
||||
" 3. Increase indentation if the line contains a starting delimiter.
|
||||
if s:IsStartingDelimiter(lnum)
|
||||
return indent + &sw
|
||||
endif
|
||||
|
||||
" 4. External indent scripts (PHP and HTML)
|
||||
execute 'let indent = ' . s:htmlindent
|
||||
|
||||
if exists('*GetBladeIndentCustom')
|
||||
let indent = GetBladeIndentCustom()
|
||||
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
|
||||
\ searchpair('@php\s*(\@!', '', '@endphp', 'bWr') )
|
||||
" Only use PHP's indent if the region spans multiple lines
|
||||
if !s:IsStartingDelimiter(v:lnum)
|
||||
execute 'let indent = ' . s:phpindent
|
||||
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
|
||||
|
||||
46
indent/caddyfile.vim
Normal file
46
indent/caddyfile.vim
Normal file
@@ -0,0 +1,46 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal nolisp
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetCaddyfileIndent(v:lnum)
|
||||
setlocal indentkeys+=<:>,0=},0=)
|
||||
" setlocal cindent
|
||||
|
||||
if exists('*shiftwidth')
|
||||
func s:sw()
|
||||
return shiftwidth()
|
||||
endfunc
|
||||
else
|
||||
func s:sw()
|
||||
return &sw
|
||||
endfunc
|
||||
endif
|
||||
|
||||
function! GetCaddyfileIndent(lnum)
|
||||
let prevlnum = prevnonblank(a:lnum-1)
|
||||
if prevlnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let thisl = substitute(getline(a:lnum), '#.*$', '', '')
|
||||
let prevl = substitute(getline(prevlnum), '#.*$', '', '')
|
||||
|
||||
let ind = indent(prevlnum)
|
||||
|
||||
if prevl =~ '{\s*$'
|
||||
let ind += s:sw()
|
||||
endif
|
||||
|
||||
if thisl =~ '^\s*}\s*$'
|
||||
let ind -= s:sw()
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
endif
|
||||
@@ -192,11 +192,7 @@ if exists("*searchpairpos")
|
||||
" 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
|
||||
return getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?"
|
||||
endfunction
|
||||
|
||||
" Returns 1 for opening brackets, -1 for _anything else_.
|
||||
@@ -294,6 +290,19 @@ if exists("*searchpairpos")
|
||||
return paren
|
||||
endif
|
||||
|
||||
" If the keyword begins with #, check if it is an anonymous
|
||||
" function or set, in which case we indent by the shiftwidth
|
||||
" (minus one if g:clojure_align_subforms = 1), or if it is
|
||||
" ignored, in which case we use the ( position for indent.
|
||||
if w[0] == "#"
|
||||
" TODO: Handle #=() and other rare reader invocations?
|
||||
if w[1] == '(' || w[1] == '{'
|
||||
return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
|
||||
elseif w[1] == '_'
|
||||
return paren
|
||||
endif
|
||||
endif
|
||||
|
||||
" Test words without namespace qualifiers and leading reader macro
|
||||
" metacharacters.
|
||||
"
|
||||
|
||||
93
indent/cmake.vim
Normal file
93
indent/cmake.vim
Normal file
@@ -0,0 +1,93 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cmake') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: CMake (ft=cmake)
|
||||
" Author: Andy Cedilnik <andy.cedilnik@kitware.com>
|
||||
" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
|
||||
" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
|
||||
" Last Change: 2017 Aug 30
|
||||
"
|
||||
" Licence: The CMake license applies to this file. See
|
||||
" https://cmake.org/licensing
|
||||
" This implies that distribution with Vim is allowed
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
let s:keepcpo= &cpo
|
||||
set cpo&vim
|
||||
|
||||
setlocal indentexpr=CMakeGetIndent(v:lnum)
|
||||
setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*CMakeGetIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
fun! CMakeGetIndent(lnum)
|
||||
let this_line = getline(a:lnum)
|
||||
|
||||
" Find a non-blank line above the current line.
|
||||
let lnum = a:lnum
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
let previous_line = getline(lnum)
|
||||
|
||||
" Hit the start of the file, use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(lnum)
|
||||
|
||||
let or = '\|'
|
||||
" Regular expressions used by line indentation function.
|
||||
let cmake_regex_comment = '#.*'
|
||||
let cmake_regex_identifier = '[A-Za-z][A-Za-z0-9_]*'
|
||||
let cmake_regex_quoted = '"\([^"\\]\|\\.\)*"'
|
||||
let cmake_regex_arguments = '\(' . cmake_regex_quoted .
|
||||
\ or . '\$(' . cmake_regex_identifier . ')' .
|
||||
\ or . '[^()\\#"]' . or . '\\.' . '\)*'
|
||||
|
||||
let cmake_indent_comment_line = '^\s*' . cmake_regex_comment
|
||||
let cmake_indent_blank_regex = '^\s*$'
|
||||
let cmake_indent_open_regex = '^\s*' . cmake_regex_identifier .
|
||||
\ '\s*(' . cmake_regex_arguments .
|
||||
\ '\(' . cmake_regex_comment . '\)\?$'
|
||||
|
||||
let cmake_indent_close_regex = '^' . cmake_regex_arguments .
|
||||
\ ')\s*' .
|
||||
\ '\(' . cmake_regex_comment . '\)\?$'
|
||||
|
||||
let cmake_indent_begin_regex = '^\s*\(IF\|MACRO\|FOREACH\|ELSE\|ELSEIF\|WHILE\|FUNCTION\)\s*('
|
||||
let cmake_indent_end_regex = '^\s*\(ENDIF\|ENDFOREACH\|ENDMACRO\|ELSE\|ELSEIF\|ENDWHILE\|ENDFUNCTION\)\s*('
|
||||
|
||||
" Add
|
||||
if previous_line =~? cmake_indent_comment_line " Handle comments
|
||||
let ind = ind
|
||||
else
|
||||
if previous_line =~? cmake_indent_begin_regex
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
if previous_line =~? cmake_indent_open_regex
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
endif
|
||||
|
||||
" Subtract
|
||||
if this_line =~? cmake_indent_end_regex
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
if previous_line =~? cmake_indent_close_regex
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfun
|
||||
|
||||
let &cpo = s:keepcpo
|
||||
unlet s:keepcpo
|
||||
|
||||
endif
|
||||
@@ -1,97 +1,19 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||
|
||||
setlocal nosmartindent
|
||||
setlocal indentexpr=elixir#indent()
|
||||
setlocal indentkeys+=0),0],0=\|>,=->
|
||||
setlocal indentkeys+=0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
|
||||
|
||||
if exists("b:did_indent") || exists("*elixir#indent")
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
end
|
||||
let b:did_indent = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
setlocal indentexpr=elixir#indent(v:lnum)
|
||||
|
||||
function! elixir#indent()
|
||||
" initiates the `old_ind` dictionary
|
||||
let b:old_ind = get(b:, 'old_ind', {})
|
||||
" initiates the `line` dictionary
|
||||
let line = s:build_line(v:lnum)
|
||||
setlocal indentkeys+==after,=catch,=do,=else,=end,=rescue,
|
||||
setlocal indentkeys+=*<Return>,=->,=\|>,=<>,0},0],0)
|
||||
|
||||
if s:is_beginning_of_file(line)
|
||||
" Reset `old_ind` dictionary at the beginning of the file
|
||||
let b:old_ind = {}
|
||||
" At the start of the file use zero indent.
|
||||
return 0
|
||||
elseif !s:is_indentable_line(line)
|
||||
" Keep last line indentation if the current line does not have an
|
||||
" indentable syntax
|
||||
return indent(line.last_non_blank.num)
|
||||
else
|
||||
" Calculates the indenation level based on the rules
|
||||
" All the rules are defined in `autoload/elixir/indent.vim`
|
||||
let ind = indent(line.last_non_blank.num)
|
||||
call s:debug('>>> line = ' . string(line.current))
|
||||
call s:debug('>>> ind = ' . ind)
|
||||
let ind = s:indent('deindent_case_arrow', ind, line)
|
||||
let ind = s:indent('indent_parenthesis', ind, line)
|
||||
let ind = s:indent('indent_square_brackets', ind, line)
|
||||
let ind = s:indent('indent_brackets', ind, line)
|
||||
let ind = s:indent('deindent_opened_symbols', ind, line)
|
||||
let ind = s:indent('indent_pipeline_assignment', ind, line)
|
||||
let ind = s:indent('indent_pipeline_continuation', ind, line)
|
||||
let ind = s:indent('indent_after_pipeline', ind, line)
|
||||
let ind = s:indent('indent_assignment', ind, line)
|
||||
let ind = s:indent('indent_ending_symbols', ind, line)
|
||||
let ind = s:indent('indent_keywords', ind, line)
|
||||
let ind = s:indent('deindent_keywords', ind, line)
|
||||
let ind = s:indent('deindent_ending_symbols', ind, line)
|
||||
let ind = s:indent('indent_case_arrow', ind, line)
|
||||
let ind = s:indent('indent_ecto_queries', ind, line)
|
||||
call s:debug('<<< final = ' . ind)
|
||||
return ind
|
||||
end
|
||||
" TODO: @jbodah 2017-02-27: all operators should cause reindent when typed
|
||||
|
||||
function! elixir#indent(lnum)
|
||||
return elixir#indent#indent(a:lnum)
|
||||
endfunction
|
||||
|
||||
function s:indent(rule, ind, line)
|
||||
let Fn = function('elixir#indent#'.a:rule)
|
||||
let ind = Fn(a:ind, a:line)
|
||||
call s:debug(a:rule . ' = ' . ind)
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
function s:debug(message)
|
||||
if get(g:, 'elixir_indent_debug', 0)
|
||||
echom a:message
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! s:is_beginning_of_file(line)
|
||||
return a:line.last_non_blank.num == 0
|
||||
endfunction
|
||||
|
||||
function! s:is_indentable_line(line)
|
||||
return elixir#util#is_indentable_at(a:line.current.num, 1)
|
||||
endfunction
|
||||
|
||||
function! s:build_line(line)
|
||||
let line = { 'current': {}, 'last': {}, 'last_non_blank': {} }
|
||||
let line.current = s:new_line(a:line)
|
||||
let line.last = s:new_line(line.current.num - 1)
|
||||
let line.last_non_blank = s:new_line(prevnonblank(line.current.num - 1))
|
||||
|
||||
return line
|
||||
endfunction
|
||||
|
||||
function! s:new_line(num)
|
||||
return {
|
||||
\ "num": a:num,
|
||||
\ "text": getline(a:num)
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
endif
|
||||
|
||||
202
indent/elm.vim
202
indent/elm.vim
@@ -1,129 +1,115 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Haskell
|
||||
" Maintainer: lilydjwg <lilydjwg@gmail.com>
|
||||
" Version: 1.0
|
||||
" References: http://en.wikibooks.org/wiki/Haskell/Indentation
|
||||
" http://book.realworldhaskell.org/read/
|
||||
" See Also: The Align plugin http://www.vim.org/scripts/script.php?script_id=294
|
||||
" indentation for Elm (http://elm-lang.org/)
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=HaskellIndent()
|
||||
for i in split('0{,:,0#,e', ',')
|
||||
exec "setlocal indentkeys-=" . i
|
||||
endfor
|
||||
setlocal indentkeys+=0=else,0=in,0=where,0),0<bar>
|
||||
setlocal tabstop=8
|
||||
" Local defaults
|
||||
setlocal expandtab
|
||||
setlocal indentexpr=GetElmIndent()
|
||||
setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in
|
||||
setlocal nolisp
|
||||
setlocal nosmartindent
|
||||
|
||||
if !exists('g:Haskell_no_mapping')
|
||||
inoremap <silent> <BS> <C-R>=<SID>HaskellDedent(1)<CR>
|
||||
inoremap <silent> <C-D> <C-R>=<SID>HaskellDedent(0)<CR>
|
||||
endif
|
||||
" Comment formatting
|
||||
setlocal comments=s1fl:{-,mb:\ ,ex:-},:--
|
||||
|
||||
" Only define the functions once.
|
||||
if exists("*HaskellIndent")
|
||||
" Only define the function once.
|
||||
if exists('*GetElmIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:align_map = {
|
||||
\ 'in': '\<let\>',
|
||||
\ '\<else\>': '\<then\>',
|
||||
\ ',': '\v%(\s|\w|^)@<=[[{]%(\s|\w|"|$)@='
|
||||
\ }
|
||||
let s:indent_self = ['=']
|
||||
let s:indent_next = ['let', 'in', 'where', 'do', 'if']
|
||||
let s:indent_if_final = ['=', 'do', '->', 'of', 'where']
|
||||
|
||||
function HaskellIndent()
|
||||
let lnum = v:lnum - 1
|
||||
|
||||
" Hit the start of the file, use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(lnum)
|
||||
let prevline = getline(lnum)
|
||||
let curline = getline(v:lnum)
|
||||
let curwords = split(curline)
|
||||
if len(curwords) > 0
|
||||
if has_key(s:align_map, curwords[0])
|
||||
let word = s:align_map[curwords[0]]
|
||||
let m = -1
|
||||
let line = v:lnum
|
||||
while m == -1
|
||||
let line -= 1
|
||||
if line <= 0
|
||||
return -1
|
||||
endif
|
||||
let m = match(getline(line), word)
|
||||
endwhile
|
||||
return m
|
||||
elseif index(s:indent_self, curwords[0]) != -1
|
||||
return ind + &sw
|
||||
elseif curwords[0] == '|'
|
||||
return match(prevline, '\v%(\s|\w|^)@<=[|=]%(\s|\w)@=')
|
||||
elseif index([')', '}'], curwords[0]) != -1
|
||||
return ind - &sw
|
||||
elseif curwords[0] == 'where'
|
||||
if prevline =~ '\v^\s+\|%(\s|\w)@='
|
||||
return ind - 1
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let prevwords = split(prevline)
|
||||
if len(prevwords) == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
if prevwords[-1] == 'where' && prevwords[0] == 'module'
|
||||
return 0
|
||||
elseif index(s:indent_if_final, prevwords[-1]) != -1
|
||||
return ind + &sw
|
||||
elseif prevwords[-1] =~ '\v%(\s|\w|^)@<=[[{(]$'
|
||||
return ind + &sw
|
||||
else
|
||||
for word in reverse(prevwords)
|
||||
if index(s:indent_next, word) != -1
|
||||
return match(prevline, '\<'.word.'\>') + len(word) + 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if len(curwords) > 0 && curwords[0] == 'where'
|
||||
return ind + &sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
" Indent pairs
|
||||
function! s:FindPair(pstart, pmid, pend)
|
||||
"call search(a:pend, 'bW')
|
||||
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
|
||||
endfunction
|
||||
|
||||
function s:HaskellDedent(isbs)
|
||||
if a:isbs && strpart(getline('.'), 0, col('.')-1) !~ '^\s\+$'
|
||||
return "\<BS>"
|
||||
function! GetElmIndent()
|
||||
let l:lnum = v:lnum - 1
|
||||
|
||||
" Ident 0 if the first line of the file:
|
||||
if l:lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let curind = indent('.')
|
||||
let line = line('.') - 1
|
||||
while curind > 0 && line > 0
|
||||
let ind = indent(line)
|
||||
if ind >= curind
|
||||
let line -= 1
|
||||
else
|
||||
echomsg curind ind
|
||||
call setline('.', repeat(' ', ind) .
|
||||
\ substitute(getline('.'), '^\s\+', '', ''))
|
||||
return ''
|
||||
let l:ind = indent(l:lnum)
|
||||
let l:lline = getline(l:lnum)
|
||||
let l:line = getline(v:lnum)
|
||||
|
||||
" Indent if current line begins with '}':
|
||||
if l:line =~? '^\s*}'
|
||||
return s:FindPair('{', '', '}')
|
||||
|
||||
" Indent if current line begins with 'else':
|
||||
elseif l:line =~# '^\s*else\>'
|
||||
if l:lline !~# '^\s*\(if\|then\)\>'
|
||||
return s:FindPair('\<if\>', '', '\<else\>')
|
||||
endif
|
||||
endwhile
|
||||
return a:isbs ? "\<BS>" : ''
|
||||
endfunction
|
||||
|
||||
" Indent if current line begins with 'then':
|
||||
elseif l:line =~# '^\s*then\>'
|
||||
if l:lline !~# '^\s*\(if\|else\)\>'
|
||||
return s:FindPair('\<if\>', '', '\<then\>')
|
||||
endif
|
||||
|
||||
" HACK: Indent lines in case with nearest case clause:
|
||||
elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\'
|
||||
return indent(search('^\s*case', 'bWn')) + &shiftwidth
|
||||
|
||||
" HACK: Don't change the indentation if the last line is a comment.
|
||||
elseif l:lline =~# '^\s*--'
|
||||
return l:ind
|
||||
|
||||
" Align the end of block comments with the start
|
||||
elseif l:line =~# '^\s*-}'
|
||||
return indent(search('{-', 'bWn'))
|
||||
|
||||
" Indent double shift after let with an empty rhs
|
||||
elseif l:lline =~# '\<let\>.*\s=$'
|
||||
return l:ind + 4 + &shiftwidth
|
||||
|
||||
" Align 'in' with the parent let.
|
||||
elseif l:line =~# '^\s*in\>'
|
||||
return indent(search('^\s*let', 'bWn'))
|
||||
|
||||
" Align bindings with the parent let.
|
||||
elseif l:lline =~# '\<let\>'
|
||||
return l:ind + 4
|
||||
|
||||
" Align bindings with the parent in.
|
||||
elseif l:lline =~# '^\s*in\>'
|
||||
return l:ind + 4
|
||||
|
||||
endif
|
||||
|
||||
" Add a 'shiftwidth' after lines ending with:
|
||||
if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$'
|
||||
let l:ind = l:ind + &shiftwidth
|
||||
|
||||
" Add a 'shiftwidth' after lines starting with type ending with '=':
|
||||
elseif l:lline =~# '^\s*type' && l:line =~# '^\s*='
|
||||
let l:ind = l:ind + &shiftwidth
|
||||
|
||||
" Back to normal indent after comments:
|
||||
elseif l:lline =~# '-}\s*$'
|
||||
call search('-}', 'bW')
|
||||
let l:ind = indent(searchpair('{-', '', '-}', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
|
||||
|
||||
" Ident some operators if there aren't any starting the last line.
|
||||
elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$'
|
||||
let l:ind = l:ind + &shiftwidth
|
||||
|
||||
elseif l:lline ==# '' && getline(l:lnum - 1) !=# ''
|
||||
let l:ind = indent(search('^\s*\S+', 'bWn'))
|
||||
|
||||
endif
|
||||
|
||||
return l:ind
|
||||
endfunc
|
||||
|
||||
endif
|
||||
|
||||
@@ -6,9 +6,9 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'erlang') == -1
|
||||
" Contributors: Edwin Fine <efine145_nospam01 at usa dot net>
|
||||
" Pawel 'kTT' Salata <rockplayer.pl@gmail.com>
|
||||
" Ricardo Catalinas Jiménez <jimenezrick@gmail.com>
|
||||
" Last Update: 2013-Jul-21
|
||||
" Last Update: 2017-Feb-28
|
||||
" License: Vim license
|
||||
" URL: https://github.com/hcs42/vim-erlang
|
||||
" URL: https://github.com/vim-erlang/vim-erlang-runtime
|
||||
|
||||
" Note About Usage:
|
||||
" This indentation script works best with the Erlang syntax file created by
|
||||
@@ -528,7 +528,9 @@ endfunction
|
||||
" ok. % IsLineAtomContinuation = false
|
||||
function! s:IsLineAtomContinuation(lnum)
|
||||
if has('syntax_items')
|
||||
return synIDattr(synID(a:lnum, 1, 0), 'name') =~# '^erlangQuotedAtom'
|
||||
let syn_name = synIDattr(synID(a:lnum, 1, 0), 'name')
|
||||
return syn_name =~# '^erlangQuotedAtom' ||
|
||||
\ syn_name =~# '^erlangQuotedRecord'
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
@@ -682,7 +684,7 @@ function! s:BeginningOfClauseFound(stack, token, stored_vcol, lnum, i)
|
||||
call s:Pop(a:stack)
|
||||
if empty(a:stack)
|
||||
call s:Log(' Stack is ["when"], so LTI is in a guard -> return')
|
||||
return [1, a:stored_vcol + &sw + 2]
|
||||
return [1, a:stored_vcol + shiftwidth() + 2]
|
||||
else
|
||||
return [1, s:UnexpectedToken(a:token, a:stack)]
|
||||
endif
|
||||
@@ -691,7 +693,7 @@ function! s:BeginningOfClauseFound(stack, token, stored_vcol, lnum, i)
|
||||
call s:Pop(a:stack)
|
||||
if empty(a:stack)
|
||||
call s:Log(' Stack is ["->"], so LTI is in function body -> return')
|
||||
return [1, a:stored_vcol + &sw]
|
||||
return [1, a:stored_vcol + shiftwidth()]
|
||||
elseif a:stack[0] ==# ';'
|
||||
call s:Pop(a:stack)
|
||||
|
||||
@@ -843,7 +845,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
|
||||
elseif token ==# 'begin'
|
||||
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
|
||||
\stored_vcol, 'end', &sw)
|
||||
\stored_vcol, 'end', shiftwidth())
|
||||
if ret | return res | endif
|
||||
|
||||
" case EXPR of BRANCHES end
|
||||
@@ -894,11 +896,11 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
elseif stack == ['->']
|
||||
call s:Log(' LTI is in a branch after ' .
|
||||
\'"of/receive/after/if/catch" -> return')
|
||||
return stored_vcol + &sw
|
||||
return stored_vcol + shiftwidth()
|
||||
elseif stack == ['when']
|
||||
call s:Log(' LTI is in a guard after ' .
|
||||
\'"of/receive/after/if/catch" -> return')
|
||||
return stored_vcol + &sw
|
||||
return stored_vcol + shiftwidth()
|
||||
else
|
||||
return s:UnexpectedToken(token, stack)
|
||||
endif
|
||||
@@ -934,7 +936,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
if empty(stack)
|
||||
call s:Log(' LTI is in a condition; matching ' .
|
||||
\'"case/if/try/receive" found')
|
||||
let stored_vcol = curr_vcol + &sw
|
||||
let stored_vcol = curr_vcol + shiftwidth()
|
||||
elseif stack[0] ==# 'align_to_begin_element'
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol
|
||||
@@ -943,23 +945,23 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
\'"case/if/try/receive" found')
|
||||
call s:Pop(stack)
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol + &sw
|
||||
let stored_vcol = curr_vcol + shiftwidth()
|
||||
elseif stack[0] ==# '->'
|
||||
call s:Log(' LTI is in a branch; matching ' .
|
||||
\'"case/if/try/receive" found')
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol + 2 * &sw
|
||||
let stored_vcol = curr_vcol + 2 * shiftwidth()
|
||||
elseif stack[0] ==# 'when'
|
||||
call s:Log(' LTI is in a guard; matching ' .
|
||||
\'"case/if/try/receive" found')
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol + 2 * &sw + 2
|
||||
let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
|
||||
\stored_vcol, 'end', &sw)
|
||||
\stored_vcol, 'end', shiftwidth())
|
||||
if ret | return res | endif
|
||||
|
||||
elseif token ==# 'fun'
|
||||
@@ -985,7 +987,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
" stack = ['when'] => LTI is in a guard
|
||||
if empty(stack)
|
||||
call s:Log(' LTI is in a condition; matching "fun" found')
|
||||
let stored_vcol = curr_vcol + &sw
|
||||
let stored_vcol = curr_vcol + shiftwidth()
|
||||
elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
|
||||
call s:Log(' LTI is in a condition; matching "fun" found')
|
||||
call s:Pop(stack)
|
||||
@@ -993,15 +995,15 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
elseif stack[0] ==# '->'
|
||||
call s:Log(' LTI is in a branch; matching "fun" found')
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol + 2 * &sw
|
||||
let stored_vcol = curr_vcol + 2 * shiftwidth()
|
||||
elseif stack[0] ==# 'when'
|
||||
call s:Log(' LTI is in a guard; matching "fun" found')
|
||||
call s:Pop(stack)
|
||||
let stored_vcol = curr_vcol + 2 * &sw + 2
|
||||
let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
|
||||
endif
|
||||
|
||||
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
|
||||
\stored_vcol, 'end', &sw)
|
||||
\stored_vcol, 'end', shiftwidth())
|
||||
if ret | return res | endif
|
||||
else
|
||||
" Pass: we have a function reference (e.g. "fun f/0")
|
||||
@@ -1275,7 +1277,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
" when A,
|
||||
" LTI
|
||||
let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
|
||||
\stored_vcol, &sw)
|
||||
\stored_vcol, shiftwidth())
|
||||
if ret | return res | endif
|
||||
else
|
||||
" Example:
|
||||
@@ -1307,7 +1309,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
|
||||
" If LTI is between an 'after' and the corresponding
|
||||
" 'end', then let's return
|
||||
let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
|
||||
\stored_vcol, &sw)
|
||||
\stored_vcol, shiftwidth())
|
||||
if ret | return res | endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ runtime! indent/ruby.vim
|
||||
unlet! b:did_indent
|
||||
setlocal indentexpr=
|
||||
|
||||
if exists("b:eruby_subtype")
|
||||
if exists("b:eruby_subtype") && b:eruby_subtype != '' && b:eruby_subtype !=# 'eruby'
|
||||
exe "runtime! indent/".b:eruby_subtype.".vim"
|
||||
else
|
||||
runtime! indent/html.vim
|
||||
@@ -97,6 +97,7 @@ function! GetErubyIndent(...)
|
||||
let ind = ind + sw
|
||||
endif
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
||||
\ && synID(v:lnum, match(cline, '\S') + 1, 1) != hlID('htmlEndTag')
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if cline =~# '^\s*[-=]\=%>\s*$'
|
||||
|
||||
253
indent/fsharp.vim
Normal file
253
indent/fsharp.vim
Normal file
@@ -0,0 +1,253 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fsharp') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: FSharp
|
||||
" Maintainers: Jean-Francois Yuen <jfyuen@happycoders.org>
|
||||
" Mike Leary <leary@nwlink.com>
|
||||
" Markus Mottl <markus.mottl@gmail.com>
|
||||
" Rudi Grinberg <rudi.grinberg@gmail.com>
|
||||
" Gregor Uhlenheuer <kongo2002@gmail.com>
|
||||
" Last Change: 2013 Jun 29
|
||||
" 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
|
||||
" 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
|
||||
" 2013 June - commented textwidth (Marc Weber)
|
||||
" 2014 August - Ported to F#
|
||||
" 2014 August - F# specific cleanup
|
||||
"
|
||||
" Marc Weber's comment: This file may contain a lot of (very custom) stuff
|
||||
" which eventually should be moved somewhere else ..
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetFsharpIndent()
|
||||
setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0)
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetFsharpIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
" Skipping pattern, for comments
|
||||
function! s:GetLineWithoutFullComment(lnum)
|
||||
let lnum = prevnonblank(a:lnum - 1)
|
||||
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
|
||||
while lline =~ '^\s*$' && lnum > 0
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" Indent for ';;' to match multiple 'let'
|
||||
function! s:GetInd(lnum, pat, lim)
|
||||
let llet = search(a:pat, 'bW')
|
||||
let old = indent(a:lnum)
|
||||
while llet > 0
|
||||
let old = indent(llet)
|
||||
let nb = s:GetLineWithoutFullComment(llet)
|
||||
if getline(nb) =~ a:lim
|
||||
return old
|
||||
endif
|
||||
let llet = search(a:pat, 'bW')
|
||||
endwhile
|
||||
return old
|
||||
endfunction
|
||||
|
||||
" Indent pairs
|
||||
function! s:FindPair(pstart, pmid, pend)
|
||||
call search(a:pend, 'bW')
|
||||
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
|
||||
endfunction
|
||||
|
||||
" Indent 'let'
|
||||
function! s:FindLet(pstart, pmid, pend)
|
||||
call search(a:pend, 'bW')
|
||||
return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\<in\\s*$" || getline(prevnonblank(".") - 1) =~ s:beflet'))
|
||||
endfunction
|
||||
|
||||
function! GetFsharpIndent()
|
||||
" Find a non-commented line above the current line.
|
||||
let lnum = s:GetLineWithoutFullComment(v:lnum)
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(lnum)
|
||||
let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
|
||||
|
||||
" " Return single 'shiftwidth' after lines matching:
|
||||
" if lline =~ '^\s*|.*->\s*$'
|
||||
" return ind + &sw
|
||||
" endif
|
||||
|
||||
let line = getline(v:lnum)
|
||||
|
||||
" Indent if current line begins with 'end':
|
||||
if line =~ '^\s*end\>'
|
||||
return s:FindPair(s:module, '','\<end\>')
|
||||
|
||||
" Indent if current line begins with 'done' for 'do':
|
||||
elseif line =~ '^\s*done\>'
|
||||
return s:FindPair('\<do\>', '','\<done\>')
|
||||
|
||||
" Indent if current line begins with '}' or '>}':
|
||||
elseif line =~ '^\s*\(\|>\)}'
|
||||
return s:FindPair('{', '','}')
|
||||
|
||||
" Indent if current line begins with ']', '|]' or '>]':
|
||||
elseif line =~ '^\s*\(\||\|>\)\]'
|
||||
return s:FindPair('\[', '','\]')
|
||||
|
||||
" Indent if current line begins with ')':
|
||||
elseif line =~ '^\s*)'
|
||||
return s:FindPair('(', '',')')
|
||||
|
||||
" Indent if current line begins with 'let':
|
||||
elseif line =~ '^\s*let\>'
|
||||
if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet
|
||||
return s:FindLet(s:type, '','\<let\s*$')
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'class' or 'type':
|
||||
elseif line =~ '^\s*\(class\|type\)\>'
|
||||
if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim
|
||||
return s:FindLet(s:type, '','\<\(class\|type\)\s*$')
|
||||
endif
|
||||
|
||||
" Indent for pattern matching:
|
||||
elseif line =~ '^\s*|'
|
||||
if lline !~ '^\s*\(|[^\]]\|\(match\|type\|with\)\>\)\|\<\(function\|private\|with\)\s*$'
|
||||
call search('|', 'bW')
|
||||
return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"'))
|
||||
endif
|
||||
|
||||
" Indent if current line begins with ';;':
|
||||
elseif line =~ '^\s*;;'
|
||||
if lline !~ ';;\s*$'
|
||||
return s:GetInd(v:lnum, s:letpat, s:letlim)
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'in':
|
||||
elseif line =~ '^\s*in\>'
|
||||
if lline !~ '^\s*\(let\|and\)\>'
|
||||
return s:FindPair('\<let\>', '', '\<in\>')
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'else':
|
||||
elseif line =~ '^\s*else\>'
|
||||
if lline !~ '^\s*\(if\|then\)\>'
|
||||
return s:FindPair('\<if\>', '', '\<else\>')
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'then':
|
||||
elseif line =~ '^\s*then\>'
|
||||
if lline !~ '^\s*\(if\|else\)\>'
|
||||
return s:FindPair('\<if\>', '', '\<then\>')
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'and':
|
||||
elseif line =~ '^\s*and\>'
|
||||
if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
|
||||
return ind - &sw
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'with':
|
||||
elseif line =~ '^\s*with\>'
|
||||
if lline !~ '^\s*\(match\|try\)\>'
|
||||
return s:FindPair('\<\%(match\|try\)\>', '','\<with\>')
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'exception', 'external', 'include' or
|
||||
" 'open':
|
||||
elseif line =~ '^\s*\(exception\|external\|include\|open\)\>'
|
||||
if lline !~ s:lim . '\|' . s:letlim
|
||||
call search(line)
|
||||
return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW'))
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'val':
|
||||
elseif line =~ '^\s*val\>'
|
||||
if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim
|
||||
return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW'))
|
||||
endif
|
||||
|
||||
" Indent if current line begins with 'constraint', 'inherit', 'initializer'
|
||||
" or 'method':
|
||||
elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
|
||||
if lline !~ s:obj
|
||||
return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
" Add a 'shiftwidth' after lines ending with:
|
||||
if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
|
||||
let ind = ind + &sw
|
||||
|
||||
" Back to normal indent after lines ending with ';;':
|
||||
elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
|
||||
let ind = s:GetInd(v:lnum, s:letpat, s:letlim)
|
||||
|
||||
" Back to normal indent after lines ending with 'end':
|
||||
elseif lline =~ '\<end\s*$'
|
||||
let ind = s:FindPair(s:module, '','\<end\>')
|
||||
|
||||
" Back to normal indent after lines ending with 'in':
|
||||
elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>'
|
||||
let ind = s:FindPair('\<let\>', '', '\<in\>')
|
||||
|
||||
" Back to normal indent after lines ending with 'done':
|
||||
elseif lline =~ '\<done\s*$'
|
||||
let ind = s:FindPair('\<do\>', '','\<done\>')
|
||||
|
||||
" Back to normal indent after lines ending with '}' or '>}':
|
||||
elseif lline =~ '\(\|>\)}\s*$'
|
||||
let ind = s:FindPair('{', '','}')
|
||||
|
||||
" Back to normal indent after lines ending with ']', '|]' or '>]':
|
||||
elseif lline =~ '\(\||\|>\)\]\s*$'
|
||||
let ind = s:FindPair('\[', '','\]')
|
||||
|
||||
" Back to normal indent after comments:
|
||||
elseif lline =~ '\*)\s*$'
|
||||
call search('\*)', 'bW')
|
||||
let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
|
||||
|
||||
" Back to normal indent after lines ending with ')':
|
||||
elseif lline =~ ')\s*$'
|
||||
let ind = s:FindPair('(', '',')')
|
||||
|
||||
" If this is a multiline comment then align '*':
|
||||
elseif lline =~ '^\s*(\*' && line =~ '^\s*\*'
|
||||
let ind = ind + 1
|
||||
|
||||
else
|
||||
" Don't change indentation of this line
|
||||
" for new lines (indent==0) use indentation of previous line
|
||||
|
||||
" This is for preventing removing indentation of these args:
|
||||
" let f x =
|
||||
" let y = x + 1 in
|
||||
" Printf.printf
|
||||
" "o" << here
|
||||
" "oeuth" << don't touch indentation
|
||||
|
||||
let i = indent(v:lnum)
|
||||
return i == 0 ? ind : i
|
||||
|
||||
endif
|
||||
|
||||
return ind
|
||||
|
||||
endfunction
|
||||
|
||||
" vim: sw=4 et sts=4
|
||||
|
||||
endif
|
||||
@@ -8,6 +8,7 @@ if exists("b:did_indent")
|
||||
endif
|
||||
|
||||
setlocal autoindent cindent
|
||||
setlocal formatoptions+=roq
|
||||
|
||||
" vim:set sts=2 sw=2 :
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:haskell_indent_disable')
|
||||
let g:haskell_indent_disable = 0
|
||||
if get(g:, 'haskell_indent_disable', 0)
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:haskell_indent_if')
|
||||
" if x
|
||||
" >>>then ...
|
||||
@@ -36,9 +36,18 @@ endif
|
||||
if !exists('g:haskell_indent_let')
|
||||
" let x = 0 in
|
||||
" >>>>x
|
||||
"
|
||||
" let x = 0
|
||||
" y = 1
|
||||
let g:haskell_indent_let = 4
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_let_no_in')
|
||||
" let x = 0
|
||||
" x
|
||||
let g:haskell_indent_let_no_in = 4
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_where')
|
||||
" where f :: Int -> Int
|
||||
" >>>>>>f x = x
|
||||
@@ -63,22 +72,16 @@ if !exists('g:haskell_indent_guard')
|
||||
let g:haskell_indent_guard = 2
|
||||
endif
|
||||
|
||||
if exists("g:haskell_indent_disable") && g:haskell_indent_disable == 0
|
||||
setlocal indentexpr=GetHaskellIndent()
|
||||
setlocal indentkeys=0{,0},0(,0),0[,0],!^F,o,O,0\=,0=where,0=let,0=deriving,<space>
|
||||
else
|
||||
setlocal nocindent
|
||||
setlocal nosmartindent
|
||||
setlocal autoindent
|
||||
endif
|
||||
setlocal indentkeys=0},0),0],!^F,o,O,0=where,0=let,0=deriving,<space>
|
||||
|
||||
function! s:isInBlock(hlstack)
|
||||
return index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1 || index(a:hlstack, 'haskellBlockComment') > -1 || index(a:hlstack, 'haskellPragma') > -1
|
||||
return index(a:hlstack, 'haskellDelimiter') > -1 || index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1 || index(a:hlstack, 'haskellBlockComment') > -1 || index(a:hlstack, 'haskellPragma') > -1
|
||||
endfunction
|
||||
|
||||
function! s:stripTrailingComment(line)
|
||||
if a:line =~ '^\s*--\(-\+\|\s\+\)' || a:line =~ '^\s*{-'
|
||||
return a:line
|
||||
function! s:stripComment(line)
|
||||
if a:line =~ '^\s*--\(-*\s\+\|$\)'
|
||||
return ''
|
||||
else
|
||||
let l:stripped = split(a:line, '-- ')
|
||||
if len(l:stripped) > 1
|
||||
@@ -144,7 +147,7 @@ function! GetHaskellIndent()
|
||||
return -1
|
||||
endif
|
||||
|
||||
let l:prevline = s:stripTrailingComment(getline(v:lnum - 1))
|
||||
let l:prevline = s:stripComment(getline(v:lnum - 1))
|
||||
let l:line = getline(v:lnum)
|
||||
|
||||
" indent multiline strings
|
||||
@@ -161,14 +164,6 @@ function! GetHaskellIndent()
|
||||
return 0
|
||||
endif
|
||||
|
||||
" comment indentation
|
||||
if l:line =~ '^\s*--'
|
||||
return match(l:prevline, '-- ')
|
||||
endif
|
||||
if l:prevline =~ '^\s*--'
|
||||
return match(l:prevline, '\S')
|
||||
endif
|
||||
|
||||
" { foo :: Int
|
||||
" >>,
|
||||
"
|
||||
@@ -176,7 +171,7 @@ function! GetHaskellIndent()
|
||||
" ...
|
||||
" >>,
|
||||
if l:line =~ '^\s*,'
|
||||
if s:isInBlock(l:hlstack)
|
||||
if s:isInBlock(s:getHLStack(line('.'), col('.')))
|
||||
normal! 0
|
||||
call search(',', 'cW')
|
||||
let l:n = s:getNesting(s:getHLStack(line('.'), col('.')))
|
||||
@@ -224,6 +219,9 @@ function! GetHaskellIndent()
|
||||
"
|
||||
" let x = 1
|
||||
" >>>>y = 2
|
||||
"
|
||||
" let x = 1
|
||||
" y 2
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+$'
|
||||
if l:line =~ '\C^\s*\<let\>'
|
||||
let l:s = match(l:prevline, '\C\<let\>')
|
||||
@@ -235,11 +233,16 @@ function! GetHaskellIndent()
|
||||
if s:isSYN('haskellLet', v:lnum - 1, l:s + 1)
|
||||
return l:s + g:haskell_indent_in
|
||||
endif
|
||||
else
|
||||
elseif l:line =~ '\s=\s'
|
||||
let l:s = match(l:prevline, '\C\<let\>')
|
||||
if s:isSYN('haskellLet', v:lnum - 1, l:s + 1)
|
||||
return l:s + g:haskell_indent_let
|
||||
endif
|
||||
else
|
||||
let l:s = match(l:prevline, '\C\<let\>')
|
||||
if s:isSYN('haskellLet', v:lnum - 1, l:s + 1)
|
||||
return l:s + g:haskell_indent_let_no_in
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -259,12 +262,16 @@ function! GetHaskellIndent()
|
||||
" where
|
||||
" >>foo
|
||||
"
|
||||
if l:prevline =~ '\C\<where\>\s*$'
|
||||
return match(l:prevline, '\S') + get(g:, 'haskell_indent_after_bare_where', &shiftwidth)
|
||||
endif
|
||||
|
||||
" do
|
||||
" >>foo
|
||||
"
|
||||
" foo =
|
||||
" >>bar
|
||||
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\)\s*$'
|
||||
if l:prevline =~ '\C\(\<do\>\|=\)\s*$'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
@@ -280,7 +287,7 @@ function! GetHaskellIndent()
|
||||
" case foo of
|
||||
" >>bar -> quux
|
||||
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
|
||||
if exists('g:haskell_indent_case_alternative') && g:haskell_indent_case_alternative
|
||||
if get(g:,'haskell_indent_case_alternative', 0)
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
else
|
||||
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
|
||||
@@ -320,6 +327,14 @@ function! GetHaskellIndent()
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo :: Int
|
||||
" -> Int
|
||||
" >>>>-> Int
|
||||
"
|
||||
" foo :: Monad m
|
||||
" => Functor f
|
||||
" >>>>=> Int
|
||||
"
|
||||
" foo :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
@@ -328,9 +343,12 @@ function! GetHaskellIndent()
|
||||
" :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
if l:prevline =~ '^\s*[-=]>' && l:line !~ '^\s*[-=]>'
|
||||
if l:prevline =~ '^\s*[-=]>'
|
||||
if l:line =~ '^\s*[-=]>'
|
||||
return match(l:prevline, '[-=]')
|
||||
else
|
||||
if s:isInBlock(l:hlstack)
|
||||
return match(l:prevline, '[^\s-=>]')
|
||||
return match(l:prevline, '[^-=]')
|
||||
else
|
||||
let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze')
|
||||
let l:l = l:prevline
|
||||
@@ -356,6 +374,7 @@ function! GetHaskellIndent()
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" | otherwise = ...
|
||||
" foo
|
||||
@@ -395,7 +414,7 @@ function! GetHaskellIndent()
|
||||
|
||||
" foo
|
||||
" >>{
|
||||
if l:line =~ '^\s*{' && l:prevline !~ '^{'
|
||||
if l:line =~ '^\s*{ '
|
||||
let l:s = match(l:prevline, '\S')
|
||||
if l:s >= 0
|
||||
return l:s + &shiftwidth
|
||||
@@ -404,12 +423,17 @@ function! GetHaskellIndent()
|
||||
|
||||
" in foo
|
||||
" where bar
|
||||
"
|
||||
" or
|
||||
"
|
||||
" foo
|
||||
" >>where
|
||||
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
|
||||
return match(l:prevline, '\S') + get(g:, 'haskell_indent_before_where', &shiftwidth)
|
||||
endif
|
||||
|
||||
" let x = 1
|
||||
@@ -477,16 +501,7 @@ function! GetHaskellIndent()
|
||||
return s:indentMatching(']')
|
||||
endif
|
||||
|
||||
" do not reindent indented lines
|
||||
if match(l:prevline, '\S') < match(l:line, '\S')
|
||||
return -1
|
||||
endif
|
||||
|
||||
if l:line !~ '^\s*[=-]>\s' && l:line =~ '^\s*[!#$%&*+./<>?@\\^|~-]\+'
|
||||
return -1
|
||||
endif
|
||||
|
||||
return match(l:prevline, '\S')
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
@@ -260,20 +260,28 @@ let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
|
||||
" [-- count indent-increasing tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentOpen(lnum, pattern)
|
||||
let s = substitute('x'.getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g')
|
||||
func! <SID>HtmlIndentPatternCount(content, pattern)
|
||||
let s = substitute('x'.a:content, a:pattern, "\1", 'g')
|
||||
let s = substitute(s, "[^\1].*$", '', '')
|
||||
return strlen(s)
|
||||
endfun
|
||||
|
||||
" [-- count indent-increasing tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentOpen(lnum, pattern)
|
||||
return <SID>HtmlIndentPatternCount(getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)')
|
||||
endfun
|
||||
|
||||
" [-- count indent-decreasing tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentClose(lnum, pattern)
|
||||
let s = substitute('x'.getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g')
|
||||
let s = substitute(s, "[^\1].*$", '', '')
|
||||
return strlen(s)
|
||||
return <SID>HtmlIndentPatternCount(getline(a:lnum),
|
||||
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)')
|
||||
endfun
|
||||
|
||||
" [-- count self close tags of line a:lnum --]
|
||||
fun! <SID>HtmlIndentSelfClose(lnum, pattern)
|
||||
return <SID>HtmlIndentPatternCount(getline(a:lnum),
|
||||
\ '.\{-}\(\(<\('.a:pattern.'\).*\)\@<!\/>\)')
|
||||
endfun
|
||||
|
||||
" [-- count indent-increasing '{' of (java|css) line a:lnum --]
|
||||
@@ -292,8 +300,9 @@ fun! <SID>HtmlIndentSum(lnum, style)
|
||||
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
|
||||
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) - <SID>HtmlIndentOpen(a:lnum, s:html_noindent_tags)
|
||||
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
|
||||
if 0 != open || 0 != close
|
||||
return open - close
|
||||
let self_close = <SID>HtmlIndentSelfClose(a:lnum, s:html_noindent_tags)
|
||||
if 0 != open || 0 != close || 0 != self_close
|
||||
return open - close - self_close
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@@ -310,6 +319,13 @@ fun! <SID>HtmlIndentSum(lnum, style)
|
||||
endfun
|
||||
|
||||
fun! HtmlIndentGet(lnum)
|
||||
" Get shiftwidth value.
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
" Find a non-empty line above the current line.
|
||||
let lnum = prevnonblank(a:lnum - 1)
|
||||
|
||||
@@ -396,7 +412,7 @@ fun! HtmlIndentGet(lnum)
|
||||
endif
|
||||
|
||||
if 0 == match(getline(a:lnum), '^\s*</')
|
||||
return indent(preline) - (1*&sw)
|
||||
return indent(preline) - (1*sw)
|
||||
else
|
||||
return indent(preline)
|
||||
endif
|
||||
@@ -417,7 +433,7 @@ fun! HtmlIndentGet(lnum)
|
||||
" let tags_exp = '<\(' . join(tags, '\|') . '\)>'
|
||||
" let close_tags_exp = '</\(' . join(tags, '\|') . '\)>'
|
||||
" if getline(a:lnum) =~ tags_exp
|
||||
" let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW')
|
||||
" let block_start = search('^'.repeat(' ', lind + (sw * ind - 1)).'\S' , 'bnW')
|
||||
" let prev_tag = search(tags_exp, 'bW', block_start)
|
||||
" let prev_closetag = search(close_tags_exp, 'W', a:lnum)
|
||||
" if prev_tag && !prev_closetag
|
||||
@@ -426,7 +442,7 @@ fun! HtmlIndentGet(lnum)
|
||||
" endif
|
||||
|
||||
" if getline(a:lnum) =~ '</\w\+>'
|
||||
" let block_start = search('^'.repeat(' ', lind + (&sw * ind - 1)).'\S' , 'bnW')
|
||||
" let block_start = search('^'.repeat(' ', lind + (sw * ind - 1)).'\S' , 'bnW')
|
||||
" let prev_tag = search(tags_exp, 'bW', block_start)
|
||||
" let prev_closetag = search(close_tags_exp, 'W', a:lnum)
|
||||
" if prev_tag && !prev_closetag
|
||||
@@ -439,7 +455,7 @@ fun! HtmlIndentGet(lnum)
|
||||
setlocal noic
|
||||
endif
|
||||
|
||||
return lind + (&sw * ind)
|
||||
return lind + (sw * ind)
|
||||
endfun
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
@@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') ==
|
||||
" Language: Javascript
|
||||
" Maintainer: Chris Paul ( https://github.com/bounceme )
|
||||
" URL: https://github.com/pangloss/vim-javascript
|
||||
" Last Change: January 24, 2017
|
||||
" Last Change: December 4, 2017
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists('b:did_indent')
|
||||
@@ -16,6 +16,10 @@ let b:did_indent = 1
|
||||
setlocal indentexpr=GetJavascriptIndent()
|
||||
setlocal autoindent nolisp nosmartindent
|
||||
setlocal indentkeys+=0],0)
|
||||
" Testable with something like:
|
||||
" vim -eNs "+filetype plugin indent on" "+syntax on" "+set ft=javascript" \
|
||||
" "+norm! gg=G" '+%print' '+:q!' testfile.js \
|
||||
" | diff -uBZ testfile.js -
|
||||
|
||||
let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<'
|
||||
|
||||
@@ -27,6 +31,23 @@ endif
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" indent correctly if inside <script>
|
||||
" vim/vim@690afe1 for the switch from cindent
|
||||
" overridden with b:html_indent_script1
|
||||
call extend(g:,{'html_indent_script1': 'inc'},'keep')
|
||||
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:bvars = {
|
||||
\ 'syng_strcom': 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!',
|
||||
\ 'syng_str': 'string\|template\|special' }
|
||||
" template strings may want to be excluded when editing graphql:
|
||||
" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special'
|
||||
" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc'
|
||||
|
||||
function s:GetVars()
|
||||
call extend(b:,extend(s:bvars,{'js_cache': [0,0,0]}),'keep')
|
||||
endfunction
|
||||
|
||||
" Get shiftwidth value
|
||||
if exists('*shiftwidth')
|
||||
function s:sw()
|
||||
@@ -34,259 +55,333 @@ if exists('*shiftwidth')
|
||||
endfunction
|
||||
else
|
||||
function s:sw()
|
||||
return &sw
|
||||
return &l:shiftwidth ? &l:shiftwidth : &l:tabstop
|
||||
endfunction
|
||||
endif
|
||||
|
||||
" searchpair() wrapper
|
||||
if has('reltime')
|
||||
function s:GetPair(start,end,flags,skip,time,...)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 2000,0] + a:000),a:time)
|
||||
endfunction
|
||||
else
|
||||
function s:GetPair(start,end,flags,skip,...)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,max([prevnonblank(v:lnum) - 1000,get(a:000,1)]))
|
||||
endfunction
|
||||
endif
|
||||
" Performance for forwards search(): start search at pos rather than masking
|
||||
" matches before pos.
|
||||
let s:z = has('patch-7.4.984') ? 'z' : ''
|
||||
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!'
|
||||
let s:syng_str = 'string\|template'
|
||||
let s:syng_com = 'comment\|doc'
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
|
||||
let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom"
|
||||
let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'"
|
||||
|
||||
function s:skip_func()
|
||||
if !s:free || search('\m`\|\${\|\*\/','nW',s:looksyn)
|
||||
let s:free = !eval(s:skip_expr)
|
||||
let s:looksyn = line('.')
|
||||
return !s:free
|
||||
let s:rel = has('reltime')
|
||||
" searchpair() wrapper
|
||||
if s:rel
|
||||
function s:GetPair(start,end,flags,skip)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200)
|
||||
endfunction
|
||||
else
|
||||
function s:GetPair(start,end,flags,skip)
|
||||
return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1)
|
||||
endfunction
|
||||
endif
|
||||
let s:looksyn = line('.')
|
||||
return getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' &&
|
||||
\ eval(s:skip_expr)
|
||||
|
||||
function s:SynAt(l,c)
|
||||
let byte = line2byte(a:l) + a:c - 1
|
||||
let pos = index(s:synid_cache[0], byte)
|
||||
if pos == -1
|
||||
let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]]
|
||||
endif
|
||||
return s:synid_cache[1][pos]
|
||||
endfunction
|
||||
|
||||
function s:alternatePair(stop)
|
||||
let pos = getpos('.')[1:2]
|
||||
while search('\m[][(){}]','bW',a:stop)
|
||||
if !s:skip_func()
|
||||
let idx = stridx('])}',s:looking_at())
|
||||
if idx + 1
|
||||
if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop) <= 0
|
||||
function s:ParseCino(f)
|
||||
let [divider, n, cstr] = [0] + matchlist(&cino,
|
||||
\ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2]
|
||||
for c in split(cstr,'\zs')
|
||||
if c == '.' && !divider
|
||||
let divider = 1
|
||||
elseif c ==# 's'
|
||||
if n !~ '\d'
|
||||
return n . s:sw() + 0
|
||||
endif
|
||||
let n = str2nr(n) * s:sw()
|
||||
break
|
||||
else
|
||||
let [n, divider] .= [c, 0]
|
||||
endif
|
||||
endfor
|
||||
return str2nr(n) / max([str2nr(divider),1])
|
||||
endfunction
|
||||
|
||||
" Optimized {skip} expr, only callable from the search loop which
|
||||
" GetJavascriptIndent does to find the containing [[{(] (side-effects)
|
||||
function s:SkipFunc()
|
||||
if s:top_col == 1
|
||||
throw 'out of bounds'
|
||||
elseif s:check_in
|
||||
if eval(s:skip_expr)
|
||||
return 1
|
||||
endif
|
||||
let s:check_in = 0
|
||||
elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
|
||||
if eval(s:skip_expr)
|
||||
return 1
|
||||
endif
|
||||
elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn)
|
||||
if eval(s:skip_expr)
|
||||
let s:check_in = 1
|
||||
return 1
|
||||
endif
|
||||
else
|
||||
let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']]
|
||||
endif
|
||||
let [s:looksyn, s:top_col] = getpos('.')[1:2]
|
||||
endfunction
|
||||
|
||||
function s:AlternatePair()
|
||||
let [pat, l:for] = ['[][(){};]', 2]
|
||||
while s:SearchLoop(pat,'bW','s:SkipFunc()')
|
||||
if s:LookingAt() == ';'
|
||||
if !l:for
|
||||
if s:GetPair('{','}','bW','s:SkipFunc()')
|
||||
return
|
||||
endif
|
||||
break
|
||||
else
|
||||
let [pat, l:for] = ['[{}();]', l:for - 1]
|
||||
endif
|
||||
else
|
||||
let idx = stridx('])}',s:LookingAt())
|
||||
if idx == -1
|
||||
return
|
||||
elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
|
||||
break
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
call call('cursor',pos)
|
||||
throw 'out of bounds'
|
||||
endfunction
|
||||
|
||||
function s:save_pos(f,...)
|
||||
let l:pos = getpos('.')[1:2]
|
||||
let ret = call(a:f,a:000)
|
||||
call call('cursor',l:pos)
|
||||
return ret
|
||||
function s:Nat(int)
|
||||
return a:int * (a:int > 0)
|
||||
endfunction
|
||||
|
||||
function s:syn_at(l,c)
|
||||
return synIDattr(synID(a:l,a:c,0),'name')
|
||||
endfunction
|
||||
|
||||
function s:looking_at()
|
||||
function s:LookingAt()
|
||||
return getline('.')[col('.')-1]
|
||||
endfunction
|
||||
|
||||
function s:token()
|
||||
return s:looking_at() =~ '\k' ? expand('<cword>') : s:looking_at()
|
||||
function s:Token()
|
||||
return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt()
|
||||
endfunction
|
||||
|
||||
function s:previous_token()
|
||||
let l:n = line('.')
|
||||
if (s:looking_at() !~ '\k' || search('\m\<','cbW')) && search('\m\S','bW')
|
||||
if (getline('.')[col('.')-2:col('.')-1] == '*/' || line('.') != l:n &&
|
||||
\ getline('.') =~ '\%<'.col('.').'c\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com
|
||||
while search('\m\/\ze[/*]','cbW')
|
||||
if !search('\m\S','bW')
|
||||
function s:PreviousToken(...)
|
||||
let [l:pos, tok] = [getpos('.'), '']
|
||||
if search('\m\k\{1,}\|\S','ebW')
|
||||
if getline('.')[col('.')-2:col('.')-1] == '*/'
|
||||
if eval(s:in_comm) && !s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm)
|
||||
call setpos('.',l:pos)
|
||||
else
|
||||
let tok = s:Token()
|
||||
endif
|
||||
else
|
||||
let two = a:0 || line('.') != l:pos[1] ? strridx(getline('.')[:col('.')],'//') + 1 : 0
|
||||
if two && eval(s:in_comm)
|
||||
call cursor(0,two)
|
||||
let tok = s:PreviousToken(1)
|
||||
if tok is ''
|
||||
call setpos('.',l:pos)
|
||||
endif
|
||||
else
|
||||
let tok = s:Token()
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return tok
|
||||
endfunction
|
||||
|
||||
function s:Pure(f,...)
|
||||
return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]")
|
||||
endfunction
|
||||
|
||||
function s:SearchLoop(pat,flags,expr)
|
||||
return s:GetPair(a:pat,'\_$.',a:flags,a:expr)
|
||||
endfunction
|
||||
|
||||
function s:ExprCol()
|
||||
if getline('.')[col('.')-2] == ':'
|
||||
return 1
|
||||
endif
|
||||
let bal = 0
|
||||
while s:SearchLoop('[{}?:]','bW',s:skip_expr)
|
||||
if s:LookingAt() == ':'
|
||||
if getline('.')[col('.')-2] == ':'
|
||||
call cursor(0,col('.')-1)
|
||||
continue
|
||||
endif
|
||||
let bal -= 1
|
||||
elseif s:LookingAt() == '?'
|
||||
if getline('.')[col('.'):col('.')+1] =~ '^\.\d\@!'
|
||||
continue
|
||||
elseif !bal
|
||||
return 1
|
||||
endif
|
||||
let bal += 1
|
||||
elseif s:LookingAt() == '{'
|
||||
return !s:IsBlock()
|
||||
elseif !s:GetPair('{','}','bW',s:skip_expr)
|
||||
break
|
||||
elseif s:syn_at(line('.'),col('.')) !~? s:syng_com
|
||||
return s:token()
|
||||
endif
|
||||
endwhile
|
||||
else
|
||||
return s:token()
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function s:others(p)
|
||||
return "((line2byte(line('.')) + col('.')) <= ".(line2byte(a:p[0]) + a:p[1]).") || ".s:skip_expr
|
||||
endfunction
|
||||
|
||||
function s:tern_skip(p)
|
||||
return s:GetPair('{','}','nbW',s:others(a:p),200,a:p[0]) > 0
|
||||
endfunction
|
||||
|
||||
function s:tern_col(p)
|
||||
return s:GetPair('?',':\@<!::\@!','nbW',s:others(a:p)
|
||||
\ .' || s:tern_skip('.string(a:p).')',200,a:p[0]) > 0
|
||||
endfunction
|
||||
|
||||
function s:label_col()
|
||||
let pos = getpos('.')[1:2]
|
||||
let [s:looksyn,s:free] = pos
|
||||
call s:alternatePair(0)
|
||||
if s:save_pos('s:IsBlock')
|
||||
let poss = getpos('.')[1:2]
|
||||
return call('cursor',pos) || !s:tern_col(poss)
|
||||
elseif s:looking_at() == ':'
|
||||
return !s:tern_col([0,0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" configurable regexes that define continuation lines, not including (, {, or [.
|
||||
let s:opfirst = '^' . get(g:,'javascript_opfirst',
|
||||
\ '\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)')
|
||||
\ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)')
|
||||
let s:continuation = get(g:,'javascript_continuation',
|
||||
\ '\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|delete\|void\|in\|instanceof\)\)') . '$'
|
||||
\ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
|
||||
|
||||
function s:continues(ln,con)
|
||||
return !cursor(a:ln, match(' '.a:con,s:continuation)) &&
|
||||
\ eval( (['s:syn_at(line("."),col(".")) !~? "regex"'] +
|
||||
\ repeat(['getline(".")[col(".")-2] != tr(s:looking_at(),">","=")'],3) +
|
||||
\ repeat(['s:previous_token() != "."'],5) + [1])[
|
||||
\ index(split('/ > - + typeof in instanceof void delete'),s:token())])
|
||||
endfunction
|
||||
|
||||
" get the line of code stripped of comments and move cursor to the last
|
||||
" non-comment char.
|
||||
function s:Trim(ln)
|
||||
call cursor(a:ln+1,1)
|
||||
call s:previous_token()
|
||||
return strpart(getline('.'),0,col('.'))
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty or in a comment
|
||||
function s:PrevCodeLine(lnum)
|
||||
let l:n = prevnonblank(a:lnum)
|
||||
while l:n
|
||||
if getline(l:n) =~ '^\s*\/[/*]'
|
||||
if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') &&
|
||||
\ s:syn_at(l:n,1) =~? s:syng_str
|
||||
return l:n
|
||||
function s:Continues()
|
||||
let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation)
|
||||
if tok =~ '[a-z:]'
|
||||
return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.'
|
||||
elseif tok !~ '[/>]'
|
||||
return tok isnot ''
|
||||
endif
|
||||
let l:n = prevnonblank(l:n-1)
|
||||
elseif s:syn_at(l:n,1) =~? s:syng_com
|
||||
let l:n = s:save_pos('eval',
|
||||
\ 'cursor('.l:n.',1) + search(''\m\/\*'',"bW")')
|
||||
else
|
||||
return l:n
|
||||
endif
|
||||
endwhile
|
||||
return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex')
|
||||
endfunction
|
||||
|
||||
" Check if line 'lnum' has a balanced amount of parentheses.
|
||||
function s:Balanced(lnum)
|
||||
function s:Balanced(lnum,line)
|
||||
let l:open = 0
|
||||
let l:line = getline(a:lnum)
|
||||
let pos = match(l:line, '[][(){}]', 0)
|
||||
let pos = match(a:line, '[][(){}]')
|
||||
while pos != -1
|
||||
if s:syn_at(a:lnum,pos + 1) !~? s:syng_strcom
|
||||
let l:open += match(' ' . l:line[pos],'[[({]')
|
||||
if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom
|
||||
let l:open += match(' ' . a:line[pos],'[[({]')
|
||||
if l:open < 0
|
||||
return
|
||||
endif
|
||||
endif
|
||||
let pos = match(l:line, '[][(){}]', pos + 1)
|
||||
let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ?
|
||||
\ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1)
|
||||
endwhile
|
||||
return !l:open
|
||||
endfunction
|
||||
|
||||
function s:OneScope(lnum)
|
||||
let pline = s:Trim(a:lnum)
|
||||
let kw = 'else do'
|
||||
if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
|
||||
call s:previous_token()
|
||||
let kw = 'for if let while with'
|
||||
if index(split('await each'),s:token()) + 1
|
||||
call s:previous_token()
|
||||
let kw = 'for'
|
||||
function s:OneScope()
|
||||
if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr)
|
||||
let tok = s:PreviousToken()
|
||||
return (count(split('for if let while with'),tok) ||
|
||||
\ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') &&
|
||||
\ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile())
|
||||
elseif s:Token() =~# '^else$\|^do$'
|
||||
return s:Pure('s:PreviousToken') != '.'
|
||||
elseif strpart(getline('.'),col('.')-2,2) == '=>'
|
||||
call cursor(0,col('.')-1)
|
||||
if s:PreviousToken() == ')'
|
||||
return s:GetPair('(', ')', 'bW', s:skip_expr)
|
||||
endif
|
||||
return 1
|
||||
endif
|
||||
return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 &&
|
||||
\ s:save_pos('s:previous_token') != '.'
|
||||
endfunction
|
||||
|
||||
" returns braceless levels started by 'i' and above lines * &sw. 'num' is the
|
||||
" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is
|
||||
" a continued expression, which could have started in a braceless context
|
||||
function s:iscontOne(i,num,cont)
|
||||
let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0]
|
||||
let pind = a:num ? indent(l:num) + s:W : 0
|
||||
let ind = indent(l:i) + (a:cont ? 0 : s:W)
|
||||
while l:i >= l:num && (ind > pind || l:i == l:num)
|
||||
if indent(l:i) < ind && s:OneScope(l:i)
|
||||
let bL += s:W
|
||||
let l:i = line('.')
|
||||
elseif !a:cont || bL || ind < indent(a:i)
|
||||
function s:DoWhile()
|
||||
let cpos = searchpos('\m\<','cbW')
|
||||
while s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr)
|
||||
if s:LookingAt() =~ '\a'
|
||||
if s:Pure('s:IsBlock')
|
||||
if s:LookingAt() ==# 'd'
|
||||
return 1
|
||||
endif
|
||||
break
|
||||
endif
|
||||
elseif s:LookingAt() != '}' || !s:GetPair('{','}','bW',s:skip_expr)
|
||||
break
|
||||
endif
|
||||
let ind = min([ind, indent(l:i)])
|
||||
let l:i = s:PrevCodeLine(l:i - 1)
|
||||
endwhile
|
||||
return bL
|
||||
call call('cursor',cpos)
|
||||
endfunction
|
||||
|
||||
" returns total offset from braceless contexts. 'num' is the lineNr which
|
||||
" encloses the entire context, 'cont' if whether a:firstline is a continued
|
||||
" expression, which could have started in a braceless context
|
||||
function s:IsContOne(cont)
|
||||
let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0]
|
||||
let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0
|
||||
let ind = indent('.') + !a:cont
|
||||
while line('.') > l:num && ind > pind || line('.') == l:num
|
||||
if indent('.') < ind && s:OneScope()
|
||||
let b_l += 1
|
||||
elseif !a:cont || b_l || ind < indent(a:firstline)
|
||||
break
|
||||
else
|
||||
call cursor(0,1)
|
||||
endif
|
||||
let ind = min([ind, indent('.')])
|
||||
if s:PreviousToken() is ''
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
return b_l
|
||||
endfunction
|
||||
|
||||
function s:IsSwitch()
|
||||
call call('cursor',b:js_cache[1:])
|
||||
return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z)
|
||||
endfunction
|
||||
|
||||
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
|
||||
function s:IsBlock()
|
||||
if s:looking_at() == '{'
|
||||
let l:n = line('.')
|
||||
let char = s:previous_token()
|
||||
let syn = char =~ '[{>/]' ? s:syn_at(line('.'),col('.')-(char == '{')) : ''
|
||||
if syn =~? 'xml\|jsx'
|
||||
return char != '{'
|
||||
elseif char =~ '\k'
|
||||
return index(split('return const let import export yield default delete var await void typeof throw case new in instanceof')
|
||||
\ ,char) < (line('.') != l:n) || s:previous_token() == '.'
|
||||
elseif char == '>'
|
||||
return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow'
|
||||
elseif char == ':'
|
||||
return getline('.')[col('.')-2] != ':' && s:label_col()
|
||||
let tok = s:PreviousToken()
|
||||
if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx'
|
||||
let s:in_jsx = 1
|
||||
return tok != '{'
|
||||
elseif tok =~ '\k'
|
||||
if tok ==# 'type'
|
||||
return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'")
|
||||
elseif tok ==# 'of'
|
||||
return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||"
|
||||
\ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'")
|
||||
endif
|
||||
return syn =~? 'regex' || char !~ '[=~!<*,/?^%|&([]' &&
|
||||
\ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char)
|
||||
return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof')
|
||||
\ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.'
|
||||
elseif tok == '>'
|
||||
return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html'
|
||||
elseif tok == '*'
|
||||
return s:Pure('s:PreviousToken') == ':'
|
||||
elseif tok == ':'
|
||||
return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()")
|
||||
elseif tok == '/'
|
||||
return s:SynAt(line('.'),col('.')) =~? 'regex'
|
||||
elseif tok !~ '[=~!<,.?^%|&([]'
|
||||
return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function GetJavascriptIndent()
|
||||
let b:js_cache = get(b:,'js_cache',[0,0,0])
|
||||
" Get the current line.
|
||||
call cursor(v:lnum,1)
|
||||
let l:line = getline('.')
|
||||
let syns = s:syn_at(v:lnum, 1)
|
||||
call s:GetVars()
|
||||
let s:synid_cache = [[],[]]
|
||||
let l:line = getline(v:lnum)
|
||||
" use synstack as it validates syn state and works in an empty line
|
||||
let s:stack = [''] + map(synstack(v:lnum,1),"synIDattr(v:val,'name')")
|
||||
|
||||
" start with strings,comments,etc.
|
||||
if syns =~? s:syng_com
|
||||
if s:stack[-1] =~? 'comment\|doc'
|
||||
if l:line =~ '^\s*\*'
|
||||
return cindent(v:lnum)
|
||||
elseif l:line !~ '^\s*\/[/*]'
|
||||
return -1
|
||||
endif
|
||||
elseif syns =~? s:syng_str && l:line !~ '^[''"]'
|
||||
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1)
|
||||
elseif s:stack[-1] =~? b:syng_str
|
||||
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))
|
||||
let b:js_cache[0] = v:lnum
|
||||
endif
|
||||
return -1
|
||||
endif
|
||||
let l:lnum = s:PrevCodeLine(v:lnum - 1)
|
||||
if !l:lnum
|
||||
|
||||
let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000),
|
||||
\ get(get(b:,'hi_indent',{}),'blocklnr')])
|
||||
call cursor(v:lnum,1)
|
||||
if s:PreviousToken() is ''
|
||||
return
|
||||
endif
|
||||
let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]]
|
||||
|
||||
let l:line = substitute(l:line,'^\s*','','')
|
||||
let l:line_raw = l:line
|
||||
if l:line[:1] == '/*'
|
||||
let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','')
|
||||
endif
|
||||
@@ -295,64 +390,92 @@ function GetJavascriptIndent()
|
||||
endif
|
||||
|
||||
" the containing paren, bracket, or curly. Many hacks for performance
|
||||
call cursor(v:lnum,1)
|
||||
let idx = index([']',')','}'],l:line[0])
|
||||
if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum &&
|
||||
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
|
||||
if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum ||
|
||||
\ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline)
|
||||
call call('cursor',b:js_cache[1:])
|
||||
else
|
||||
let [s:looksyn, s:free, top] = [v:lnum - 1, 1, (!indent(l:lnum) &&
|
||||
\ s:syn_at(l:lnum,1) !~? s:syng_str) * l:lnum]
|
||||
if idx + 1
|
||||
call s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,top)
|
||||
elseif indent(v:lnum) && syns =~? 'block'
|
||||
call s:GetPair('{','}','bW','s:skip_func()',2000,top)
|
||||
let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0,
|
||||
\ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])]
|
||||
try
|
||||
if idx != -1
|
||||
call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()')
|
||||
elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$'
|
||||
call s:GetPair('{','}','bW','s:SkipFunc()')
|
||||
else
|
||||
call s:alternatePair(top)
|
||||
call s:AlternatePair()
|
||||
endif
|
||||
catch /^\Cout of bounds$/
|
||||
call cursor(v:lnum,1)
|
||||
endtry
|
||||
let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2]
|
||||
endif
|
||||
|
||||
let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [0,0] : getpos('.')[1:2])
|
||||
let num = b:js_cache[1]
|
||||
let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]]
|
||||
|
||||
let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0]
|
||||
if !num || s:IsBlock()
|
||||
let [num_ind, is_op, b_l, l:switch_offset, s:in_jsx] = [s:Nat(indent(num)),0,0,0,0]
|
||||
if !num || s:LookingAt() == '{' && s:IsBlock()
|
||||
let ilnum = line('.')
|
||||
let pline = s:save_pos('s:Trim',l:lnum)
|
||||
if num && s:looking_at() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
|
||||
let num = ilnum == num ? line('.') : num
|
||||
if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.'
|
||||
if &cino !~ ':'
|
||||
let switch_offset = s:W
|
||||
else
|
||||
let cinc = matchlist(&cino,'.*:\zs\(-\)\=\(\d*\)\(\.\d\+\)\=\(s\)\=\C')
|
||||
let switch_offset = max([cinc[0] is '' ? 0 : (cinc[1].1) *
|
||||
\ ((strlen(cinc[2].cinc[3]) ? str2nr(cinc[2].str2nr(cinc[3][1])) : 10) *
|
||||
\ (cinc[4] is '' ? 1 : s:W)) / 10, -indent(num)])
|
||||
if num && !s:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr)
|
||||
if ilnum == num
|
||||
let [num, num_ind] = [line('.'), indent('.')]
|
||||
endif
|
||||
if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch()
|
||||
let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':')
|
||||
if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
|
||||
return indent(num) + switch_offset
|
||||
return s:Nat(num_ind + l:switch_offset)
|
||||
elseif &cino =~ '='
|
||||
let l:case_offset = s:ParseCino('=')
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if idx < 0 && pline !~ '[{;]$'
|
||||
if pline =~# ':\@<!:$'
|
||||
call cursor(l:lnum,strlen(pline))
|
||||
let isOp = s:tern_col(b:js_cache[1:2]) * s:W
|
||||
if idx == -1 && pline[-1:] !~ '[{;]'
|
||||
call cursor(l:lnum, len(pline))
|
||||
let sol = matchstr(l:line,s:opfirst)
|
||||
if sol is '' || sol == '/' && s:SynAt(v:lnum,
|
||||
\ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex'
|
||||
if s:Continues()
|
||||
let is_op = s:sw()
|
||||
endif
|
||||
elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' &&
|
||||
\ s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) &&
|
||||
\ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) &&
|
||||
\ (s:PreviousToken() == ']' || s:LookingAt() =~ '\k' &&
|
||||
\ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function')
|
||||
return num_ind + s:sw()
|
||||
else
|
||||
let isOp = (l:line =~# s:opfirst || s:continues(l:lnum,pline)) * s:W
|
||||
let is_op = s:sw()
|
||||
endif
|
||||
let bL = s:iscontOne(l:lnum,b:js_cache[1],isOp)
|
||||
let bL -= (bL && l:line[0] == '{') * s:W
|
||||
call cursor(l:lnum, len(pline))
|
||||
let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw()
|
||||
endif
|
||||
elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U'))
|
||||
let pval = s:ParseCino('(')
|
||||
if !pval
|
||||
let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')]
|
||||
if search('\m\S','W',num)
|
||||
return s:ParseCino('w') ? vcol : virtcol('.')-1
|
||||
endif
|
||||
return Wval ? s:Nat(num_ind + Wval) : vcol
|
||||
endif
|
||||
return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw())
|
||||
endif
|
||||
|
||||
" main return
|
||||
if idx + 1 || l:line[:1] == '|}'
|
||||
return indent(num)
|
||||
elseif num
|
||||
return indent(num) + s:W + switch_offset + bL + isOp
|
||||
if l:line =~ '^[])}]\|^|}'
|
||||
if l:line_raw[0] == ')'
|
||||
if s:ParseCino('M')
|
||||
return indent(l:lnum)
|
||||
elseif num && &cino =~# 'm' && !s:ParseCino('m')
|
||||
return virtcol('.') - 1
|
||||
endif
|
||||
return bL + isOp
|
||||
endif
|
||||
return num_ind
|
||||
elseif num
|
||||
return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op)
|
||||
endif
|
||||
return b_l + is_op
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
223
indent/julia.vim
223
indent/julia.vim
@@ -3,13 +3,13 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'julia') == -1
|
||||
" Vim indent file
|
||||
" Language: Julia
|
||||
" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
|
||||
" Last Change: 2011 dec 11
|
||||
" Notes: based on Bram Moneaar's indent file for vim
|
||||
" Last Change: 2016 jun 16
|
||||
" Notes: originally based on Bram Molenaar's indent file for vim
|
||||
|
||||
setlocal autoindent
|
||||
|
||||
setlocal indentexpr=GetJuliaIndent()
|
||||
setlocal indentkeys+==end,=else,=catch,=finally
|
||||
setlocal indentkeys+==end,=else,=catch,=finally,),],}
|
||||
setlocal indentkeys-=0#
|
||||
setlocal indentkeys-=:
|
||||
setlocal indentkeys-=0{
|
||||
@@ -21,12 +21,16 @@ if exists("*GetJuliaIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:skipPatterns = '\<julia\%(Comment\)\>'
|
||||
let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeEnd\|CommentL\|\%([bsv]\|ip\|big\|MIME\|Shell\|Printf\|Doc\)\=String\|RegEx\|SymbolS\?\)\>'
|
||||
|
||||
function JuliaMatch(lnum, str, regex, st)
|
||||
function JuliaMatch(lnum, str, regex, st, ...)
|
||||
let s = a:st
|
||||
let e = a:0 > 0 ? a:1 : -1
|
||||
while 1
|
||||
let f = match(a:str, a:regex, s)
|
||||
if e >= 0 && f >= e
|
||||
return -1
|
||||
endif
|
||||
if f >= 0
|
||||
let attr = synIDattr(synID(a:lnum,f+1,1),"name")
|
||||
if attr =~ s:skipPatterns
|
||||
@@ -39,15 +43,16 @@ function JuliaMatch(lnum, str, regex, st)
|
||||
return f
|
||||
endfunction
|
||||
|
||||
function GetJuliaNestingStruct(lnum)
|
||||
function GetJuliaNestingStruct(lnum, ...)
|
||||
" Auxiliary function to inspect the block structure of a line
|
||||
let line = getline(a:lnum)
|
||||
let s = 0
|
||||
let s = a:0 > 0 ? a:1 : 0
|
||||
let e = a:0 > 1 ? a:2 : -1
|
||||
let blocks_stack = []
|
||||
let num_closed_blocks = 0
|
||||
while 1
|
||||
let fb = JuliaMatch(a:lnum, line, '@\@<!\<\%(if\|else\%(if\)\=\|while\|for\|try\|catch\|finally\|function\|macro\|begin\|type\|immutable\|let\|\%(bare\)\?module\|quote\|do\)\>', s)
|
||||
let fe = JuliaMatch(a:lnum, line, '@\@<!\<end\>', s)
|
||||
let fb = JuliaMatch(a:lnum, line, '@\@<!\<\%(if\|else\%(if\)\=\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|\%(\%(abstract\|primitive\)\s\+\)\@<!type\|immutable\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
|
||||
let fe = JuliaMatch(a:lnum, line, '@\@<!\<end\>', s, e)
|
||||
|
||||
if fb < 0 && fe < 0
|
||||
" No blocks found
|
||||
@@ -128,9 +133,13 @@ function GetJuliaNestingStruct(lnum)
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '@\@<!\<\%(while\|for\|function\|macro\|begin\|type\|immutable\|let\|quote\|do\)\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '@\@<!\<\%(while\|for\|\%(staged\)\?function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(\%(abstract\|primitive\)\s\+\)\?type\|immutable\|let\|quote\|do\)\>', s)
|
||||
if i >= 0 && i == fb
|
||||
if match(line, '\<\%(mutable\|abstract\|primitive\)', i) != -1
|
||||
let s = i+11
|
||||
else
|
||||
let s = i+1
|
||||
endif
|
||||
call add(blocks_stack, 'other')
|
||||
continue
|
||||
endif
|
||||
@@ -158,6 +167,128 @@ function GetJuliaNestingStruct(lnum)
|
||||
return [num_open_blocks, num_closed_blocks]
|
||||
endfunction
|
||||
|
||||
function GetJuliaNestingBrackets(lnum, c)
|
||||
" Auxiliary function to inspect the brackets structure of a line
|
||||
let line = getline(a:lnum)[0 : (a:c - 1)]
|
||||
let s = 0
|
||||
let brackets_stack = []
|
||||
let last_closed_bracket = -1
|
||||
while 1
|
||||
let fb = JuliaMatch(a:lnum, line, '[([{]', s)
|
||||
let fe = JuliaMatch(a:lnum, line, '[])}]', s)
|
||||
|
||||
if fb < 0 && fe < 0
|
||||
" No brackets found
|
||||
break
|
||||
end
|
||||
|
||||
if fb >= 0 && (fb < fe || fe < 0)
|
||||
" The first occurrence is an opening bracket
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '(', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
call add(brackets_stack, ['par',i])
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '\[', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
call add(brackets_stack, ['sqbra',i])
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '{', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
call add(brackets_stack, ['curbra',i])
|
||||
continue
|
||||
endif
|
||||
|
||||
" Note: it should be impossible to get here
|
||||
break
|
||||
|
||||
else
|
||||
" The first occurrence is a closing bracket
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, ')', s)
|
||||
if i >= 0 && i == fe
|
||||
let s = i+1
|
||||
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'par'
|
||||
call remove(brackets_stack, -1)
|
||||
else
|
||||
let last_closed_bracket = i + 1
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, ']', s)
|
||||
if i >= 0 && i == fe
|
||||
let s = i+1
|
||||
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'sqbra'
|
||||
call remove(brackets_stack, -1)
|
||||
else
|
||||
let last_closed_bracket = i + 1
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '}', s)
|
||||
if i >= 0 && i == fe
|
||||
let s = i+1
|
||||
if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'curbra'
|
||||
call remove(brackets_stack, -1)
|
||||
else
|
||||
let last_closed_bracket = i + 1
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
|
||||
" Note: it should be impossible to get here
|
||||
break
|
||||
|
||||
endif
|
||||
|
||||
" Note: it should be impossible to get here
|
||||
break
|
||||
endwhile
|
||||
let first_open_bracket = -1
|
||||
let last_open_bracket = -1
|
||||
if len(brackets_stack) > 0
|
||||
let first_open_bracket = brackets_stack[0][1]
|
||||
let last_open_bracket = brackets_stack[-1][1]
|
||||
endif
|
||||
return [first_open_bracket, last_open_bracket, last_closed_bracket]
|
||||
endfunction
|
||||
|
||||
let s:bracketBlocks = '\<julia\%(\%(\%(Printf\)\?Par\|SqBra\|CurBra\)Block\|ParBlockInRange\|StringVars\%(Par\|SqBra\|CurBra\)\|Dollar\%(Par\|SqBra\)\|QuotedParBlockS\?\)\>'
|
||||
|
||||
function IsInBrackets(lnum, c)
|
||||
let stack = map(synstack(a:lnum, a:c), 'synIDattr(v:val, "name")')
|
||||
call filter(stack, 'v:val =~# s:bracketBlocks')
|
||||
return len(stack) > 0
|
||||
endfunction
|
||||
|
||||
" Auxiliary function to find a line which does not start in the middle of a
|
||||
" multiline bracketed expression, to be used as reference for block
|
||||
" indentation.
|
||||
function LastBlockIndent(lnum)
|
||||
let lnum = a:lnum
|
||||
let ind = 0
|
||||
while lnum > 0
|
||||
let ind = indent(lnum)
|
||||
if ind == 0
|
||||
return [lnum, 0]
|
||||
endif
|
||||
if !IsInBrackets(lnum, 1)
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
endwhile
|
||||
return [max([lnum,1]), ind]
|
||||
endfunction
|
||||
|
||||
function GetJuliaIndent()
|
||||
let s:save_ignorecase = &ignorecase
|
||||
set noignorecase
|
||||
@@ -172,19 +303,81 @@ function GetJuliaIndent()
|
||||
return 0
|
||||
endif
|
||||
|
||||
let ind = indent(lnum)
|
||||
let ind = -1
|
||||
let st = -1
|
||||
let lim = -1
|
||||
|
||||
" Analyse previous line
|
||||
let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum)
|
||||
" Multiline bracketed expressions take precedence
|
||||
let c = len(getline(lnum)) + 1
|
||||
while IsInBrackets(lnum, c)
|
||||
let [first_open_bracket, last_open_bracket, last_closed_bracket] = GetJuliaNestingBrackets(lnum, c)
|
||||
|
||||
" First scenario: the previous line has a hanging open bracket:
|
||||
" set the indentation to match the opening bracket (plus an extra space)
|
||||
if last_open_bracket != -1
|
||||
let st = last_open_bracket
|
||||
let ind = virtcol([lnum, st + 1])
|
||||
|
||||
" Second scenario: some multiline bracketed expression was closed in the
|
||||
" previous line. But since we know we are still in a bracketed expression,
|
||||
" we need to find the line where the bracket was open
|
||||
elseif last_closed_bracket != -1 " && exists("loaded_matchit")
|
||||
" we use the % command to skip back (this is buggy without matchit, and
|
||||
" is potentially a disaster if % got remapped)
|
||||
call cursor(lnum, last_closed_bracket)
|
||||
normal %
|
||||
if line(".") == lnum
|
||||
" something wrong here, give up
|
||||
let ind = indent(lnum)
|
||||
else
|
||||
let lnum = line(".")
|
||||
let c = col(".") - 1
|
||||
if c == 0
|
||||
" uhm, give up
|
||||
let ind = 0
|
||||
else
|
||||
" we skipped a bracket set, keep searching for an opening bracket
|
||||
let lim = c
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
||||
" Third scenario: nothing special, or matchit not available: keep the indentation
|
||||
else
|
||||
let ind = indent(lnum)
|
||||
endif
|
||||
|
||||
" In case the current line starts with a closing bracket, we align it with
|
||||
" the opening one.
|
||||
if JuliaMatch(v:lnum, getline(v:lnum), '[])}]', indent(v:lnum)) == indent(v:lnum) && ind > 0
|
||||
return ind - 1
|
||||
endif
|
||||
|
||||
break
|
||||
endwhile
|
||||
|
||||
if ind == -1
|
||||
" We are not in a multiline bracketed expression. Thus we look for a
|
||||
" previous line to use as a reference
|
||||
let [lnum,ind] = LastBlockIndent(lnum)
|
||||
let c = len(getline(lnum)) + 1
|
||||
if IsInBrackets(lnum, c)
|
||||
let [first_open_bracket, last_open_bracket, last_closed_bracket] = GetJuliaNestingBrackets(lnum, c)
|
||||
let lim = first_open_bracket
|
||||
endif
|
||||
end
|
||||
|
||||
" Analyse the reference line
|
||||
let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum, st, lim)
|
||||
|
||||
" Increase indentation for each newly opened block
|
||||
" in the previous line
|
||||
" in the reference line
|
||||
while num_open_blocks > 0
|
||||
let ind += &sw
|
||||
let num_open_blocks -= 1
|
||||
endwhile
|
||||
|
||||
" Analyse current line
|
||||
" Analyse the current line
|
||||
let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(v:lnum)
|
||||
|
||||
" Decrease indentation for each closed block
|
||||
|
||||
@@ -3,13 +3,14 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'kotlin') == -1
|
||||
" Vim indent file
|
||||
" Language: Kotlin
|
||||
" Maintainer: Alexander Udalov
|
||||
" Latest Revision: 27 June 2015
|
||||
" Latest Revision: 15 July 2017
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal cinoptions& cinoptions+=j1,L0
|
||||
setlocal indentexpr=GetKotlinIndent()
|
||||
setlocal indentkeys=0},0),!^F,o,O,e,<CR>
|
||||
setlocal autoindent " TODO ?
|
||||
@@ -25,6 +26,21 @@ function! GetKotlinIndent()
|
||||
let prev_indent = indent(prev_num)
|
||||
let cur = getline(v:lnum)
|
||||
|
||||
if cur =~ '^\s*\*'
|
||||
return cindent(v:lnum)
|
||||
endif
|
||||
|
||||
if prev =~ '^\s*\*/'
|
||||
let st = prev
|
||||
while st > 1
|
||||
if getline(st) =~ '^\s*/\*'
|
||||
break
|
||||
endif
|
||||
let st = st - 1
|
||||
endwhile
|
||||
return indent(st)
|
||||
endif
|
||||
|
||||
let prev_open_paren = prev =~ '^.*(\s*$'
|
||||
let cur_close_paren = cur =~ '^\s*).*$'
|
||||
|
||||
|
||||
26
indent/litcoffee.vim
Normal file
26
indent/litcoffee.vim
Normal file
@@ -0,0 +1,26 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'coffee-script') == -1
|
||||
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! indent/coffee.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetLitCoffeeIndent()
|
||||
|
||||
if exists('*GetLitCoffeeIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
function GetLitCoffeeIndent()
|
||||
if searchpair('^ \|\t', '', '$', 'bWnm') > 0
|
||||
return GetCoffeeIndent(v:lnum)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
endfunc
|
||||
|
||||
|
||||
endif
|
||||
@@ -24,21 +24,21 @@ endif
|
||||
|
||||
" Variables -----------------------------------------------{{{1
|
||||
|
||||
let s:open_patt = '\%(\<\%(function\|if\|repeat\|do\)\>\|(\|{\)'
|
||||
let s:middle_patt = '\<\%(else\|elseif\)\>'
|
||||
let s:close_patt = '\%(\<\%(end\|until\)\>\|)\|}\)'
|
||||
let s:open_patt = '\C\%(\<\%(function\|if\|repeat\|do\)\>\|(\|{\)'
|
||||
let s:middle_patt = '\C\<\%(else\|elseif\)\>'
|
||||
let s:close_patt = '\C\%(\<\%(end\|until\)\>\|)\|}\)'
|
||||
|
||||
let s:anon_func_start = '\S\+\s*[({].*\<function\s*(.*)\s*$'
|
||||
let s:anon_func_end = '\<end\%(\s*[)}]\)\+'
|
||||
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ 'luaComment\\|luaString'"
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~# 'luaComment\\|luaString'"
|
||||
|
||||
" Auxiliary Functions -------------------------------------{{{1
|
||||
|
||||
function s:IsInCommentOrString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ 'luaCommentLong\|luaStringLong'
|
||||
\ && !(getline(a:lnum) =~ '^\s*\%(--\)\?\[=*\[') " opening tag is not considered 'in'
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~# 'luaCommentLong\|luaStringLong'
|
||||
\ && !(getline(a:lnum) =~# '^\s*\%(--\)\?\[=*\[') " opening tag is not considered 'in'
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't blank, in a comment or string.
|
||||
@@ -74,48 +74,42 @@ function GetLuaIndent()
|
||||
|
||||
let original_cursor_pos = getpos(".")
|
||||
|
||||
let i = 0
|
||||
|
||||
" check if the previous line opens blocks
|
||||
" count how many blocks the previous line opens
|
||||
call cursor(v:lnum, 1)
|
||||
let num_pairs = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||
let num_prev_opens = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||
\ 'mrb', s:skip_expr, prev_line)
|
||||
if num_pairs > 0
|
||||
let i += num_pairs
|
||||
endif
|
||||
|
||||
" special case: call(with, {anon = function() -- should indent only once
|
||||
if num_pairs > 1 && contents_prev =~ s:anon_func_start
|
||||
let i = 1
|
||||
endif
|
||||
|
||||
" check if current line closes blocks
|
||||
" count how many blocks the current line closes
|
||||
call cursor(prev_line, col([prev_line,'$']))
|
||||
let num_pairs = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||
let num_cur_closes = searchpair(s:open_patt, s:middle_patt, s:close_patt,
|
||||
\ 'mr', s:skip_expr, v:lnum)
|
||||
if num_pairs > 0
|
||||
let i -= num_pairs
|
||||
endif
|
||||
|
||||
" special case: end}) -- end of call with anon func should unindent once
|
||||
if num_pairs > 1 && contents_cur =~ s:anon_func_end
|
||||
let i = -1
|
||||
endif
|
||||
let i = num_prev_opens - num_cur_closes
|
||||
|
||||
" if the previous line closed a paren, unindent (except with anon funcs)
|
||||
" if the previous line closed a paren, outdent (except with anon funcs)
|
||||
call cursor(prev_line - 1, col([prev_line - 1, '$']))
|
||||
let num_pairs = searchpair('(', '', ')', 'mr', s:skip_expr, prev_line)
|
||||
if num_pairs > 0 && contents_prev !~ s:anon_func_end
|
||||
let num_prev_closed_parens = searchpair('(', '', ')', 'mr', s:skip_expr, prev_line)
|
||||
if num_prev_closed_parens > 0 && contents_prev !~# s:anon_func_end
|
||||
let i -= 1
|
||||
endif
|
||||
|
||||
" if this line closed a paren, indent (except with anon funcs)
|
||||
call cursor(prev_line, col([prev_line, '$']))
|
||||
let num_pairs = searchpair('(', '', ')', 'mr', s:skip_expr, v:lnum)
|
||||
if num_pairs > 0 && contents_cur !~ s:anon_func_end
|
||||
let num_cur_closed_parens = searchpair('(', '', ')', 'mr', s:skip_expr, v:lnum)
|
||||
if num_cur_closed_parens > 0 && contents_cur !~# s:anon_func_end
|
||||
let i += 1
|
||||
endif
|
||||
|
||||
" special case: call(with, {anon = function() -- should indent only once
|
||||
if i > 1 && contents_prev =~# s:anon_func_start
|
||||
let i = 1
|
||||
endif
|
||||
|
||||
" special case: end}) -- end of call w/ anon func should outdent only once
|
||||
if i < -1 && contents_cur =~# s:anon_func_end
|
||||
let i = -1
|
||||
endif
|
||||
|
||||
" restore cursor
|
||||
call setpos(".", original_cursor_pos)
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mako') == -1
|
||||
" 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
|
||||
@@ -55,6 +53,9 @@ setlocal nosmartindent
|
||||
setlocal noautoindent
|
||||
setlocal nocindent
|
||||
setlocal nolisp
|
||||
setlocal expandtab
|
||||
setlocal softtabstop=2
|
||||
setlocal shiftwidth=2
|
||||
|
||||
setlocal indentexpr=GetMakoIndent()
|
||||
setlocal indentkeys+=*<Return>,<>>,<bs>,end,:
|
||||
|
||||
86
indent/nix.vim
Normal file
86
indent/nix.vim
Normal file
@@ -0,0 +1,86 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Nix
|
||||
" Maintainer: Daiderd Jordan <daiderd@gmail.com>
|
||||
" URL: https://github.com/LnL7/vim-nix
|
||||
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentexpr=GetNixIndent()
|
||||
setlocal indentkeys+=0=then,0=else,0=inherit,*<Return>
|
||||
|
||||
if exists("*GetNixIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||
let s:block_open = '\%({\|[\)'
|
||||
let s:block_close = '\%(}\|]\)'
|
||||
|
||||
function! GetNixIndent()
|
||||
let lnum = prevnonblank(v:lnum - 1)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
if synIDattr(synID(v:lnum, 1, 1), "name") !~ s:skip_syntax
|
||||
let current_line = getline(v:lnum)
|
||||
let last_line = getline(lnum)
|
||||
|
||||
if last_line =~ s:block_open . '\s*$'
|
||||
let ind += &sw
|
||||
endif
|
||||
|
||||
if current_line =~ '^\s*' . s:block_close
|
||||
let ind -= &sw
|
||||
endif
|
||||
|
||||
if last_line =~ '\<let\s*$'
|
||||
let ind += &sw
|
||||
endif
|
||||
|
||||
if getline(v:lnum - 1) =~ '^\<in\s*$'
|
||||
let ind += &sw
|
||||
endif
|
||||
|
||||
if current_line =~ '^\s*in\>'
|
||||
let ind -= &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
if synIDattr(synID(v:lnum, 1, 1), "name") =~ '^nixString'
|
||||
let current_line = getline(v:lnum)
|
||||
|
||||
let ind = indent(v:lnum)
|
||||
let bslnum = searchpair('''''', '', '''''', 'bnW',
|
||||
\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "InterpolationSpecial$"')
|
||||
|
||||
if ind <= indent(bslnum)
|
||||
let ind = indent(bslnum) + &sw
|
||||
endif
|
||||
|
||||
if current_line =~ '^\s*''''[^''\$]'
|
||||
let ind = indent(bslnum)
|
||||
endif
|
||||
if current_line =~ '^\s*''''$'
|
||||
let ind = indent(bslnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
endif
|
||||
@@ -136,9 +136,9 @@ function! GetPerlIndent()
|
||||
\ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
|
||||
let brace = strpart(line, bracepos, 1)
|
||||
if brace == '(' || brace == '{' || brace == '['
|
||||
let ind = ind + &sw
|
||||
let ind = ind + shiftwidth()
|
||||
else
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
endif
|
||||
let bracepos = match(line, braceclass, bracepos + 1)
|
||||
@@ -151,25 +151,25 @@ function! GetPerlIndent()
|
||||
\ || synid == "perlBraces"
|
||||
\ || synid == "perlStatementIndirObj"
|
||||
\ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if line =~ '[{[(]\s*\(#[^])}]*\)\=$'
|
||||
let ind = ind + &sw
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
if cline =~ '^\s*[])}]'
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
endif
|
||||
|
||||
" Indent lines that begin with 'or' or 'and'
|
||||
if cline =~ '^\s*\(or\|and\)\>'
|
||||
if line !~ '^\s*\(or\|and\)\>'
|
||||
let ind = ind + &sw
|
||||
let ind = ind + shiftwidth()
|
||||
endif
|
||||
elseif line =~ '^\s*\(or\|and\)\>'
|
||||
let ind = ind - &sw
|
||||
let ind = ind - shiftwidth()
|
||||
endif
|
||||
|
||||
return ind
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'plantuml') == -1
|
||||
|
||||
if exists("b:did_indent")
|
||||
if exists('b:did_indent')
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
@@ -9,7 +9,7 @@ setlocal indentexpr=GetPlantUMLIndent()
|
||||
setlocal indentkeys=o,O,<CR>,<:>,!^F,0end,0else,}
|
||||
|
||||
" only define the indent code once
|
||||
if exists("*GetPlantUMLIndent")
|
||||
if exists('*GetPlantUMLIndent')
|
||||
finish
|
||||
endif
|
||||
|
||||
@@ -19,7 +19,7 @@ let s:incIndent =
|
||||
\ '^\s*[hr]\?note\>\%(\%("[^"]*" \<as\>\)\@![^:]\)*$\|' .
|
||||
\ '^\s*title\s*$\|' .
|
||||
\ '^\s*skinparam\>.*{\s*$\|' .
|
||||
\ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\)\>.*{'
|
||||
\ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\|object\)\>.*{'
|
||||
|
||||
let s:decIndent = '^\s*\%(end\|else\|}\)'
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user