mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-09 12:03:53 -05:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96c5c20e41 | ||
|
|
18efda3933 | ||
|
|
bfc6ed9fba | ||
|
|
58709c49f6 | ||
|
|
3d5b784fa5 | ||
|
|
cef5e2d931 | ||
|
|
17ad302c54 | ||
|
|
1541356fe1 | ||
|
|
f3556c1eca | ||
|
|
4855e5ee82 | ||
|
|
bb85059bac |
15
README.md
15
README.md
@@ -21,6 +21,12 @@ A collection of language packs for Vim.
|
|||||||
1. Install [Pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [NeoBundle](https://github.com/Shougo/neobundle.vim), or [Plug](https://github.com/junegunn/vim-plug) package manager for Vim.
|
1. Install [Pathogen](https://github.com/tpope/vim-pathogen), [Vundle](https://github.com/VundleVim/Vundle.vim), [NeoBundle](https://github.com/Shougo/neobundle.vim), or [Plug](https://github.com/junegunn/vim-plug) package manager for Vim.
|
||||||
2. Use this repository as submodule or package.
|
2. Use this repository as submodule or package.
|
||||||
|
|
||||||
|
For example when using [Plug](https://github.com/junegunn/vim-plug):
|
||||||
|
|
||||||
|
```
|
||||||
|
Plug 'sheerun/vim-polyglot'
|
||||||
|
```
|
||||||
|
|
||||||
Optionally download one of the [releases](https://github.com/sheerun/vim-polyglot/releases) and unpack it directly under `~/.vim` directory.
|
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:
|
You can also use Vim 8 built-in package manager:
|
||||||
@@ -46,6 +52,7 @@ If you need full functionality of any plugin, please use it directly with your p
|
|||||||
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
|
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
|
||||||
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
|
||||||
- [caddyfile](https://github.com/isobit/vim-caddyfile) (syntax, indent, ftplugin)
|
- [caddyfile](https://github.com/isobit/vim-caddyfile) (syntax, indent, ftplugin)
|
||||||
|
- [carp](https://github.com/hellerve/carp-vim) (syntax)
|
||||||
- [cjsx](https://github.com/mtscout6/vim-cjsx) (syntax, ftplugin)
|
- [cjsx](https://github.com/mtscout6/vim-cjsx) (syntax, ftplugin)
|
||||||
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin)
|
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin)
|
||||||
- [cmake](https://github.com/pboettch/vim-cmake-syntax) (syntax, indent)
|
- [cmake](https://github.com/pboettch/vim-cmake-syntax) (syntax, indent)
|
||||||
@@ -78,18 +85,19 @@ If you need full functionality of any plugin, please use it directly with your p
|
|||||||
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax)
|
- [jasmine](https://github.com/glanotte/vim-jasmine) (syntax)
|
||||||
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras)
|
- [javascript](https://github.com/pangloss/vim-javascript) (syntax, indent, compiler, ftplugin, extras)
|
||||||
- [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent)
|
- [jenkins](https://github.com/martinda/Jenkinsfile-vim-syntax) (syntax, indent)
|
||||||
|
- [json5](https://github.com/GutenYe/json5.vim) (syntax)
|
||||||
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin)
|
- [json](https://github.com/elzr/vim-json) (syntax, indent, ftplugin)
|
||||||
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent)
|
- [jst](https://github.com/briancollins/vim-jst) (syntax, indent)
|
||||||
- [jsx](https://github.com/mxw/vim-jsx) (after)
|
- [jsx](https://github.com/mxw/vim-jsx) (after)
|
||||||
- [julia](https://github.com/JuliaEditorSupport/julia-vim) (syntax, indent, autoload, ftplugin)
|
- [julia](https://github.com/JuliaEditorSupport/julia-vim) (syntax, indent, autoload, ftplugin)
|
||||||
- [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent)
|
- [kotlin](https://github.com/udalov/kotlin-vim) (syntax, indent)
|
||||||
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) ()
|
- [latex](https://github.com/LaTeX-Box-Team/LaTeX-Box) (syntax, indent, ftplugin)
|
||||||
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin)
|
- [less](https://github.com/groenewege/vim-less) (syntax, indent, ftplugin)
|
||||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin)
|
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin)
|
||||||
- [livescript](https://github.com/gkz/vim-ls) (syntax, indent, compiler, ftplugin)
|
- [livescript](https://github.com/gkz/vim-ls) (syntax, indent, compiler, ftplugin)
|
||||||
- [lua](https://github.com/tbastos/vim-lua) (syntax, indent)
|
- [lua](https://github.com/tbastos/vim-lua) (syntax, indent)
|
||||||
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin)
|
- [mako](https://github.com/sophacles/vim-bundle-mako) (syntax, indent, ftplugin)
|
||||||
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax)
|
- [markdown](https://github.com/plasticboy/vim-markdown) (syntax, indent)
|
||||||
- [mathematica](https://github.com/rsmenon/vim-mathematica) (syntax, ftplugin)
|
- [mathematica](https://github.com/rsmenon/vim-mathematica) (syntax, ftplugin)
|
||||||
- [nginx](https://github.com/chr4/nginx.vim) (syntax, indent, ftplugin)
|
- [nginx](https://github.com/chr4/nginx.vim) (syntax, indent, ftplugin)
|
||||||
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, indent)
|
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, indent)
|
||||||
@@ -108,7 +116,8 @@ If you need full functionality of any plugin, please use it directly with your p
|
|||||||
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin)
|
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin)
|
||||||
- [purescript](https://github.com/purescript-contrib/purescript-vim) (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-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload)
|
||||||
- [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent)
|
- [python-ident](https://github.com/Vimjas/vim-python-pep8-indent) (indent)
|
||||||
|
- [python](https://github.com/vim-python/python-syntax) (syntax)
|
||||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin)
|
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin)
|
||||||
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
||||||
- [racket](https://github.com/wlangstroth/vim-racket) (syntax, indent, autoload, ftplugin)
|
- [racket](https://github.com/wlangstroth/vim-racket) (syntax, indent, autoload, ftplugin)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
|||||||
" Highlight function names.
|
" Highlight function names.
|
||||||
" -----------------------------------------------------------------------------
|
" -----------------------------------------------------------------------------
|
||||||
if !exists('g:cpp_no_function_highlight')
|
if !exists('g:cpp_no_function_highlight')
|
||||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
syn match cCustomParen transparent "(" contains=cParen contains=cCppParen
|
||||||
syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen
|
syn match cCustomFunc "\w\+\s*(\@=" contains=cCustomParen
|
||||||
hi def link cCustomFunc Function
|
hi def link cCustomFunc Function
|
||||||
endif
|
endif
|
||||||
@@ -32,7 +32,7 @@ endif
|
|||||||
if exists('g:cpp_member_variable_highlight') && g:cpp_member_variable_highlight
|
if exists('g:cpp_member_variable_highlight') && g:cpp_member_variable_highlight
|
||||||
syn match cCustomDot "\." contained
|
syn match cCustomDot "\." contained
|
||||||
syn match cCustomPtr "->" contained
|
syn match cCustomPtr "->" contained
|
||||||
syn match cCustomMemVar "\(\.\|->\)\w\+" contains=cCustomDot,cCustomPtr
|
syn match cCustomMemVar "\(\.\|->\)\h\w*" contains=cCustomDot,cCustomPtr
|
||||||
hi def link cCustomMemVar Function
|
hi def link cCustomMemVar Function
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
|||||||
" Language: C++ Additions
|
" Language: C++ Additions
|
||||||
" Maintainer: Jon Haggblad <jon@haeggblad.com>
|
" Maintainer: Jon Haggblad <jon@haeggblad.com>
|
||||||
" URL: http://www.haeggblad.com
|
" URL: http://www.haeggblad.com
|
||||||
" Last Change: 12 Oct 2016
|
" Last Change: 1 Feb 2018
|
||||||
" Version: 0.6
|
" Version: 0.6
|
||||||
" Changelog:
|
" Changelog:
|
||||||
" 0.1 - initial version.
|
" 0.1 - initial version.
|
||||||
@@ -37,7 +37,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c++11') == -1
|
|||||||
|
|
||||||
" Functions
|
" Functions
|
||||||
if !exists('g:cpp_no_function_highlight')
|
if !exists('g:cpp_no_function_highlight')
|
||||||
syn match cCustomParen "(" contains=cParen contains=cCppParen
|
syn match cCustomParen transparent "(" contains=cParen contains=cCppParen
|
||||||
syn match cCustomFunc "\w\+\s*(\@="
|
syn match cCustomFunc "\w\+\s*(\@="
|
||||||
hi def link cCustomFunc Function
|
hi def link cCustomFunc Function
|
||||||
endif
|
endif
|
||||||
@@ -855,6 +855,37 @@ syntax keyword cppSTLconstant WEOF
|
|||||||
syntax keyword cppSTLconstant WCHAR_MIN
|
syntax keyword cppSTLconstant WCHAR_MIN
|
||||||
syntax keyword cppSTLconstant WCHAR_MAX
|
syntax keyword cppSTLconstant WCHAR_MAX
|
||||||
|
|
||||||
|
" locale
|
||||||
|
syntax keyword cppSTLtype locale
|
||||||
|
syntax keyword cppSTLtype ctype_base
|
||||||
|
syntax keyword cppSTLtype codecvt_base
|
||||||
|
syntax keyword cppSTLtype messages_base
|
||||||
|
syntax keyword cppSTLtype time_base
|
||||||
|
syntax keyword cppSTLtype money_base
|
||||||
|
syntax keyword cppSTLtype ctype
|
||||||
|
syntax keyword cppSTLtype codecvt
|
||||||
|
syntax keyword cppSTLtype collate
|
||||||
|
syntax keyword cppSTLtype messages
|
||||||
|
syntax keyword cppSTLtype time_get
|
||||||
|
syntax keyword cppSTLtype time_put
|
||||||
|
syntax keyword cppSTLtype num_get
|
||||||
|
syntax keyword cppSTLtype num_put
|
||||||
|
syntax keyword cppSTLtype numpunct
|
||||||
|
syntax keyword cppSTLtype money_get
|
||||||
|
syntax keyword cppSTLtype money_put
|
||||||
|
syntax keyword cppSTLtype moneypunct
|
||||||
|
syntax keyword cppSTLtype ctype_byname
|
||||||
|
syntax keyword cppSTLtype codecvt_byname
|
||||||
|
syntax keyword cppSTLtype messages_byname
|
||||||
|
syntax keyword cppSTLtype collate_byname
|
||||||
|
syntax keyword cppSTLtype time_get_byname
|
||||||
|
syntax keyword cppSTLtype time_put_byname
|
||||||
|
syntax keyword cppSTLtype numpunct_byname
|
||||||
|
syntax keyword cppSTLtype moneypunct_byname
|
||||||
|
syntax keyword cppSTLfunction use_facet
|
||||||
|
syntax keyword cppSTLfunction has_facet
|
||||||
|
syntax keyword cppSTLfunction isspace isblank iscntrl isupper islower isalpha
|
||||||
|
syntax keyword cppSTLfunction isdigit ispunct isxdigit isalnum isprint isgraph
|
||||||
|
|
||||||
if !exists("cpp_no_cpp11")
|
if !exists("cpp_no_cpp11")
|
||||||
syntax keyword cppSTLconstant nullptr
|
syntax keyword cppSTLconstant nullptr
|
||||||
@@ -1766,6 +1797,9 @@ if !exists("cpp_no_cpp17")
|
|||||||
syntax keyword cppSTLfunction do_deallocate
|
syntax keyword cppSTLfunction do_deallocate
|
||||||
syntax keyword cppSTLfunction do_is_equal
|
syntax keyword cppSTLfunction do_is_equal
|
||||||
|
|
||||||
|
" mutex
|
||||||
|
syntax keyword cppSTLtype scoped_lock
|
||||||
|
|
||||||
" new
|
" new
|
||||||
syntax keyword cppSTLconstant hardware_destructive_interference_size
|
syntax keyword cppSTLconstant hardware_destructive_interference_size
|
||||||
syntax keyword cppSTLconstant hardware_constructive_interference_size
|
syntax keyword cppSTLconstant hardware_constructive_interference_size
|
||||||
@@ -1804,7 +1838,7 @@ if !exists("cpp_no_cpp17")
|
|||||||
syntax keyword cppSTLbool is_error_code_enum_v
|
syntax keyword cppSTLbool is_error_code_enum_v
|
||||||
syntax keyword cppSTLbool is_error_condition_enum_v
|
syntax keyword cppSTLbool is_error_condition_enum_v
|
||||||
|
|
||||||
" thread
|
" shared_mutex
|
||||||
syntax keyword cppSTLtype shared_mutex
|
syntax keyword cppSTLtype shared_mutex
|
||||||
|
|
||||||
" tuple
|
" tuple
|
||||||
@@ -1879,6 +1913,16 @@ if !exists("cpp_no_cpp17")
|
|||||||
syntax keyword cppSTLbool conjunction_v
|
syntax keyword cppSTLbool conjunction_v
|
||||||
syntax keyword cppSTLbool disjunction_v
|
syntax keyword cppSTLbool disjunction_v
|
||||||
syntax keyword cppSTLbool negation_v
|
syntax keyword cppSTLbool negation_v
|
||||||
|
syntax keyword cppSTLbool has_unique_object_representations_v
|
||||||
|
syntax keyword cppSTLbool is_swappable_v
|
||||||
|
syntax keyword cppSTLbool is_swappable_with_v
|
||||||
|
syntax keyword cppSTLbool is_nothrow_swappable_v
|
||||||
|
syntax keyword cppSTLbool is_nothrow_swappable_with_v
|
||||||
|
syntax keyword cppSTLbool is_invocable_v
|
||||||
|
syntax keyword cppSTLbool is_invocable_r_v
|
||||||
|
syntax keyword cppSTLbool is_nothrow_invocable_v
|
||||||
|
syntax keyword cppSTLbool is_nothrow_invocable_r_v
|
||||||
|
syntax keyword cppSTLbool is_aggregate_v
|
||||||
syntax keyword cppSTLconstant alignment_of_v
|
syntax keyword cppSTLconstant alignment_of_v
|
||||||
syntax keyword cppSTLconstant rank_v
|
syntax keyword cppSTLconstant rank_v
|
||||||
syntax keyword cppSTLconstant extent_v
|
syntax keyword cppSTLconstant extent_v
|
||||||
@@ -1888,6 +1932,19 @@ if !exists("cpp_no_cpp17")
|
|||||||
syntax keyword cppSTLtype conjunction
|
syntax keyword cppSTLtype conjunction
|
||||||
syntax keyword cppSTLtype disjunction
|
syntax keyword cppSTLtype disjunction
|
||||||
syntax keyword cppSTLtype negation
|
syntax keyword cppSTLtype negation
|
||||||
|
syntax keyword cppSTLtype void_t
|
||||||
|
syntax keyword cppSTLtype has_unique_object_representations
|
||||||
|
syntax keyword cppSTLtype is_swappable
|
||||||
|
syntax keyword cppSTLtype is_swappable_with
|
||||||
|
syntax keyword cppSTLtype is_nothrow_swappable
|
||||||
|
syntax keyword cppSTLtype is_nothrow_swappable_with
|
||||||
|
syntax keyword cppSTLtype is_invocable
|
||||||
|
syntax keyword cppSTLtype is_invocable_r
|
||||||
|
syntax keyword cppSTLtype is_nothrow_invocable
|
||||||
|
syntax keyword cppSTLtype is_nothrow_invocable_r
|
||||||
|
syntax keyword cppSTLtype invoke_result
|
||||||
|
syntax keyword cppSTLtype invoke_result_t
|
||||||
|
syntax keyword cppSTLtype is_aggregate
|
||||||
|
|
||||||
" unordered_map, unordered_set, unordered_multimap, unordered_multiset
|
" unordered_map, unordered_set, unordered_multimap, unordered_multiset
|
||||||
syntax keyword cppSTLtype node_type
|
syntax keyword cppSTLtype node_type
|
||||||
@@ -1921,6 +1978,12 @@ if !exists("cpp_no_cpp17")
|
|||||||
endif " C++17
|
endif " C++17
|
||||||
|
|
||||||
|
|
||||||
|
if !exists("cpp_no_cpp20")
|
||||||
|
" type_traits
|
||||||
|
syntax keyword cppSTLtype remove_cvref remove_cvref_t
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
if exists('g:cpp_concepts_highlight') && g:cpp_concepts_highlight
|
if exists('g:cpp_concepts_highlight') && g:cpp_concepts_highlight
|
||||||
syntax keyword cppStatement concept
|
syntax keyword cppStatement concept
|
||||||
syntax keyword cppStorageClass requires
|
syntax keyword cppStorageClass requires
|
||||||
|
|||||||
13
after/syntax/tex.vim
Normal file
13
after/syntax/tex.vim
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
@@ -26,7 +26,7 @@ syn match yamlBlock "[\[\]\{\}\|\>]"
|
|||||||
syn region yamlComment start="\#" end="$"
|
syn region yamlComment start="\#" end="$"
|
||||||
syn match yamlIndicator "#YAML:\S\+"
|
syn match yamlIndicator "#YAML:\S\+"
|
||||||
|
|
||||||
syn region yamlString start="\%(^\| \)\zs'" end="'\ze\%( \|$\)" skip="\\'"
|
syn region yamlString start="\(^\|\s\|\[\|\,\|\-\)'" end="'" skip="\\'"
|
||||||
syn region yamlString start='"' end='"' skip='\\"' contains=yamlEscape
|
syn region yamlString start='"' end='"' skip='\\"' contains=yamlEscape
|
||||||
syn match yamlEscape +\\[abfnrtv'"\\]+ contained
|
syn match yamlEscape +\\[abfnrtv'"\\]+ contained
|
||||||
syn match yamlEscape "\\\o\o\=\o\=" contained
|
syn match yamlEscape "\\\o\o\=\o\=" contained
|
||||||
|
|||||||
89
autoload/cargo.vim
Normal file
89
autoload/cargo.vim
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1
|
||||||
|
|
||||||
|
function! cargo#cmd(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo ". a:args
|
||||||
|
else
|
||||||
|
echom "Missing arguments"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#build(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo build " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo build"
|
||||||
|
endif
|
||||||
|
silent! clear
|
||||||
|
execute "!" . "cargo build"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#clean(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo clean " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo clean"
|
||||||
|
endif
|
||||||
|
silent! clear
|
||||||
|
execute "!" . "cargo clean"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#doc(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo doc " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo doc"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#new(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!cargo new " . a:args
|
||||||
|
:cd `=a:args`
|
||||||
|
else
|
||||||
|
echom "Missing arguments"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#init(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo init " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo init"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#run(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo run " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo run"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#test(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo test " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo test"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! cargo#bench(args)
|
||||||
|
silent! clear
|
||||||
|
if !a:args
|
||||||
|
execute "!" . "cargo bench " . a:args
|
||||||
|
else
|
||||||
|
execute "!" . "cargo bench"
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -3,11 +3,21 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
|||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
let s:V = vital#of('crystal')
|
let s:V = vital#crystal#new()
|
||||||
let s:P = s:V.import('Process')
|
let s:P = s:V.import('Process')
|
||||||
let s:J = s:V.import('Web.JSON')
|
|
||||||
let s:C = s:V.import('ColorEcho')
|
let s:C = s:V.import('ColorEcho')
|
||||||
|
|
||||||
|
if exists('*json_decode')
|
||||||
|
function! s:decode_json(text) abort
|
||||||
|
return json_decode(a:text)
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
let s:J = s:V.import('Web.JSON')
|
||||||
|
function! s:decode_json(text) abort
|
||||||
|
return s:J.decode(a:text)
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
function! s:echo_error(msg, ...) abort
|
function! s:echo_error(msg, ...) abort
|
||||||
echohl ErrorMsg
|
echohl ErrorMsg
|
||||||
if a:0 == 0
|
if a:0 == 0
|
||||||
@@ -102,7 +112,7 @@ function! crystal_lang#jump_to_definition(file, pos) abort
|
|||||||
return s:echo_error(cmd_result.output)
|
return s:echo_error(cmd_result.output)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let impl = s:J.decode(cmd_result.output)
|
let impl = s:decode_json(cmd_result.output)
|
||||||
if impl.status !=# 'ok'
|
if impl.status !=# 'ok'
|
||||||
return s:echo_error(impl.message)
|
return s:echo_error(impl.message)
|
||||||
endif
|
endif
|
||||||
@@ -149,7 +159,6 @@ endfunction
|
|||||||
|
|
||||||
function! crystal_lang#complete(findstart, base) abort
|
function! crystal_lang#complete(findstart, base) abort
|
||||||
if a:findstart
|
if a:findstart
|
||||||
echom 'find start'
|
|
||||||
return s:find_completion_start()
|
return s:find_completion_start()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -158,7 +167,7 @@ function! crystal_lang#complete(findstart, base) abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let contexts = s:J.decode(cmd_result.output)
|
let contexts = s:decode_json(cmd_result.output)
|
||||||
if contexts.status !=# 'ok'
|
if contexts.status !=# 'ok'
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -271,59 +280,34 @@ function! crystal_lang#format_string(code, ...) abort
|
|||||||
return output
|
return output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:get_saved_states() abort
|
" crystal_lang#format(option_str [, on_save])
|
||||||
let result = {}
|
function! crystal_lang#format(option_str, ...) abort
|
||||||
let fname = bufname('%')
|
|
||||||
let current_winnr = winnr()
|
|
||||||
for i in range(1, winnr('$'))
|
|
||||||
let bufnr = winbufnr(i)
|
|
||||||
if bufnr == -1
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
if bufname(bufnr) ==# fname
|
|
||||||
execute i 'wincmd w'
|
|
||||||
let result[i] = {
|
|
||||||
\ 'pos': getpos('.'),
|
|
||||||
\ 'screen': winsaveview()
|
|
||||||
\ }
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
execute current_winnr 'wincmd w'
|
|
||||||
return result
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! crystal_lang#format(option_str) abort
|
|
||||||
if !executable(g:crystal_compiler_command)
|
if !executable(g:crystal_compiler_command)
|
||||||
" Finish command silently
|
" Finish command silently
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let formatted = crystal_lang#format_string(join(getline(1, '$'), "\n"), a:option_str)
|
let on_save = a:0 > 0 ? a:1 : 0
|
||||||
let formatted = substitute(formatted, '\n$', '', '')
|
|
||||||
|
|
||||||
let sel_save = &l:selection
|
let before = join(getline(1, '$'), "\n")
|
||||||
let ve_save = &virtualedit
|
let formatted = crystal_lang#format_string(before, a:option_str)
|
||||||
let &l:selection = 'inclusive'
|
if !on_save
|
||||||
let &virtualedit = ''
|
let after = substitute(formatted, '\n$', '', '')
|
||||||
let [save_g_reg, save_g_regtype] = [getreg('g'), getregtype('g')]
|
if before ==# after
|
||||||
let windows_save = s:get_saved_states()
|
return
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
try
|
let view_save = winsaveview()
|
||||||
call setreg('g', formatted, 'v')
|
let pos_save = getpos('.')
|
||||||
silent normal! gg0vG$"gp
|
let lines = split(formatted, '\n')
|
||||||
finally
|
silent! undojoin
|
||||||
call setreg('g', save_g_reg, save_g_regtype)
|
if line('$') > len(lines)
|
||||||
let &l:selection = sel_save
|
execute len(lines) . ',$delete' '_'
|
||||||
let &virtualedit = ve_save
|
endif
|
||||||
let winnr = winnr()
|
call setline(1, lines)
|
||||||
for winnr in keys(windows_save)
|
call winrestview(view_save)
|
||||||
let w = windows_save[winnr]
|
call setpos('.', pos_save)
|
||||||
execute winnr 'wincmd w'
|
|
||||||
call setpos('.', w.pos)
|
|
||||||
call winrestview(w.screen)
|
|
||||||
endfor
|
|
||||||
execute winnr 'wincmd w'
|
|
||||||
endtry
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
|||||||
@@ -18,11 +18,15 @@ function! elixir#indent#indent(lnum)
|
|||||||
call s:debug("==> Indenting line " . lnum)
|
call s:debug("==> Indenting line " . lnum)
|
||||||
call s:debug("text = '" . text . "'")
|
call s:debug("text = '" . text . "'")
|
||||||
|
|
||||||
|
let [_, curs_lnum, curs_col, _] = getpos('.')
|
||||||
|
call cursor(lnum, 0)
|
||||||
|
|
||||||
let handlers = [
|
let handlers = [
|
||||||
\'top_of_file',
|
\'top_of_file',
|
||||||
\'starts_with_end',
|
\'starts_with_end',
|
||||||
\'starts_with_mid_or_end_block_keyword',
|
\'starts_with_mid_or_end_block_keyword',
|
||||||
\'following_trailing_do',
|
\'following_trailing_do',
|
||||||
|
\'following_trailing_rocket',
|
||||||
\'following_trailing_binary_operator',
|
\'following_trailing_binary_operator',
|
||||||
\'starts_with_pipe',
|
\'starts_with_pipe',
|
||||||
\'starts_with_close_bracket',
|
\'starts_with_close_bracket',
|
||||||
@@ -37,11 +41,13 @@ function! elixir#indent#indent(lnum)
|
|||||||
let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text)
|
let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||||
if indent != -1
|
if indent != -1
|
||||||
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent)
|
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent)
|
||||||
|
call cursor(curs_lnum, curs_col)
|
||||||
return indent
|
return indent
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call s:debug("defaulting")
|
call s:debug("defaulting")
|
||||||
|
call cursor(curs_lnum, curs_col)
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -166,7 +172,7 @@ function! s:get_base_indent(lnum, text)
|
|||||||
elseif s:ends_with(a:text, data_structure_close, a:lnum)
|
elseif s:ends_with(a:text, data_structure_close, a:lnum)
|
||||||
let data_structure_open = '\%(\[\|{\|(\)'
|
let data_structure_open = '\%(\[\|{\|(\)'
|
||||||
let close_match_idx = match(a:text, data_structure_close . '\s*$')
|
let close_match_idx = match(a:text, data_structure_close . '\s*$')
|
||||||
let _move = cursor(a:lnum, close_match_idx + 1)
|
call 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_lnum, open_match_col] = searchpairpos(data_structure_open, '', data_structure_close, 'bnW')
|
||||||
let open_match_text = getline(open_match_lnum)
|
let open_match_text = getline(open_match_lnum)
|
||||||
return s:get_base_indent(open_match_lnum, open_match_text)
|
return s:get_base_indent(open_match_lnum, open_match_text)
|
||||||
@@ -175,7 +181,6 @@ function! s:get_base_indent(lnum, text)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" TODO: @jbodah 2017-03-31: remove
|
|
||||||
function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, prev_nb_text)
|
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:ends_with(a:prev_nb_text, s:keyword('do'), a:prev_nb_lnum)
|
||||||
if s:starts_with(a:text, s:keyword('end'), a:lnum)
|
if s:starts_with(a:text, s:keyword('end'), a:lnum)
|
||||||
@@ -188,6 +193,14 @@ function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, p
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! elixir#indent#handle_following_trailing_rocket(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||||
|
if s:ends_with(a:prev_nb_text, '->', a:prev_nb_lnum)
|
||||||
|
return indent(a:prev_nb_lnum) + s:sw()
|
||||||
|
else
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text)
|
function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text)
|
||||||
let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
|
let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
|
||||||
|
|
||||||
|
|||||||
31
autoload/vifm/globals.vim
Normal file
31
autoload/vifm/globals.vim
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
||||||
|
|
||||||
|
" common functions for vifm plugin related to globals
|
||||||
|
" Maintainer: xaizek <xaizek@posteo.net>
|
||||||
|
" Last Change: January 02, 2018
|
||||||
|
|
||||||
|
" Initializes global variables to defaults unless they are already set
|
||||||
|
function! vifm#globals#Init()
|
||||||
|
if !exists('g:vifm_exec')
|
||||||
|
let g:vifm_exec = 'vifm'
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists('g:vifm_exec_args')
|
||||||
|
let g:vifm_exec_args = ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists('g:vifm_term')
|
||||||
|
if has('win32')
|
||||||
|
if filereadable('C:\Windows\system32\cmd.exe')
|
||||||
|
let g:vifm_term = 'C:\Windows\system32\cmd.exe /C'
|
||||||
|
else
|
||||||
|
" If don't find use the integrate shell it work too
|
||||||
|
let g:vifm_term = ''
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let g:vifm_term = 'xterm -e'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
|
||||||
|
|
||||||
function! vital#of(name) abort
|
|
||||||
let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital')
|
|
||||||
let file = split(files, "\n")
|
|
||||||
if empty(file)
|
|
||||||
throw 'vital: version file not found: ' . a:name
|
|
||||||
endif
|
|
||||||
let ver = readfile(file[0], 'b')
|
|
||||||
if empty(ver)
|
|
||||||
throw 'vital: invalid version file: ' . a:name
|
|
||||||
endif
|
|
||||||
return vital#_{substitute(ver[0], '\W', '', 'g')}#new()
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
endif
|
|
||||||
@@ -1,313 +1,13 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
let s:self_version = expand('<sfile>:t:r')
|
let s:_plugin_name = expand('<sfile>:t:r')
|
||||||
let s:self_file = expand('<sfile>')
|
|
||||||
|
|
||||||
" Note: The extra argument to globpath() was added in Patch 7.2.051.
|
function! vital#{s:_plugin_name}#new() abort
|
||||||
let s:globpath_third_arg = v:version > 702 || v:version == 702 && has('patch51')
|
return vital#{s:_plugin_name[1:]}#new()
|
||||||
|
|
||||||
let s:loaded = {}
|
|
||||||
let s:cache_module_path = {}
|
|
||||||
let s:cache_sid = {}
|
|
||||||
|
|
||||||
let s:_vital_files_cache_runtimepath = ''
|
|
||||||
let s:_vital_files_cache = []
|
|
||||||
let s:_unify_path_cache = {}
|
|
||||||
|
|
||||||
function! s:import(name, ...) abort
|
|
||||||
let target = {}
|
|
||||||
let functions = []
|
|
||||||
for a in a:000
|
|
||||||
if type(a) == type({})
|
|
||||||
let target = a
|
|
||||||
elseif type(a) == type([])
|
|
||||||
let functions = a
|
|
||||||
endif
|
|
||||||
unlet a
|
|
||||||
endfor
|
|
||||||
let module = s:_import(a:name)
|
|
||||||
if empty(functions)
|
|
||||||
call extend(target, module, 'keep')
|
|
||||||
else
|
|
||||||
for f in functions
|
|
||||||
if has_key(module, f) && !has_key(target, f)
|
|
||||||
let target[f] = module[f]
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
return target
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:load(...) dict abort
|
function! vital#{s:_plugin_name}#function(funcname) abort
|
||||||
for arg in a:000
|
silent! return function(a:funcname)
|
||||||
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
|
||||||
let target = split(join(as, ''), '\W\+')
|
|
||||||
let dict = self
|
|
||||||
let dict_type = type({})
|
|
||||||
while !empty(target)
|
|
||||||
let ns = remove(target, 0)
|
|
||||||
if !has_key(dict, ns)
|
|
||||||
let dict[ns] = {}
|
|
||||||
endif
|
|
||||||
if type(dict[ns]) == dict_type
|
|
||||||
let dict = dict[ns]
|
|
||||||
else
|
|
||||||
unlet dict
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
if exists('dict')
|
|
||||||
call extend(dict, s:_import(name))
|
|
||||||
endif
|
|
||||||
unlet arg
|
|
||||||
endfor
|
|
||||||
return self
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:unload() abort
|
|
||||||
let s:loaded = {}
|
|
||||||
let s:cache_sid = {}
|
|
||||||
let s:cache_module_path = {}
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:exists(name) abort
|
|
||||||
return s:_get_module_path(a:name) !=# ''
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:search(pattern) abort
|
|
||||||
let paths = s:_vital_files(a:pattern)
|
|
||||||
let modules = sort(map(paths, 's:_file2module(v:val)'))
|
|
||||||
return s:_uniq(modules)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:expand_modules(entry, all) abort
|
|
||||||
if type(a:entry) == type([])
|
|
||||||
let candidates = s:_concat(map(copy(a:entry), 's:search(v:val)'))
|
|
||||||
if empty(candidates)
|
|
||||||
throw printf('vital: Any of module %s is not found', string(a:entry))
|
|
||||||
endif
|
|
||||||
if eval(join(map(copy(candidates), 'has_key(a:all, v:val)'), '+'))
|
|
||||||
let modules = []
|
|
||||||
else
|
|
||||||
let modules = [candidates[0]]
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
let modules = s:search(a:entry)
|
|
||||||
if empty(modules)
|
|
||||||
throw printf('vital: Module %s is not found', a:entry)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
call filter(modules, '!has_key(a:all, v:val)')
|
|
||||||
for module in modules
|
|
||||||
let a:all[module] = 1
|
|
||||||
endfor
|
|
||||||
return modules
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_import(name) abort
|
|
||||||
if type(a:name) == type(0)
|
|
||||||
return s:_build_module(a:name)
|
|
||||||
endif
|
|
||||||
let path = s:_get_module_path(a:name)
|
|
||||||
if path ==# ''
|
|
||||||
throw 'vital: module not found: ' . a:name
|
|
||||||
endif
|
|
||||||
let sid = s:_get_sid_by_script(path)
|
|
||||||
if !sid
|
|
||||||
try
|
|
||||||
execute 'source' fnameescape(path)
|
|
||||||
catch /^Vim\%((\a\+)\)\?:E484/
|
|
||||||
throw 'vital: module not found: ' . a:name
|
|
||||||
catch /^Vim\%((\a\+)\)\?:E127/
|
|
||||||
" Ignore.
|
|
||||||
endtry
|
|
||||||
|
|
||||||
let sid = s:_get_sid_by_script(path)
|
|
||||||
endif
|
|
||||||
return s:_build_module(sid)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_get_module_path(name) abort
|
|
||||||
let key = a:name . '_'
|
|
||||||
if has_key(s:cache_module_path, key)
|
|
||||||
return s:cache_module_path[key]
|
|
||||||
endif
|
|
||||||
if s:_is_absolute_path(a:name) && filereadable(a:name)
|
|
||||||
return a:name
|
|
||||||
endif
|
|
||||||
if a:name ==# ''
|
|
||||||
let paths = [s:self_file]
|
|
||||||
elseif a:name =~# '\v^\u\w*%(\.\u\w*)*$'
|
|
||||||
let paths = s:_vital_files(a:name)
|
|
||||||
else
|
|
||||||
throw 'vital: Invalid module name: ' . a:name
|
|
||||||
endif
|
|
||||||
|
|
||||||
call filter(paths, 'filereadable(expand(v:val, 1))')
|
|
||||||
let path = get(paths, 0, '')
|
|
||||||
let s:cache_module_path[key] = path
|
|
||||||
return path
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_get_sid_by_script(path) abort
|
|
||||||
if has_key(s:cache_sid, a:path)
|
|
||||||
return s:cache_sid[a:path]
|
|
||||||
endif
|
|
||||||
|
|
||||||
let path = s:_unify_path(a:path)
|
|
||||||
for line in filter(split(s:_redir('scriptnames'), "\n"),
|
|
||||||
\ 'stridx(v:val, s:self_version) > 0')
|
|
||||||
let list = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
|
|
||||||
if !empty(list) && s:_unify_path(list[2]) ==# path
|
|
||||||
let s:cache_sid[a:path] = list[1] - 0
|
|
||||||
return s:cache_sid[a:path]
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_file2module(file) abort
|
|
||||||
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
|
|
||||||
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
|
|
||||||
return join(split(tail, '[\\/]\+'), '.')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if filereadable(expand('<sfile>:r') . '.VIM')
|
|
||||||
" resolve() is slow, so we cache results.
|
|
||||||
" Note: On windows, vim can't expand path names from 8.3 formats.
|
|
||||||
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
|
|
||||||
" vital load duplicated scripts. Below's :~ avoid this issue.
|
|
||||||
function! s:_unify_path(path) abort
|
|
||||||
if has_key(s:_unify_path_cache, a:path)
|
|
||||||
return s:_unify_path_cache[a:path]
|
|
||||||
endif
|
|
||||||
let value = tolower(fnamemodify(resolve(fnamemodify(
|
|
||||||
\ a:path, ':p')), ':~:gs?[\\/]?/?'))
|
|
||||||
let s:_unify_path_cache[a:path] = value
|
|
||||||
return value
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:_unify_path(path) abort
|
|
||||||
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
if s:globpath_third_arg
|
|
||||||
function! s:_runtime_files(path) abort
|
|
||||||
return split(globpath(&runtimepath, a:path, 1), "\n")
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:_runtime_files(path) abort
|
|
||||||
return split(globpath(&runtimepath, a:path), "\n")
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! s:_vital_files(pattern) abort
|
|
||||||
if s:_vital_files_cache_runtimepath !=# &runtimepath
|
|
||||||
let path = printf('autoload/vital/%s/**/*.vim', s:self_version)
|
|
||||||
let s:_vital_files_cache = s:_runtime_files(path)
|
|
||||||
let mod = ':p:gs?[\\/]\+?/?'
|
|
||||||
call map(s:_vital_files_cache, 'fnamemodify(v:val, mod)')
|
|
||||||
let s:_vital_files_cache_runtimepath = &runtimepath
|
|
||||||
endif
|
|
||||||
let target = substitute(a:pattern, '\.', '/', 'g')
|
|
||||||
let target = substitute(target, '\*', '[^/]*', 'g')
|
|
||||||
let regexp = printf('autoload/vital/%s/%s.vim', s:self_version, target)
|
|
||||||
return filter(copy(s:_vital_files_cache), 'v:val =~# regexp')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Copy from System.Filepath
|
|
||||||
if has('win16') || has('win32') || has('win64')
|
|
||||||
function! s:_is_absolute_path(path) abort
|
|
||||||
return a:path =~? '^[a-z]:[/\\]'
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:_is_absolute_path(path) abort
|
|
||||||
return a:path[0] ==# '/'
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! s:_build_module(sid) abort
|
|
||||||
if has_key(s:loaded, a:sid)
|
|
||||||
return copy(s:loaded[a:sid])
|
|
||||||
endif
|
|
||||||
let functions = s:_get_functions(a:sid)
|
|
||||||
|
|
||||||
let prefix = '<SNR>' . a:sid . '_'
|
|
||||||
let module = {}
|
|
||||||
for func in functions
|
|
||||||
let module[func] = function(prefix . func)
|
|
||||||
endfor
|
|
||||||
if has_key(module, '_vital_created')
|
|
||||||
call module._vital_created(module)
|
|
||||||
endif
|
|
||||||
let export_module = filter(copy(module), 'v:key =~# "^\\a"')
|
|
||||||
let s:loaded[a:sid] = get(g:, 'vital_debug', 0) ? module : export_module
|
|
||||||
if has_key(module, '_vital_loaded')
|
|
||||||
let V = vital#{s:self_version}#new()
|
|
||||||
call module._vital_loaded(V)
|
|
||||||
endif
|
|
||||||
return copy(s:loaded[a:sid])
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if exists('+regexpengine')
|
|
||||||
function! s:_get_functions(sid) abort
|
|
||||||
let funcs = s:_redir(printf("function /\\%%#=2^\<SNR>%d_", a:sid))
|
|
||||||
let map_pat = '<SNR>' . a:sid . '_\zs\w\+'
|
|
||||||
return map(split(funcs, "\n"), 'matchstr(v:val, map_pat)')
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:_get_functions(sid) abort
|
|
||||||
let prefix = '<SNR>' . a:sid . '_'
|
|
||||||
let funcs = s:_redir('function')
|
|
||||||
let filter_pat = '^\s*function ' . prefix
|
|
||||||
let map_pat = prefix . '\zs\w\+'
|
|
||||||
return map(filter(split(funcs, "\n"),
|
|
||||||
\ 'stridx(v:val, prefix) > 0 && v:val =~# filter_pat'),
|
|
||||||
\ 'matchstr(v:val, map_pat)')
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
if exists('*uniq')
|
|
||||||
function! s:_uniq(list) abort
|
|
||||||
return uniq(a:list)
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:_uniq(list) abort
|
|
||||||
let i = len(a:list) - 1
|
|
||||||
while 0 < i
|
|
||||||
if a:list[i] ==# a:list[i - 1]
|
|
||||||
call remove(a:list, i)
|
|
||||||
let i -= 2
|
|
||||||
else
|
|
||||||
let i -= 1
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
return a:list
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! s:_concat(lists) abort
|
|
||||||
let result_list = []
|
|
||||||
for list in a:lists
|
|
||||||
let result_list += list
|
|
||||||
endfor
|
|
||||||
return result_list
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_redir(cmd) abort
|
|
||||||
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
|
|
||||||
set verbose=0 verbosefile=
|
|
||||||
redir => res
|
|
||||||
silent! execute a:cmd
|
|
||||||
redir END
|
|
||||||
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
|
|
||||||
return res
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! vital#{s:self_version}#new() abort
|
|
||||||
return s:_import('')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
" ___vital___
|
||||||
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
||||||
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
execute join(['function! vital#_crystal#ColorEcho#import() abort', printf("return map({'get_echorizer': '', 'echo': '', 'is_available': ''}, \"vital#_crystal#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
||||||
|
delfunction s:_SID
|
||||||
|
" ___vital___
|
||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
" ___vital___
|
||||||
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
||||||
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
execute join(['function! vital#_crystal#Data#List#import() abort', printf("return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'shift': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'drop_while': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'map_accum': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, \"vital#_crystal#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
||||||
|
delfunction s:_SID
|
||||||
|
" ___vital___
|
||||||
" Utilities for list.
|
" Utilities for list.
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
@@ -175,6 +184,11 @@ function! s:take_while(f, xs) abort
|
|||||||
return s:span(a:f, a:xs)[0]
|
return s:span(a:f, a:xs)[0]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" similar to Haskell's Data.List.dropWhile
|
||||||
|
function! s:drop_while(f, xs) abort
|
||||||
|
return s:span(a:f, a:xs)[1]
|
||||||
|
endfunction
|
||||||
|
|
||||||
" similar to Haskell's Data.List.partition
|
" similar to Haskell's Data.List.partition
|
||||||
function! s:partition(f, xs) abort
|
function! s:partition(f, xs) abort
|
||||||
return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')]
|
return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')]
|
||||||
@@ -271,14 +285,22 @@ endfunction
|
|||||||
|
|
||||||
" similar to Ruby's detect or Haskell's find.
|
" similar to Ruby's detect or Haskell's find.
|
||||||
function! s:find(list, default, f) abort
|
function! s:find(list, default, f) abort
|
||||||
|
let l:Call = type(a:f) is type(function('function'))
|
||||||
|
\ ? function('call')
|
||||||
|
\ : function('s:_call_string_expr')
|
||||||
|
|
||||||
for x in a:list
|
for x in a:list
|
||||||
if eval(substitute(a:f, 'v:val', string(x), 'g'))
|
if l:Call(a:f, [x])
|
||||||
return x
|
return x
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return a:default
|
return a:default
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:_call_string_expr(expr, args) abort
|
||||||
|
return map([a:args[0]], a:expr)[0]
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Returns the index of the first element which satisfies the given expr.
|
" Returns the index of the first element which satisfies the given expr.
|
||||||
function! s:find_index(xs, f, ...) abort
|
function! s:find_index(xs, f, ...) abort
|
||||||
let len = len(a:xs)
|
let len = len(a:xs)
|
||||||
@@ -426,7 +448,7 @@ function! s:combinations(list, r) abort
|
|||||||
if a:r > len(a:list)
|
if a:r > len(a:list)
|
||||||
return []
|
return []
|
||||||
elseif a:r < 0
|
elseif a:r < 0
|
||||||
throw 'vital: Data:List: {r} must be non-negative integer'
|
throw 'vital: Data.List: {r} must be non-negative integer'
|
||||||
endif
|
endif
|
||||||
let n = len(a:list)
|
let n = len(a:list)
|
||||||
let result = []
|
let result = []
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
" ___vital___
|
||||||
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
||||||
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
execute join(['function! vital#_crystal#Data#String#import() abort', printf("return map({'starts_with': '', 'split3': '', 'replace_first': '', 'chop': '', 'unescape': '', 'split_posix_text': '', 'replace': '', 'scan': '', 'strwidthpart': '', 'common_head': '', 'reverse': '', 'escape_pattern': '', 'trim_end': '', '_vital_depends': '', 'wrap': '', 'join_posix_lines': '', 'contains_multibyte': '', 'truncate_skipping': '', 'split_leftright': '', 'ends_with': '', 'nsplit': '', 'strwidthpart_reverse': '', 'unescape_pattern': '', 'levenshtein_distance': '', 'trim_start': '', 'justify_equal_spacing': '', 'nr2hex': '', 'iconv': '', 'pad_left': '', 'nr2enc_char': '', 'lines': '', 'repair_posix_text': '', 'nr2byte': '', 'trim': '', 'diffidx': '', 'truncate': '', 'split_by_displaywidth': '', '_vital_created': '', 'padding_by_displaywidth': '', 'hash': '', 'chomp': '', 'pad_between_letters': '', 'dstring': '', 'pad_both_sides': '', 'substitute_last': '', 'pad_right': '', 'remove_ansi_sequences': '', '_vital_loaded': ''}, \"vital#_crystal#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
||||||
|
delfunction s:_SID
|
||||||
|
" ___vital___
|
||||||
" Utilities for string.
|
" Utilities for string.
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
@@ -7,12 +16,21 @@ set cpo&vim
|
|||||||
|
|
||||||
function! s:_vital_loaded(V) abort
|
function! s:_vital_loaded(V) abort
|
||||||
let s:V = a:V
|
let s:V = a:V
|
||||||
let s:P = s:V.import('Prelude')
|
|
||||||
let s:L = s:V.import('Data.List')
|
let s:L = s:V.import('Data.List')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_vital_depends() abort
|
function! s:_vital_depends() abort
|
||||||
return ['Prelude', 'Data.List']
|
return ['Data.List']
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_vital_created(module) abort
|
||||||
|
" Expose script-local funcref
|
||||||
|
if exists('s:strchars')
|
||||||
|
let a:module.strchars = s:strchars
|
||||||
|
endif
|
||||||
|
if exists('s:wcswidth')
|
||||||
|
let a:module.wcswidth = s:wcswidth
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Substitute a:from => a:to by string.
|
" Substitute a:from => a:to by string.
|
||||||
@@ -61,7 +79,7 @@ function! s:common_head(strs) abort
|
|||||||
endif
|
endif
|
||||||
let strs = len == 2 ? a:strs : sort(copy(a:strs))
|
let strs = len == 2 ? a:strs : sort(copy(a:strs))
|
||||||
let pat = substitute(strs[0], '.', '\="[" . escape(submatch(0), "^\\") . "]"', 'g')
|
let pat = substitute(strs[0], '.', '\="[" . escape(submatch(0), "^\\") . "]"', 'g')
|
||||||
return pat == '' ? '' : matchstr(strs[-1], '\C^\%[' . pat . ']')
|
return pat ==# '' ? '' : matchstr(strs[-1], '\C^\%[' . pat . ']')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Split to two elements of List. ([left, right])
|
" Split to two elements of List. ([left, right])
|
||||||
@@ -130,9 +148,7 @@ endfunction
|
|||||||
" even if a:str contains multibyte character(s).
|
" even if a:str contains multibyte character(s).
|
||||||
" s:strchars(str) {{{
|
" s:strchars(str) {{{
|
||||||
if exists('*strchars')
|
if exists('*strchars')
|
||||||
function! s:strchars(str) abort
|
let s:strchars = function('strchars')
|
||||||
return strchars(a:str)
|
|
||||||
endfunction
|
|
||||||
else
|
else
|
||||||
function! s:strchars(str) abort
|
function! s:strchars(str) abort
|
||||||
return strlen(substitute(copy(a:str), '.', 'x', 'g'))
|
return strlen(substitute(copy(a:str), '.', 'x', 'g'))
|
||||||
@@ -210,7 +226,7 @@ function! s:nr2byte(nr) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:nr2enc_char(charcode) abort
|
function! s:nr2enc_char(charcode) abort
|
||||||
if &encoding == 'utf-8'
|
if &encoding ==# 'utf-8'
|
||||||
return nr2char(a:charcode)
|
return nr2char(a:charcode)
|
||||||
endif
|
endif
|
||||||
let char = s:nr2byte(a:charcode)
|
let char = s:nr2byte(a:charcode)
|
||||||
@@ -222,7 +238,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:nr2hex(nr) abort
|
function! s:nr2hex(nr) abort
|
||||||
let n = a:nr
|
let n = a:nr
|
||||||
let r = ""
|
let r = ''
|
||||||
while n
|
while n
|
||||||
let r = '0123456789ABCDEF'[n % 16] . r
|
let r = '0123456789ABCDEF'[n % 16] . r
|
||||||
let n = n / 16
|
let n = n / 16
|
||||||
@@ -318,7 +334,7 @@ function! s:levenshtein_distance(str1, str2) abort
|
|||||||
let letters2 = split(a:str2, '\zs')
|
let letters2 = split(a:str2, '\zs')
|
||||||
let length1 = len(letters1)
|
let length1 = len(letters1)
|
||||||
let length2 = len(letters2)
|
let length2 = len(letters2)
|
||||||
let distances = map(range(1, length1 + 1), 'map(range(1, length2 + 1), "0")')
|
let distances = map(range(1, length1 + 1), 'map(range(1, length2 + 1), ''0'')')
|
||||||
|
|
||||||
for i1 in range(0, length1)
|
for i1 in range(0, length1)
|
||||||
let distances[i1][0] = i1
|
let distances[i1][0] = i1
|
||||||
@@ -373,7 +389,7 @@ function! s:split_by_displaywidth(expr, width, float, is_wrap) abort
|
|||||||
|
|
||||||
let text = ''
|
let text = ''
|
||||||
while cs_index < len(cs)
|
while cs_index < len(cs)
|
||||||
if cs[cs_index] is "\n"
|
if cs[cs_index] is# "\n"
|
||||||
let text = s:padding_by_displaywidth(text, a:width, a:float)
|
let text = s:padding_by_displaywidth(text, a:width, a:float)
|
||||||
let lines += [text]
|
let lines += [text]
|
||||||
let text = ''
|
let text = ''
|
||||||
@@ -394,7 +410,7 @@ function! s:split_by_displaywidth(expr, width, float, is_wrap) abort
|
|||||||
if a:is_wrap
|
if a:is_wrap
|
||||||
if a:width < w
|
if a:width < w
|
||||||
if a:width < strdisplaywidth(cs[cs_index])
|
if a:width < strdisplaywidth(cs[cs_index])
|
||||||
while get(cs, cs_index, "\n") isnot "\n"
|
while get(cs, cs_index, "\n") isnot# "\n"
|
||||||
let cs_index += 1
|
let cs_index += 1
|
||||||
endwhile
|
endwhile
|
||||||
continue
|
continue
|
||||||
@@ -403,7 +419,7 @@ function! s:split_by_displaywidth(expr, width, float, is_wrap) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
while get(cs, cs_index, "\n") isnot "\n"
|
while get(cs, cs_index, "\n") isnot# "\n"
|
||||||
let cs_index += 1
|
let cs_index += 1
|
||||||
endwhile
|
endwhile
|
||||||
continue
|
continue
|
||||||
@@ -440,8 +456,9 @@ function! s:truncate(str, width) abort
|
|||||||
" http://github.com/mattn/googlereader-vim/tree/master
|
" http://github.com/mattn/googlereader-vim/tree/master
|
||||||
|
|
||||||
if a:str =~# '^[\x00-\x7f]*$'
|
if a:str =~# '^[\x00-\x7f]*$'
|
||||||
return len(a:str) < a:width ?
|
return len(a:str) < a:width
|
||||||
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
|
\ ? printf('%-' . a:width . 's', a:str)
|
||||||
|
\ : strpart(a:str, 0, a:width)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let ret = a:str
|
let ret = a:str
|
||||||
@@ -471,57 +488,20 @@ function! s:truncate_skipping(str, max, footer_width, separator) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:strwidthpart(str, width) abort
|
function! s:strwidthpart(str, width) abort
|
||||||
if a:width <= 0
|
let str = tr(a:str, "\t", ' ')
|
||||||
return ''
|
let vcol = a:width + 2
|
||||||
endif
|
return matchstr(str, '.*\%<' . (vcol < 0 ? 0 : vcol) . 'v')
|
||||||
let strarr = split(a:str, '\zs')
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
let index = len(strarr)
|
|
||||||
let diff = (index + 1) / 2
|
|
||||||
let rightindex = index - 1
|
|
||||||
while width > a:width
|
|
||||||
let index = max([rightindex - diff + 1, 0])
|
|
||||||
let partwidth = s:wcswidth(join(strarr[(index):(rightindex)], ''))
|
|
||||||
if width - partwidth >= a:width || diff <= 1
|
|
||||||
let width -= partwidth
|
|
||||||
let rightindex = index - 1
|
|
||||||
endif
|
|
||||||
if diff > 1
|
|
||||||
let diff = diff / 2
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
return index ? join(strarr[:index - 1], '') : ''
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:strwidthpart_reverse(str, width) abort
|
function! s:strwidthpart_reverse(str, width) abort
|
||||||
if a:width <= 0
|
let str = tr(a:str, "\t", ' ')
|
||||||
return ''
|
let vcol = s:wcswidth(str) - a:width
|
||||||
endif
|
return matchstr(str, '\%>' . (vcol < 0 ? 0 : vcol) . 'v.*')
|
||||||
let strarr = split(a:str, '\zs')
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
let strlen = len(strarr)
|
|
||||||
let diff = (strlen + 1) / 2
|
|
||||||
let leftindex = 0
|
|
||||||
let index = -1
|
|
||||||
while width > a:width
|
|
||||||
let index = min([leftindex + diff, strlen]) - 1
|
|
||||||
let partwidth = s:wcswidth(join(strarr[(leftindex):(index)], ''))
|
|
||||||
if width - partwidth >= a:width || diff <= 1
|
|
||||||
let width -= partwidth
|
|
||||||
let leftindex = index + 1
|
|
||||||
endif
|
|
||||||
if diff > 1
|
|
||||||
let diff = diff / 2
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
return index < strlen ? join(strarr[(index + 1):], '') : ''
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if v:version >= 703
|
if v:version >= 703
|
||||||
" Use builtin function.
|
" Use builtin function.
|
||||||
function! s:wcswidth(str) abort
|
let s:wcswidth = function('strwidth')
|
||||||
return strwidth(a:str)
|
|
||||||
endfunction
|
|
||||||
else
|
else
|
||||||
function! s:wcswidth(str) abort
|
function! s:wcswidth(str) abort
|
||||||
if a:str =~# '^[\x00-\x7f]*$'
|
if a:str =~# '^[\x00-\x7f]*$'
|
||||||
@@ -564,9 +544,88 @@ else
|
|||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! s:remove_ansi_sequences(text) abort
|
||||||
|
return substitute(a:text, '\e\[\%(\%(\d\+;\)*\d\+\)\?[mK]', '', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:escape_pattern(str) abort
|
||||||
|
" escape characters for no-magic
|
||||||
|
return escape(a:str, '^$~.*[]\')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:unescape_pattern(str) abort
|
||||||
|
" unescape characters for no-magic
|
||||||
|
return s:unescape(a:str, '^$~.*[]\')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:unescape(str, chars) abort
|
||||||
|
let chars = map(split(a:chars, '\zs'), 'escape(v:val, ''^$~.*[]\'')')
|
||||||
|
return substitute(a:str, '\\\(' . join(chars, '\|') . '\)', '\1', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:iconv(expr, from, to) abort
|
||||||
|
if a:from ==# '' || a:to ==# '' || a:from ==? a:to
|
||||||
|
return a:expr
|
||||||
|
endif
|
||||||
|
let result = iconv(a:expr, a:from, a:to)
|
||||||
|
return empty(result) ? a:expr : result
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" NOTE:
|
||||||
|
" A definition of a TEXT file is "A file that contains characters organized
|
||||||
|
" into one or more lines."
|
||||||
|
" A definition of a LINE is "A sequence of zero or more non- <newline>s
|
||||||
|
" plus a terminating <newline>"
|
||||||
|
" That's why {stdin} always ends with <newline> ideally. However, there are
|
||||||
|
" some programs which does not follow the POSIX rule and a Vim's way to join
|
||||||
|
" List into TEXT; join({text}, "\n"); does not add <newline> to the end of
|
||||||
|
" the last line.
|
||||||
|
" That's why add a trailing <newline> if it does not exist.
|
||||||
|
" REF:
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
|
||||||
|
" :help split()
|
||||||
|
" NOTE:
|
||||||
|
" it does nothing if the text is a correct POSIX text
|
||||||
|
function! s:repair_posix_text(text, ...) abort
|
||||||
|
let newline = get(a:000, 0, "\n")
|
||||||
|
return a:text =~# '\n$' ? a:text : a:text . newline
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" NOTE:
|
||||||
|
" A definition of a TEXT file is "A file that contains characters organized
|
||||||
|
" into one or more lines."
|
||||||
|
" A definition of a LINE is "A sequence of zero or more non- <newline>s
|
||||||
|
" plus a terminating <newline>"
|
||||||
|
" REF:
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
|
||||||
|
function! s:join_posix_lines(lines, ...) abort
|
||||||
|
let newline = get(a:000, 0, "\n")
|
||||||
|
return join(a:lines, newline) . newline
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" NOTE:
|
||||||
|
" A definition of a TEXT file is "A file that contains characters organized
|
||||||
|
" into one or more lines."
|
||||||
|
" A definition of a LINE is "A sequence of zero or more non- <newline>s
|
||||||
|
" plus a terminating <newline>"
|
||||||
|
" TEXT into List; split({text}, '\r\?\n', 1); add an extra empty line at the
|
||||||
|
" end of List because the end of TEXT ends with <newline> and keepempty=1 is
|
||||||
|
" specified. (btw. keepempty=0 cannot be used because it will remove
|
||||||
|
" emptylines in the head and the tail).
|
||||||
|
" That's why removing a trailing <newline> before proceeding to 'split' is required
|
||||||
|
" REF:
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_392
|
||||||
|
" http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_205
|
||||||
|
function! s:split_posix_text(text, ...) abort
|
||||||
|
let newline = get(a:000, 0, '\r\?\n')
|
||||||
|
let text = substitute(a:text, newline . '$', '', '')
|
||||||
|
return split(text, newline, 1)
|
||||||
|
endfunction
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,389 +0,0 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
|
||||||
set cpo&vim
|
|
||||||
|
|
||||||
if v:version ># 703 ||
|
|
||||||
\ (v:version is 703 && has('patch465'))
|
|
||||||
function! s:glob(expr) abort
|
|
||||||
return glob(a:expr, 1, 1)
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:glob(expr) abort
|
|
||||||
let R = glob(a:expr, 1)
|
|
||||||
return split(R, '\n')
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! s:globpath(path, expr) abort
|
|
||||||
let R = globpath(a:path, a:expr, 1)
|
|
||||||
return split(R, '\n')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Wrapper functions for type().
|
|
||||||
let [
|
|
||||||
\ s:__TYPE_NUMBER,
|
|
||||||
\ s:__TYPE_STRING,
|
|
||||||
\ s:__TYPE_FUNCREF,
|
|
||||||
\ s:__TYPE_LIST,
|
|
||||||
\ s:__TYPE_DICT,
|
|
||||||
\ s:__TYPE_FLOAT] = [
|
|
||||||
\ type(3),
|
|
||||||
\ type(""),
|
|
||||||
\ type(function('tr')),
|
|
||||||
\ type([]),
|
|
||||||
\ type({}),
|
|
||||||
\ has('float') ? type(str2float('0')) : -1]
|
|
||||||
" __TYPE_FLOAT = -1 when -float
|
|
||||||
" This doesn't match to anything.
|
|
||||||
|
|
||||||
" Number or Float
|
|
||||||
function! s:is_numeric(Value) abort
|
|
||||||
let _ = type(a:Value)
|
|
||||||
return _ ==# s:__TYPE_NUMBER
|
|
||||||
\ || _ ==# s:__TYPE_FLOAT
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Number
|
|
||||||
function! s:is_number(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_NUMBER
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Float
|
|
||||||
function! s:is_float(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_FLOAT
|
|
||||||
endfunction
|
|
||||||
" String
|
|
||||||
function! s:is_string(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_STRING
|
|
||||||
endfunction
|
|
||||||
" Funcref
|
|
||||||
function! s:is_funcref(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_FUNCREF
|
|
||||||
endfunction
|
|
||||||
" List
|
|
||||||
function! s:is_list(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_LIST
|
|
||||||
endfunction
|
|
||||||
" Dictionary
|
|
||||||
function! s:is_dict(Value) abort
|
|
||||||
return type(a:Value) ==# s:__TYPE_DICT
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:truncate_skipping(str, max, footer_width, separator) abort
|
|
||||||
call s:_warn_deprecated("truncate_skipping", "Data.String.truncate_skipping")
|
|
||||||
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
if width <= a:max
|
|
||||||
let ret = a:str
|
|
||||||
else
|
|
||||||
let header_width = a:max - s:wcswidth(a:separator) - a:footer_width
|
|
||||||
let ret = s:strwidthpart(a:str, header_width) . a:separator
|
|
||||||
\ . s:strwidthpart_reverse(a:str, a:footer_width)
|
|
||||||
endif
|
|
||||||
|
|
||||||
return s:truncate(ret, a:max)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:truncate(str, width) abort
|
|
||||||
" Original function is from mattn.
|
|
||||||
" http://github.com/mattn/googlereader-vim/tree/master
|
|
||||||
|
|
||||||
call s:_warn_deprecated("truncate", "Data.String.truncate")
|
|
||||||
|
|
||||||
if a:str =~# '^[\x00-\x7f]*$'
|
|
||||||
return len(a:str) < a:width ?
|
|
||||||
\ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let ret = a:str
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
if width > a:width
|
|
||||||
let ret = s:strwidthpart(ret, a:width)
|
|
||||||
let width = s:wcswidth(ret)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if width < a:width
|
|
||||||
let ret .= repeat(' ', a:width - width)
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ret
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:strwidthpart(str, width) abort
|
|
||||||
call s:_warn_deprecated("strwidthpart", "Data.String.strwidthpart")
|
|
||||||
|
|
||||||
if a:width <= 0
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
let ret = a:str
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
while width > a:width
|
|
||||||
let char = matchstr(ret, '.$')
|
|
||||||
let ret = ret[: -1 - len(char)]
|
|
||||||
let width -= s:wcswidth(char)
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
return ret
|
|
||||||
endfunction
|
|
||||||
function! s:strwidthpart_reverse(str, width) abort
|
|
||||||
call s:_warn_deprecated("strwidthpart_reverse", "Data.String.strwidthpart_reverse")
|
|
||||||
|
|
||||||
if a:width <= 0
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
let ret = a:str
|
|
||||||
let width = s:wcswidth(a:str)
|
|
||||||
while width > a:width
|
|
||||||
let char = matchstr(ret, '^.')
|
|
||||||
let ret = ret[len(char) :]
|
|
||||||
let width -= s:wcswidth(char)
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
return ret
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if v:version >= 703
|
|
||||||
" Use builtin function.
|
|
||||||
function! s:wcswidth(str) abort
|
|
||||||
call s:_warn_deprecated("wcswidth", "Data.String.wcswidth")
|
|
||||||
return strwidth(a:str)
|
|
||||||
endfunction
|
|
||||||
else
|
|
||||||
function! s:wcswidth(str) abort
|
|
||||||
call s:_warn_deprecated("wcswidth", "Data.String.wcswidth")
|
|
||||||
|
|
||||||
if a:str =~# '^[\x00-\x7f]*$'
|
|
||||||
return strlen(a:str)
|
|
||||||
end
|
|
||||||
|
|
||||||
let mx_first = '^\(.\)'
|
|
||||||
let str = a:str
|
|
||||||
let width = 0
|
|
||||||
while 1
|
|
||||||
let ucs = char2nr(substitute(str, mx_first, '\1', ''))
|
|
||||||
if ucs == 0
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
let width += s:_wcwidth(ucs)
|
|
||||||
let str = substitute(str, mx_first, '', '')
|
|
||||||
endwhile
|
|
||||||
return width
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" UTF-8 only.
|
|
||||||
function! s:_wcwidth(ucs) abort
|
|
||||||
let ucs = a:ucs
|
|
||||||
if (ucs >= 0x1100
|
|
||||||
\ && (ucs <= 0x115f
|
|
||||||
\ || ucs == 0x2329
|
|
||||||
\ || ucs == 0x232a
|
|
||||||
\ || (ucs >= 0x2e80 && ucs <= 0xa4cf
|
|
||||||
\ && ucs != 0x303f)
|
|
||||||
\ || (ucs >= 0xac00 && ucs <= 0xd7a3)
|
|
||||||
\ || (ucs >= 0xf900 && ucs <= 0xfaff)
|
|
||||||
\ || (ucs >= 0xfe30 && ucs <= 0xfe6f)
|
|
||||||
\ || (ucs >= 0xff00 && ucs <= 0xff60)
|
|
||||||
\ || (ucs >= 0xffe0 && ucs <= 0xffe6)
|
|
||||||
\ || (ucs >= 0x20000 && ucs <= 0x2fffd)
|
|
||||||
\ || (ucs >= 0x30000 && ucs <= 0x3fffd)
|
|
||||||
\ ))
|
|
||||||
return 2
|
|
||||||
endif
|
|
||||||
return 1
|
|
||||||
endfunction
|
|
||||||
endif
|
|
||||||
|
|
||||||
let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95')
|
|
||||||
let s:is_cygwin = has('win32unix')
|
|
||||||
let s:is_mac = !s:is_windows && !s:is_cygwin
|
|
||||||
\ && (has('mac') || has('macunix') || has('gui_macvim') ||
|
|
||||||
\ (!isdirectory('/proc') && executable('sw_vers')))
|
|
||||||
let s:is_unix = has('unix')
|
|
||||||
|
|
||||||
function! s:is_windows() abort
|
|
||||||
return s:is_windows
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:is_cygwin() abort
|
|
||||||
return s:is_cygwin
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:is_mac() abort
|
|
||||||
return s:is_mac
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:is_unix() abort
|
|
||||||
return s:is_unix
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_warn_deprecated(name, alternative) abort
|
|
||||||
try
|
|
||||||
echohl Error
|
|
||||||
echomsg "Prelude." . a:name . " is deprecated! Please use " . a:alternative . " instead."
|
|
||||||
finally
|
|
||||||
echohl None
|
|
||||||
endtry
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:smart_execute_command(action, word) abort
|
|
||||||
execute a:action . ' ' . (a:word == '' ? '' : '`=a:word`')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:escape_file_searching(buffer_name) abort
|
|
||||||
return escape(a:buffer_name, '*[]?{}, ')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:escape_pattern(str) abort
|
|
||||||
return escape(a:str, '~"\.^$[]*')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:getchar(...) abort
|
|
||||||
let c = call('getchar', a:000)
|
|
||||||
return type(c) == type(0) ? nr2char(c) : c
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:getchar_safe(...) abort
|
|
||||||
let c = s:input_helper('getchar', a:000)
|
|
||||||
return type(c) == type("") ? c : nr2char(c)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:input_safe(...) abort
|
|
||||||
return s:input_helper('input', a:000)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:input_helper(funcname, args) abort
|
|
||||||
let success = 0
|
|
||||||
if inputsave() !=# success
|
|
||||||
throw 'vital: Prelude: inputsave() failed'
|
|
||||||
endif
|
|
||||||
try
|
|
||||||
return call(a:funcname, a:args)
|
|
||||||
finally
|
|
||||||
if inputrestore() !=# success
|
|
||||||
throw 'vital: Prelude: inputrestore() failed'
|
|
||||||
endif
|
|
||||||
endtry
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:set_default(var, val) abort
|
|
||||||
if !exists(a:var) || type({a:var}) != type(a:val)
|
|
||||||
let {a:var} = a:val
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:substitute_path_separator(path) abort
|
|
||||||
return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:path2directory(path) abort
|
|
||||||
return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h'))
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_path2project_directory_git(path) abort
|
|
||||||
let parent = a:path
|
|
||||||
|
|
||||||
while 1
|
|
||||||
let path = parent . '/.git'
|
|
||||||
if isdirectory(path) || filereadable(path)
|
|
||||||
return parent
|
|
||||||
endif
|
|
||||||
let next = fnamemodify(parent, ':h')
|
|
||||||
if next == parent
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
let parent = next
|
|
||||||
endwhile
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_path2project_directory_svn(path) abort
|
|
||||||
let search_directory = a:path
|
|
||||||
let directory = ''
|
|
||||||
|
|
||||||
let find_directory = s:escape_file_searching(search_directory)
|
|
||||||
let d = finddir('.svn', find_directory . ';')
|
|
||||||
if d == ''
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
|
|
||||||
let directory = fnamemodify(d, ':p:h:h')
|
|
||||||
|
|
||||||
" Search parent directories.
|
|
||||||
let parent_directory = s:path2directory(
|
|
||||||
\ fnamemodify(directory, ':h'))
|
|
||||||
|
|
||||||
if parent_directory != ''
|
|
||||||
let d = finddir('.svn', parent_directory . ';')
|
|
||||||
if d != ''
|
|
||||||
let directory = s:_path2project_directory_svn(parent_directory)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
return directory
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:_path2project_directory_others(vcs, path) abort
|
|
||||||
let vcs = a:vcs
|
|
||||||
let search_directory = a:path
|
|
||||||
|
|
||||||
let find_directory = s:escape_file_searching(search_directory)
|
|
||||||
let d = finddir(vcs, find_directory . ';')
|
|
||||||
if d == ''
|
|
||||||
return ''
|
|
||||||
endif
|
|
||||||
return fnamemodify(d, ':p:h:h')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:path2project_directory(path, ...) abort
|
|
||||||
let is_allow_empty = get(a:000, 0, 0)
|
|
||||||
let search_directory = s:path2directory(a:path)
|
|
||||||
let directory = ''
|
|
||||||
|
|
||||||
" Search VCS directory.
|
|
||||||
for vcs in ['.git', '.bzr', '.hg', '.svn']
|
|
||||||
if vcs ==# '.git'
|
|
||||||
let directory = s:_path2project_directory_git(search_directory)
|
|
||||||
elseif vcs ==# '.svn'
|
|
||||||
let directory = s:_path2project_directory_svn(search_directory)
|
|
||||||
else
|
|
||||||
let directory = s:_path2project_directory_others(vcs, search_directory)
|
|
||||||
endif
|
|
||||||
if directory != ''
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
" Search project file.
|
|
||||||
if directory == ''
|
|
||||||
for d in ['build.xml', 'prj.el', '.project', 'pom.xml', 'package.json',
|
|
||||||
\ 'Makefile', 'configure', 'Rakefile', 'NAnt.build',
|
|
||||||
\ 'P4CONFIG', 'tags', 'gtags']
|
|
||||||
let d = findfile(d, s:escape_file_searching(search_directory) . ';')
|
|
||||||
if d != ''
|
|
||||||
let directory = fnamemodify(d, ':p:h')
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
|
|
||||||
if directory == ''
|
|
||||||
" Search /src/ directory.
|
|
||||||
let base = s:substitute_path_separator(search_directory)
|
|
||||||
if base =~# '/src/'
|
|
||||||
let directory = base[: strridx(base, '/src/') + 3]
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
if directory == '' && !is_allow_empty
|
|
||||||
" Use original path.
|
|
||||||
let directory = search_directory
|
|
||||||
endif
|
|
||||||
|
|
||||||
return s:substitute_path_separator(directory)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
|
||||||
unlet s:save_cpo
|
|
||||||
|
|
||||||
" vim:set et ts=2 sts=2 sw=2 tw=0:
|
|
||||||
|
|
||||||
endif
|
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
" ___vital___
|
||||||
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
||||||
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
execute join(['function! vital#_crystal#Process#import() abort', printf("return map({'shellescape': '', 'has_vimproc': '', 'system': '', 'iconv': '', 'spawn': '', 'get_last_status': ''}, \"vital#_crystal#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
||||||
|
delfunction s:_SID
|
||||||
|
" ___vital___
|
||||||
" TODO: move all comments to doc file.
|
" TODO: move all comments to doc file.
|
||||||
"
|
"
|
||||||
"
|
"
|
||||||
@@ -21,62 +30,36 @@ let s:need_trans = v:version < 704 || (v:version == 704 && !has('patch122'))
|
|||||||
|
|
||||||
let s:TYPE_DICT = type({})
|
let s:TYPE_DICT = type({})
|
||||||
let s:TYPE_LIST = type([])
|
let s:TYPE_LIST = type([])
|
||||||
let s:TYPE_STRING = type("")
|
let s:TYPE_STRING = type('')
|
||||||
|
|
||||||
|
|
||||||
" Execute program in the background from Vim.
|
|
||||||
" Return an empty string always.
|
|
||||||
"
|
|
||||||
" If a:expr is a List, shellescape() each argument.
|
|
||||||
" If a:expr is a String, the arguments are passed as-is.
|
|
||||||
"
|
|
||||||
" Windows:
|
|
||||||
" Using :!start , execute program without via cmd.exe.
|
|
||||||
" Spawning 'expr' with 'noshellslash'
|
|
||||||
" keep special characters from unwanted expansion.
|
|
||||||
" (see :help shellescape())
|
|
||||||
"
|
|
||||||
" Unix:
|
|
||||||
" using :! , execute program in the background by shell.
|
|
||||||
function! s:spawn(expr, ...) abort
|
function! s:spawn(expr, ...) abort
|
||||||
let shellslash = 0
|
if type(a:expr) is s:TYPE_LIST
|
||||||
if s:is_windows
|
let special = 1
|
||||||
let shellslash = &l:shellslash
|
let cmdline = join(map(a:expr, 's:shellescape(v:val, special)'), ' ')
|
||||||
setlocal noshellslash
|
elseif type(a:expr) is s:TYPE_STRING
|
||||||
|
let cmdline = a:expr
|
||||||
|
if a:0 && a:1
|
||||||
|
" for :! command
|
||||||
|
let cmdline = substitute(cmdline, '\([!%#]\|<[^<>]\+>\)', '\\\1', 'g')
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
throw 'vital: Process: invalid argument (value type:' . type(a:expr) . ')'
|
||||||
|
endif
|
||||||
|
if s:is_windows
|
||||||
|
silent execute '!start' cmdline
|
||||||
|
else
|
||||||
|
silent execute '!' cmdline '&'
|
||||||
endif
|
endif
|
||||||
try
|
|
||||||
if type(a:expr) is s:TYPE_LIST
|
|
||||||
let special = 1
|
|
||||||
let cmdline = join(map(a:expr, 'shellescape(v:val, special)'), ' ')
|
|
||||||
elseif type(a:expr) is s:TYPE_STRING
|
|
||||||
let cmdline = a:expr
|
|
||||||
if a:0 && a:1
|
|
||||||
" for :! command
|
|
||||||
let cmdline = substitute(cmdline, '\([!%#]\|<[^<>]\+>\)', '\\\1', 'g')
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
throw 'Process.spawn(): invalid argument (value type:'.type(a:expr).')'
|
|
||||||
endif
|
|
||||||
if s:is_windows
|
|
||||||
silent execute '!start' cmdline
|
|
||||||
else
|
|
||||||
silent execute '!' cmdline '&'
|
|
||||||
endif
|
|
||||||
finally
|
|
||||||
if s:is_windows
|
|
||||||
let &l:shellslash = shellslash
|
|
||||||
endif
|
|
||||||
endtry
|
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" iconv() wrapper for safety.
|
" iconv() wrapper for safety.
|
||||||
function! s:iconv(expr, from, to) abort
|
function! s:iconv(expr, from, to) abort
|
||||||
if a:from == '' || a:to == '' || a:from ==? a:to
|
if a:from ==# '' || a:to ==# '' || a:from ==? a:to
|
||||||
return a:expr
|
return a:expr
|
||||||
endif
|
endif
|
||||||
let result = iconv(a:expr, a:from, a:to)
|
let result = iconv(a:expr, a:from, a:to)
|
||||||
return result != '' ? result : a:expr
|
return result !=# '' ? result : a:expr
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Check vimproc.
|
" Check vimproc.
|
||||||
@@ -128,7 +111,7 @@ function! s:system(str, ...) abort
|
|||||||
elseif type(a:1) is s:TYPE_STRING
|
elseif type(a:1) is s:TYPE_STRING
|
||||||
let args += [s:iconv(a:1, &encoding, 'char')]
|
let args += [s:iconv(a:1, &encoding, 'char')]
|
||||||
else
|
else
|
||||||
throw 'Process.system(): invalid argument (value type:'.type(a:1).')'
|
throw 'vital: Process: invalid argument (value type:' . type(a:1) . ')'
|
||||||
endif
|
endif
|
||||||
elseif a:0 >= 2
|
elseif a:0 >= 2
|
||||||
" {command} [, {input} [, {timeout}]]
|
" {command} [, {input} [, {timeout}]]
|
||||||
@@ -145,13 +128,16 @@ function! s:system(str, ...) abort
|
|||||||
elseif type(a:str) is s:TYPE_STRING
|
elseif type(a:str) is s:TYPE_STRING
|
||||||
let command = a:str
|
let command = a:str
|
||||||
else
|
else
|
||||||
throw 'Process.system(): invalid argument (value type:'.type(a:str).')'
|
throw 'vital: Process: invalid argument (value type:' . type(a:str) . ')'
|
||||||
endif
|
endif
|
||||||
if s:need_trans
|
if s:need_trans
|
||||||
let command = s:iconv(command, &encoding, 'char')
|
let command = s:iconv(command, &encoding, 'char')
|
||||||
endif
|
endif
|
||||||
let args = [command] + args
|
let args = [command] + args
|
||||||
if background && (use_vimproc || !s:is_windows)
|
if background && (use_vimproc || !s:is_windows)
|
||||||
|
if has('nvim')
|
||||||
|
throw "vital: Process: neovim's system() doesn't support background(&) process (cmdline:" . string(a:str) . ')'
|
||||||
|
endif
|
||||||
let args[0] = args[0] . ' &'
|
let args[0] = args[0] . ' &'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -167,8 +153,14 @@ function! s:get_last_status() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if s:is_windows
|
if s:is_windows
|
||||||
function! s:shellescape(command) abort
|
function! s:shellescape(...) abort
|
||||||
return substitute(a:command, '[&()[\]{}^=;!''+,`~]', '^\0', 'g')
|
try
|
||||||
|
let shellslash = &shellslash
|
||||||
|
set noshellslash
|
||||||
|
return call('shellescape', a:000)
|
||||||
|
finally
|
||||||
|
let &shellslash = shellslash
|
||||||
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:shellescape(...) abort
|
function! s:shellescape(...) abort
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
" ___vital___
|
||||||
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
||||||
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
execute join(['function! vital#_crystal#Web#JSON#import() abort', printf("return map({'decode': '', '_vital_depends': '', '_vital_created': '', 'encode': '', '_vital_loaded': ''}, \"vital#_crystal#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
||||||
|
delfunction s:_SID
|
||||||
|
" ___vital___
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
@@ -15,11 +24,6 @@ function! s:_null() abort
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:const = {}
|
|
||||||
let s:const.true = function('s:_true')
|
|
||||||
let s:const.false = function('s:_false')
|
|
||||||
let s:const.null = function('s:_null')
|
|
||||||
|
|
||||||
function! s:_resolve(val, prefix) abort
|
function! s:_resolve(val, prefix) abort
|
||||||
let t = type(a:val)
|
let t = type(a:val)
|
||||||
if t == type('')
|
if t == type('')
|
||||||
@@ -36,6 +40,13 @@ endfunction
|
|||||||
|
|
||||||
function! s:_vital_created(module) abort
|
function! s:_vital_created(module) abort
|
||||||
" define constant variables
|
" define constant variables
|
||||||
|
if !exists('s:const')
|
||||||
|
let s:const = {}
|
||||||
|
let s:const.true = function('s:_true')
|
||||||
|
let s:const.false = function('s:_false')
|
||||||
|
let s:const.null = function('s:_null')
|
||||||
|
lockvar s:const
|
||||||
|
endif
|
||||||
call extend(a:module, s:const)
|
call extend(a:module, s:const)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -55,7 +66,7 @@ function! s:decode(json, ...) abort
|
|||||||
let settings = extend({
|
let settings = extend({
|
||||||
\ 'use_token': 0,
|
\ 'use_token': 0,
|
||||||
\}, get(a:000, 0, {}))
|
\}, get(a:000, 0, {}))
|
||||||
let json = iconv(a:json, "utf-8", &encoding)
|
let json = iconv(a:json, 'utf-8', &encoding)
|
||||||
let json = join(split(json, "\n"), '')
|
let json = join(split(json, "\n"), '')
|
||||||
let json = substitute(json, '\\u34;', '\\"', 'g')
|
let json = substitute(json, '\\u34;', '\\"', 'g')
|
||||||
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=s:string.nr2enc_char("0x".submatch(1))', 'g')
|
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=s:string.nr2enc_char("0x".submatch(1))', 'g')
|
||||||
@@ -75,7 +86,11 @@ endfunction
|
|||||||
" @vimlint(EVL102, 0, l:true)
|
" @vimlint(EVL102, 0, l:true)
|
||||||
" @vimlint(EVL102, 0, l:false)
|
" @vimlint(EVL102, 0, l:false)
|
||||||
|
|
||||||
function! s:encode(val) abort
|
function! s:encode(val, ...) abort
|
||||||
|
let settings = extend({
|
||||||
|
\ 'indent': 0,
|
||||||
|
\}, get(a:000, 0, {})
|
||||||
|
\)
|
||||||
if type(a:val) == 0
|
if type(a:val) == 0
|
||||||
return a:val
|
return a:val
|
||||||
elseif type(a:val) == 1
|
elseif type(a:val) == 1
|
||||||
@@ -83,7 +98,7 @@ function! s:encode(val) abort
|
|||||||
let json = substitute(json, "\r", '\\r', 'g')
|
let json = substitute(json, "\r", '\\r', 'g')
|
||||||
let json = substitute(json, "\n", '\\n', 'g')
|
let json = substitute(json, "\n", '\\n', 'g')
|
||||||
let json = substitute(json, "\t", '\\t', 'g')
|
let json = substitute(json, "\t", '\\t', 'g')
|
||||||
return iconv(json, &encoding, "utf-8")
|
return iconv(json, &encoding, 'utf-8')
|
||||||
elseif type(a:val) == 2
|
elseif type(a:val) == 2
|
||||||
if s:const.true == a:val
|
if s:const.true == a:val
|
||||||
return 'true'
|
return 'true'
|
||||||
@@ -96,14 +111,69 @@ function! s:encode(val) abort
|
|||||||
return string(a:val)
|
return string(a:val)
|
||||||
endif
|
endif
|
||||||
elseif type(a:val) == 3
|
elseif type(a:val) == 3
|
||||||
return '[' . join(map(copy(a:val), 's:encode(v:val)'), ',') . ']'
|
return s:_encode_list(a:val, settings)
|
||||||
elseif type(a:val) == 4
|
elseif type(a:val) == 4
|
||||||
return '{' . join(map(keys(a:val), 's:encode(v:val).":".s:encode(a:val[v:val])'), ',') . '}'
|
return s:_encode_dict(a:val, settings)
|
||||||
else
|
else
|
||||||
return string(a:val)
|
return string(a:val)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" @vimlint(EVL102, 1, l:ns)
|
||||||
|
function! s:_encode_list(val, settings) abort
|
||||||
|
if empty(a:val)
|
||||||
|
return '[]'
|
||||||
|
elseif !a:settings.indent
|
||||||
|
let encoded_candidates = map(copy(a:val), 's:encode(v:val, a:settings)')
|
||||||
|
return printf('[%s]', join(encoded_candidates, ','))
|
||||||
|
else
|
||||||
|
let previous_indent = get(a:settings, '_previous_indent')
|
||||||
|
let indent = previous_indent + a:settings.indent
|
||||||
|
let ns = extend(copy(a:settings), {
|
||||||
|
\ '_previous_indent': indent,
|
||||||
|
\})
|
||||||
|
let encoded_candidates = map(
|
||||||
|
\ copy(a:val),
|
||||||
|
\ printf('''%s'' . s:encode(v:val, ns)', repeat(' ', indent)),
|
||||||
|
\)
|
||||||
|
return printf(
|
||||||
|
\ "[\n%s\n%s]",
|
||||||
|
\ join(encoded_candidates, ",\n"),
|
||||||
|
\ repeat(' ', previous_indent)
|
||||||
|
\)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" @vimlint(EVL102, 0, l:ns)
|
||||||
|
|
||||||
|
" @vimlint(EVL102, 1, l:ns)
|
||||||
|
function! s:_encode_dict(val, settings) abort
|
||||||
|
if empty(a:val)
|
||||||
|
return '{}'
|
||||||
|
elseif !a:settings.indent
|
||||||
|
let encoded_candidates = map(keys(a:val),
|
||||||
|
\ 's:encode(v:val, a:settings) . '':'' . s:encode(a:val[v:val], a:settings)'
|
||||||
|
\)
|
||||||
|
return printf('{%s}', join(encoded_candidates, ','))
|
||||||
|
else
|
||||||
|
let previous_indent = get(a:settings, '_previous_indent')
|
||||||
|
let indent = previous_indent + a:settings.indent
|
||||||
|
let ns = extend(copy(a:settings), {
|
||||||
|
\ '_previous_indent': indent,
|
||||||
|
\})
|
||||||
|
let encoded_candidates = map(keys(a:val),
|
||||||
|
\ printf(
|
||||||
|
\ '''%s'' . s:encode(v:val, ns) . '': '' . s:encode(a:val[v:val], ns)',
|
||||||
|
\ repeat(' ', indent),
|
||||||
|
\ ),
|
||||||
|
\)
|
||||||
|
return printf("{\n%s\n%s}",
|
||||||
|
\ join(encoded_candidates, ",\n"),
|
||||||
|
\ repeat(' ', previous_indent),
|
||||||
|
\)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
" @vimlint(EVL102, 0, l:ns)
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
|||||||
332
autoload/vital/crystal.vim
Normal file
332
autoload/vital/crystal.vim
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
let s:plugin_name = expand('<sfile>:t:r')
|
||||||
|
let s:vital_base_dir = expand('<sfile>:h')
|
||||||
|
let s:project_root = expand('<sfile>:h:h:h')
|
||||||
|
let s:is_vital_vim = s:plugin_name is# 'vital'
|
||||||
|
|
||||||
|
let s:loaded = {}
|
||||||
|
let s:cache_sid = {}
|
||||||
|
|
||||||
|
" function() wrapper
|
||||||
|
if v:version > 703 || v:version == 703 && has('patch1170')
|
||||||
|
function! s:_function(fstr) abort
|
||||||
|
return function(a:fstr)
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:_SID() abort
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
||||||
|
endfunction
|
||||||
|
let s:_s = '<SNR>' . s:_SID() . '_'
|
||||||
|
function! s:_function(fstr) abort
|
||||||
|
return function(substitute(a:fstr, 's:', s:_s, 'g'))
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! vital#{s:plugin_name}#new() abort
|
||||||
|
return s:new(s:plugin_name)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! vital#{s:plugin_name}#import(...) abort
|
||||||
|
if !exists('s:V')
|
||||||
|
let s:V = s:new(s:plugin_name)
|
||||||
|
endif
|
||||||
|
return call(s:V.import, a:000, s:V)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:Vital = {}
|
||||||
|
|
||||||
|
function! s:new(plugin_name) abort
|
||||||
|
let base = deepcopy(s:Vital)
|
||||||
|
let base._plugin_name = a:plugin_name
|
||||||
|
return base
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:vital_files() abort
|
||||||
|
if !exists('s:vital_files')
|
||||||
|
let s:vital_files = map(
|
||||||
|
\ s:is_vital_vim ? s:_global_vital_files() : s:_self_vital_files(),
|
||||||
|
\ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")')
|
||||||
|
endif
|
||||||
|
return copy(s:vital_files)
|
||||||
|
endfunction
|
||||||
|
let s:Vital.vital_files = s:_function('s:vital_files')
|
||||||
|
|
||||||
|
function! s:import(name, ...) abort dict
|
||||||
|
let target = {}
|
||||||
|
let functions = []
|
||||||
|
for a in a:000
|
||||||
|
if type(a) == type({})
|
||||||
|
let target = a
|
||||||
|
elseif type(a) == type([])
|
||||||
|
let functions = a
|
||||||
|
endif
|
||||||
|
unlet a
|
||||||
|
endfor
|
||||||
|
let module = self._import(a:name)
|
||||||
|
if empty(functions)
|
||||||
|
call extend(target, module, 'keep')
|
||||||
|
else
|
||||||
|
for f in functions
|
||||||
|
if has_key(module, f) && !has_key(target, f)
|
||||||
|
let target[f] = module[f]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
return target
|
||||||
|
endfunction
|
||||||
|
let s:Vital.import = s:_function('s:import')
|
||||||
|
|
||||||
|
function! s:load(...) abort dict
|
||||||
|
for arg in a:000
|
||||||
|
let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg]
|
||||||
|
let target = split(join(as, ''), '\W\+')
|
||||||
|
let dict = self
|
||||||
|
let dict_type = type({})
|
||||||
|
while !empty(target)
|
||||||
|
let ns = remove(target, 0)
|
||||||
|
if !has_key(dict, ns)
|
||||||
|
let dict[ns] = {}
|
||||||
|
endif
|
||||||
|
if type(dict[ns]) == dict_type
|
||||||
|
let dict = dict[ns]
|
||||||
|
else
|
||||||
|
unlet dict
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
if exists('dict')
|
||||||
|
call extend(dict, self._import(name))
|
||||||
|
endif
|
||||||
|
unlet arg
|
||||||
|
endfor
|
||||||
|
return self
|
||||||
|
endfunction
|
||||||
|
let s:Vital.load = s:_function('s:load')
|
||||||
|
|
||||||
|
function! s:unload() abort dict
|
||||||
|
let s:loaded = {}
|
||||||
|
let s:cache_sid = {}
|
||||||
|
unlet! s:vital_files
|
||||||
|
endfunction
|
||||||
|
let s:Vital.unload = s:_function('s:unload')
|
||||||
|
|
||||||
|
function! s:exists(name) abort dict
|
||||||
|
if a:name !~# '\v^\u\w*%(\.\u\w*)*$'
|
||||||
|
throw 'vital: Invalid module name: ' . a:name
|
||||||
|
endif
|
||||||
|
return s:_module_path(a:name) isnot# ''
|
||||||
|
endfunction
|
||||||
|
let s:Vital.exists = s:_function('s:exists')
|
||||||
|
|
||||||
|
function! s:search(pattern) abort dict
|
||||||
|
let paths = s:_extract_files(a:pattern, self.vital_files())
|
||||||
|
let modules = sort(map(paths, 's:_file2module(v:val)'))
|
||||||
|
return s:_uniq(modules)
|
||||||
|
endfunction
|
||||||
|
let s:Vital.search = s:_function('s:search')
|
||||||
|
|
||||||
|
function! s:plugin_name() abort dict
|
||||||
|
return self._plugin_name
|
||||||
|
endfunction
|
||||||
|
let s:Vital.plugin_name = s:_function('s:plugin_name')
|
||||||
|
|
||||||
|
function! s:_self_vital_files() abort
|
||||||
|
let builtin = printf('%s/__%s__/', s:vital_base_dir, s:plugin_name)
|
||||||
|
let installed = printf('%s/_%s/', s:vital_base_dir, s:plugin_name)
|
||||||
|
let base = builtin . ',' . installed
|
||||||
|
return split(globpath(base, '**/*.vim', 1), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_global_vital_files() abort
|
||||||
|
let pattern = 'autoload/vital/__*__/**/*.vim'
|
||||||
|
return split(globpath(&runtimepath, pattern, 1), "\n")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_extract_files(pattern, files) abort
|
||||||
|
let tr = {'.': '/', '*': '[^/]*', '**': '.*'}
|
||||||
|
let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g')
|
||||||
|
let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target)
|
||||||
|
return filter(a:files, 'v:val =~# regexp')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_file2module(file) abort
|
||||||
|
let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?')
|
||||||
|
let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$')
|
||||||
|
return join(split(tail, '[\\/]\+'), '.')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" @param {string} name e.g. Data.List
|
||||||
|
function! s:_import(name) abort dict
|
||||||
|
if has_key(s:loaded, a:name)
|
||||||
|
return copy(s:loaded[a:name])
|
||||||
|
endif
|
||||||
|
let module = self._get_module(a:name)
|
||||||
|
if has_key(module, '_vital_created')
|
||||||
|
call module._vital_created(module)
|
||||||
|
endif
|
||||||
|
let export_module = filter(copy(module), 'v:key =~# "^\\a"')
|
||||||
|
" Cache module before calling module.vital_loaded() to avoid cyclic
|
||||||
|
" dependences but remove the cache if module._vital_loaded() fails.
|
||||||
|
" let s:loaded[a:name] = export_module
|
||||||
|
let s:loaded[a:name] = export_module
|
||||||
|
if has_key(module, '_vital_loaded')
|
||||||
|
try
|
||||||
|
call module._vital_loaded(vital#{s:plugin_name}#new())
|
||||||
|
catch
|
||||||
|
unlet s:loaded[a:name]
|
||||||
|
throw 'vital: fail to call ._vital_loaded(): ' . v:exception
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
|
return copy(s:loaded[a:name])
|
||||||
|
endfunction
|
||||||
|
let s:Vital._import = s:_function('s:_import')
|
||||||
|
|
||||||
|
" s:_get_module() returns module object wihch has all script local functions.
|
||||||
|
function! s:_get_module(name) abort dict
|
||||||
|
let funcname = s:_import_func_name(self.plugin_name(), a:name)
|
||||||
|
try
|
||||||
|
return call(funcname, [])
|
||||||
|
catch /^Vim\%((\a\+)\)\?:E117/
|
||||||
|
return s:_get_builtin_module(a:name)
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_get_builtin_module(name) abort
|
||||||
|
return s:sid2sfuncs(s:_module_sid(a:name))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if s:is_vital_vim
|
||||||
|
" For vital.vim, we can use s:_get_builtin_module directly
|
||||||
|
let s:Vital._get_module = s:_function('s:_get_builtin_module')
|
||||||
|
else
|
||||||
|
let s:Vital._get_module = s:_function('s:_get_module')
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:_import_func_name(plugin_name, module_name) abort
|
||||||
|
return printf('vital#_%s#%s#import', a:plugin_name, s:_dot_to_sharp(a:module_name))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_module_sid(name) abort
|
||||||
|
let path = s:_module_path(a:name)
|
||||||
|
if !filereadable(path)
|
||||||
|
throw 'vital: module not found: ' . a:name
|
||||||
|
endif
|
||||||
|
let vital_dir = s:is_vital_vim ? '__\w\+__' : printf('_\{1,2}%s\%%(__\)\?', s:plugin_name)
|
||||||
|
let base = join([vital_dir, ''], '[/\\]\+')
|
||||||
|
let p = base . substitute('' . a:name, '\.', '[/\\\\]\\+', 'g')
|
||||||
|
let sid = s:_sid(path, p)
|
||||||
|
if !sid
|
||||||
|
call s:_source(path)
|
||||||
|
let sid = s:_sid(path, p)
|
||||||
|
if !sid
|
||||||
|
throw printf('vital: cannot get <SID> from path: %s', path)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return sid
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_module_path(name) abort
|
||||||
|
return get(s:_extract_files(a:name, s:vital_files()), 0, '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_module_sid_base_dir() abort
|
||||||
|
return s:is_vital_vim ? &rtp : s:project_root
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_dot_to_sharp(name) abort
|
||||||
|
return substitute(a:name, '\.', '#', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:_source(path) abort
|
||||||
|
execute 'source' fnameescape(a:path)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" @vimlint(EVL102, 1, l:_)
|
||||||
|
" @vimlint(EVL102, 1, l:__)
|
||||||
|
function! s:_sid(path, filter_pattern) abort
|
||||||
|
let unified_path = s:_unify_path(a:path)
|
||||||
|
if has_key(s:cache_sid, unified_path)
|
||||||
|
return s:cache_sid[unified_path]
|
||||||
|
endif
|
||||||
|
for line in filter(split(s:_execute(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern')
|
||||||
|
let [_, sid, path; __] = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$')
|
||||||
|
if s:_unify_path(path) is# unified_path
|
||||||
|
let s:cache_sid[unified_path] = sid
|
||||||
|
return s:cache_sid[unified_path]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" We want to use a execute() builtin function instead of s:_execute(),
|
||||||
|
" however there is a bug in execute().
|
||||||
|
" execute() returns empty string when it is called in
|
||||||
|
" completion function of user defined ex command.
|
||||||
|
" https://github.com/vim-jp/issues/issues/1129
|
||||||
|
function! s:_execute(cmd) abort
|
||||||
|
let [save_verbose, save_verbosefile] = [&verbose, &verbosefile]
|
||||||
|
set verbose=0 verbosefile=
|
||||||
|
redir => res
|
||||||
|
silent! execute a:cmd
|
||||||
|
redir END
|
||||||
|
let [&verbose, &verbosefile] = [save_verbose, save_verbosefile]
|
||||||
|
return res
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if filereadable(expand('<sfile>:r') . '.VIM') " is case-insensitive or not
|
||||||
|
let s:_unify_path_cache = {}
|
||||||
|
" resolve() is slow, so we cache results.
|
||||||
|
" Note: On windows, vim can't expand path names from 8.3 formats.
|
||||||
|
" So if getting full path via <sfile> and $HOME was set as 8.3 format,
|
||||||
|
" vital load duplicated scripts. Below's :~ avoid this issue.
|
||||||
|
function! s:_unify_path(path) abort
|
||||||
|
if has_key(s:_unify_path_cache, a:path)
|
||||||
|
return s:_unify_path_cache[a:path]
|
||||||
|
endif
|
||||||
|
let value = tolower(fnamemodify(resolve(fnamemodify(
|
||||||
|
\ a:path, ':p')), ':~:gs?[\\/]?/?'))
|
||||||
|
let s:_unify_path_cache[a:path] = value
|
||||||
|
return value
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:_unify_path(path) abort
|
||||||
|
return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?'))
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
" copied and modified from Vim.ScriptLocal
|
||||||
|
let s:SNR = join(map(range(len("\<SNR>")), '"[\\x" . printf("%0x", char2nr("\<SNR>"[v:val])) . "]"'), '')
|
||||||
|
function! s:sid2sfuncs(sid) abort
|
||||||
|
let fs = split(s:_execute(printf(':function /^%s%s_', s:SNR, a:sid)), "\n")
|
||||||
|
let r = {}
|
||||||
|
let pattern = printf('\m^function\s<SNR>%d_\zs\w\{-}\ze(', a:sid)
|
||||||
|
for fname in map(fs, 'matchstr(v:val, pattern)')
|
||||||
|
let r[fname] = function(s:_sfuncname(a:sid, fname))
|
||||||
|
endfor
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
"" Return funcname of script local functions with SID
|
||||||
|
function! s:_sfuncname(sid, funcname) abort
|
||||||
|
return printf('<SNR>%s_%s', a:sid, a:funcname)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if exists('*uniq')
|
||||||
|
function! s:_uniq(list) abort
|
||||||
|
return uniq(a:list)
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:_uniq(list) abort
|
||||||
|
let i = len(a:list) - 1
|
||||||
|
while 0 < i
|
||||||
|
if a:list[i] ==# a:list[i - 1]
|
||||||
|
call remove(a:list, i)
|
||||||
|
endif
|
||||||
|
let i -= 1
|
||||||
|
endwhile
|
||||||
|
return a:list
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
10
autoload/vital/crystal.vital
Normal file
10
autoload/vital/crystal.vital
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'crystal') == -1
|
||||||
|
|
||||||
|
crystal
|
||||||
|
bee84ae23effb0510137ad177e98c94d8b3657a6
|
||||||
|
|
||||||
|
Process
|
||||||
|
Web.JSON
|
||||||
|
ColorEcho
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -62,7 +62,7 @@ let charset = [
|
|||||||
\ 'windows-1256', 'windows-1257', 'windows-1258', 'TIS-620', ]
|
\ 'windows-1256', 'windows-1257', 'windows-1258', 'TIS-620', ]
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
let autofill_tokens = ['on', 'off', 'name', 'honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix', 'nickname', 'username', 'new-password', 'current-password', 'organization-title', 'organization', 'street-address', 'address-line1', 'address-line2', 'address-line3', 'address-level4', 'address-level3', 'address-level2', 'address-level1', 'country', 'country-name', 'postal-code', 'cc-name', 'cc-given-name', 'cc-additional-name', 'cc-family-name', 'cc-number', 'cc-exp', 'cc-exp-month', 'cc-exp-year', 'cc-csc', 'cc-type', 'transaction-currency', 'transaction-amount', 'language', 'bday', 'bday-day', 'bday-month', 'bday-year', 'sex', 'url', 'photo']
|
let autofill_tokens = ['on', 'off', 'name', 'honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix', 'nickname', 'organization-title', 'username', 'new-password', 'current-password', 'organization', 'street-address', 'address-line1', 'address-line2', 'address-line3', 'address-level4', 'address-level3', 'address-level2', 'address-level1', 'country', 'country-name', 'postal-code', 'cc-name', 'cc-given-name', 'cc-additional-name', 'cc-family-name', 'cc-number', 'cc-exp', 'cc-exp-month', 'cc-exp-year', 'cc-csc', 'cc-type', 'transaction-currency', 'transaction-amount', 'language', 'bday', 'bday-day', 'bday-month', 'bday-year', 'sex', 'url', 'photo', 'tel', 'tel-country-code', 'tel-national', 'tel-area-code', 'tel-local', 'tel-local-prefix', 'tel-local-suffix', 'tel-extension', 'email', 'impp']
|
||||||
|
|
||||||
" Attributes_and_Settings: {{{
|
" Attributes_and_Settings: {{{
|
||||||
let core_attributes = {'accesskey': [], 'class': [], 'contenteditable': ['true', 'false', ''], 'contextmenu': [], 'dir': ['ltr', 'rtl'], 'draggable': ['true', 'false'], 'hidden': ['hidden', ''], 'id': [], 'is': [], 'lang': lang_tag, 'spellcheck': ['true', 'false', ''], 'style': [], 'tabindex': [], 'title': []}
|
let core_attributes = {'accesskey': [], 'class': [], 'contenteditable': ['true', 'false', ''], 'contextmenu': [], 'dir': ['ltr', 'rtl'], 'draggable': ['true', 'false'], 'hidden': ['hidden', ''], 'id': [], 'is': [], 'lang': lang_tag, 'spellcheck': ['true', 'false', ''], 'style': [], 'tabindex': [], 'title': []}
|
||||||
@@ -82,6 +82,7 @@ let attributes_value = {
|
|||||||
\ 'action': ['URL', ''],
|
\ 'action': ['URL', ''],
|
||||||
\ 'allowfullscreen': ['Bool', ''],
|
\ 'allowfullscreen': ['Bool', ''],
|
||||||
\ 'allowpaymentrequest': ['Bool', ''],
|
\ 'allowpaymentrequest': ['Bool', ''],
|
||||||
|
\ 'allowpresentation': ['Bool', ''],
|
||||||
\ 'allowusermedia': ['Bool', ''],
|
\ 'allowusermedia': ['Bool', ''],
|
||||||
\ 'alt': ['Text', ''],
|
\ 'alt': ['Text', ''],
|
||||||
\ 'async': ['Bool', ''],
|
\ 'async': ['Bool', ''],
|
||||||
@@ -579,7 +580,7 @@ let g:xmldata_html5 = {
|
|||||||
\ ],
|
\ ],
|
||||||
\ 'iframe': [
|
\ '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'], 'allowfullscreen': [], 'allowpaymentrequest': [], 'allowusermedia': []})
|
\ 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': [], 'allowpresentation': [], 'allowusermedia': []})
|
||||||
\ ],
|
\ ],
|
||||||
\ 'img': [
|
\ 'img': [
|
||||||
\ [],
|
\ [],
|
||||||
@@ -615,7 +616,7 @@ let g:xmldata_html5 = {
|
|||||||
\ ],
|
\ ],
|
||||||
\ 'link': [
|
\ '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'], 'crossorigin': crossorigin, 'preload': ['preload', ''], 'prefetch': ['prefetch', '']})
|
\ 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', ''], 'as': ['report', 'document', 'document', 'object', 'embed', 'audio', 'font', 'image', 'audioworklet', 'paintworklet', 'script', 'serviceworker', 'sharedworker', 'worker', 'style', 'track', 'video', 'image', 'manifest', 'xslt', 'fetch', '']})
|
||||||
\ ],
|
\ ],
|
||||||
\ 'main': [
|
\ 'main': [
|
||||||
\ flow_elements + ['style'],
|
\ flow_elements + ['style'],
|
||||||
|
|||||||
17
build
17
build
@@ -5,7 +5,7 @@ set -E
|
|||||||
DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin"
|
DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin"
|
||||||
DIRS_BASIC="syntax compiler indent after/syntax after/indent"
|
DIRS_BASIC="syntax compiler indent after/syntax after/indent"
|
||||||
DIRS_ALL="syntax indent compiler autoload ftplugin after"
|
DIRS_ALL="syntax indent compiler autoload ftplugin after"
|
||||||
DIRS_SYNTAX="syntax after/syntax"
|
DIRS_SYNTAX="syntax indent after/syntax after/indent"
|
||||||
DIRS_JAVASCRIPT="${DIRS} extras"
|
DIRS_JAVASCRIPT="${DIRS} extras"
|
||||||
DIRS_RM="$DIRS_JAVASCRIPT"
|
DIRS_RM="$DIRS_JAVASCRIPT"
|
||||||
|
|
||||||
@@ -52,6 +52,13 @@ extract() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
output "${subdirs##, })\n"
|
||||||
|
|
||||||
|
if (echo "julia coffee-script elixir fish git plantuml scala swift" | fgrep -q "$name"); then
|
||||||
|
echo "Skipping ftdetect installation of $name"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
for f in ${dir}/ftdetect/*; do
|
for f in ${dir}/ftdetect/*; do
|
||||||
(
|
(
|
||||||
echo "augroup filetypedetect";
|
echo "augroup filetypedetect";
|
||||||
@@ -62,7 +69,6 @@ extract() {
|
|||||||
) >> tmp/polyglot.vim;
|
) >> tmp/polyglot.vim;
|
||||||
done
|
done
|
||||||
|
|
||||||
output "${subdirs##, })\n"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
mv tmp/polyglot.vim ftdetect/
|
mv tmp/polyglot.vim ftdetect/
|
||||||
@@ -80,7 +86,7 @@ extract() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copy_dir() {
|
copy_dir() {
|
||||||
for file in $(find "$1/$2" -name '*.vim'); do
|
for file in $(find "$1/$2" -name '*.vim' -o -name '*.vital'); do
|
||||||
file_path="$(dirname "${file##$1/}")"
|
file_path="$(dirname "${file##$1/}")"
|
||||||
mkdir -p "$file_path"
|
mkdir -p "$file_path"
|
||||||
touch "$file_path/$(basename "$file")"
|
touch "$file_path/$(basename "$file")"
|
||||||
@@ -118,6 +124,7 @@ PACKS="
|
|||||||
c++11:octol/vim-cpp-enhanced-highlight
|
c++11:octol/vim-cpp-enhanced-highlight
|
||||||
c/c++:vim-jp/vim-cpp
|
c/c++:vim-jp/vim-cpp
|
||||||
caddyfile:isobit/vim-caddyfile
|
caddyfile:isobit/vim-caddyfile
|
||||||
|
carp:hellerve/carp-vim
|
||||||
cjsx:mtscout6/vim-cjsx
|
cjsx:mtscout6/vim-cjsx
|
||||||
clojure:guns/vim-clojure-static
|
clojure:guns/vim-clojure-static
|
||||||
cmake:pboettch/vim-cmake-syntax
|
cmake:pboettch/vim-cmake-syntax
|
||||||
@@ -151,6 +158,7 @@ PACKS="
|
|||||||
javascript:pangloss/vim-javascript:_JAVASCRIPT
|
javascript:pangloss/vim-javascript:_JAVASCRIPT
|
||||||
jenkins:martinda/Jenkinsfile-vim-syntax
|
jenkins:martinda/Jenkinsfile-vim-syntax
|
||||||
json:elzr/vim-json
|
json:elzr/vim-json
|
||||||
|
json5:GutenYe/json5.vim
|
||||||
jst:briancollins/vim-jst
|
jst:briancollins/vim-jst
|
||||||
jsx:mxw/vim-jsx:_ALL
|
jsx:mxw/vim-jsx:_ALL
|
||||||
julia:JuliaEditorSupport/julia-vim
|
julia:JuliaEditorSupport/julia-vim
|
||||||
@@ -179,8 +187,9 @@ PACKS="
|
|||||||
pug:digitaltoad/vim-pug
|
pug:digitaltoad/vim-pug
|
||||||
puppet:voxpupuli/vim-puppet
|
puppet:voxpupuli/vim-puppet
|
||||||
purescript:purescript-contrib/purescript-vim
|
purescript:purescript-contrib/purescript-vim
|
||||||
python:mitsuhiko/vim-python-combined
|
python:vim-python/python-syntax
|
||||||
python-compiler:aliev/vim-compiler-python
|
python-compiler:aliev/vim-compiler-python
|
||||||
|
python-ident:Vimjas/vim-python-pep8-indent
|
||||||
qml:peterhoeg/vim-qml
|
qml:peterhoeg/vim-qml
|
||||||
r-lang:vim-scripts/R.vim
|
r-lang:vim-scripts/R.vim
|
||||||
racket:wlangstroth/vim-racket
|
racket:wlangstroth/vim-racket
|
||||||
|
|||||||
56
config.vim
56
config.vim
@@ -13,3 +13,59 @@ let g:filetype_euphoria = 'elixir'
|
|||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
let g:python_highlight_all = 1
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
if v:version < 704
|
||||||
|
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
|
||||||
|
" which didn't define b:undo_ftplugin on older Vim versions
|
||||||
|
" (*.jl files are recognized as lisp)
|
||||||
|
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
|
||||||
|
endif
|
||||||
|
|
||||||
|
autocmd BufRead,BufNewFile *.jl set filetype=julia
|
||||||
|
|
||||||
|
" coffeescript
|
||||||
|
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *Cakefile set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *._coffee set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *.litcoffee set filetype=litcoffee
|
||||||
|
autocmd BufNewFile,BufRead *.coffee.md set filetype=litcoffee
|
||||||
|
|
||||||
|
|
||||||
|
" elixir
|
||||||
|
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
|
||||||
|
au BufRead,BufNewFile *.eex call s:setf('eelixir')
|
||||||
|
|
||||||
|
" fish
|
||||||
|
autocmd BufRead,BufNewFile *.fish setfiletype fish
|
||||||
|
autocmd BufRead fish_funced_*_*.fish call search('^$')
|
||||||
|
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
|
||||||
|
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
|
||||||
|
autocmd BufNewFile ~/.config/fish/functions/*.fish
|
||||||
|
\ call append(0, ['function '.expand('%:t:r'),
|
||||||
|
\'',
|
||||||
|
\'end']) |
|
||||||
|
\ 2
|
||||||
|
|
||||||
|
" git
|
||||||
|
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit
|
||||||
|
autocmd BufNewFile,BufRead *.git/config,.gitconfig,gitconfig,.gitmodules set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead */.config/git/config set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead *.git/modules/**/config set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead git-rebase-todo set ft=gitrebase
|
||||||
|
autocmd BufNewFile,BufRead .gitsendemail.* set ft=gitsendemail
|
||||||
|
|
||||||
|
" plantuml
|
||||||
|
autocmd BufRead,BufNewFile *.pu,*.uml,*.plantuml setfiletype plantuml | set filetype=plantuml
|
||||||
|
|
||||||
|
" scala
|
||||||
|
au BufRead,BufNewFile *.scala,*.sc set filetype=scala
|
||||||
|
au BufRead,BufNewFile *.sbt setfiletype sbt.scala
|
||||||
|
|
||||||
|
" swift
|
||||||
|
autocmd BufNewFile,BufRead *.swift set filetype=swift
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,62 @@ let g:filetype_euphoria = 'elixir'
|
|||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
let g:python_highlight_all = 1
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
if v:version < 704
|
||||||
|
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
|
||||||
|
" which didn't define b:undo_ftplugin on older Vim versions
|
||||||
|
" (*.jl files are recognized as lisp)
|
||||||
|
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
|
||||||
|
endif
|
||||||
|
|
||||||
|
autocmd BufRead,BufNewFile *.jl set filetype=julia
|
||||||
|
|
||||||
|
" coffeescript
|
||||||
|
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *Cakefile set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *._coffee set filetype=coffee
|
||||||
|
autocmd BufNewFile,BufRead *.litcoffee set filetype=litcoffee
|
||||||
|
autocmd BufNewFile,BufRead *.coffee.md set filetype=litcoffee
|
||||||
|
|
||||||
|
|
||||||
|
" elixir
|
||||||
|
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
|
||||||
|
au BufRead,BufNewFile *.eex call s:setf('eelixir')
|
||||||
|
|
||||||
|
" fish
|
||||||
|
autocmd BufRead,BufNewFile *.fish setfiletype fish
|
||||||
|
autocmd BufRead fish_funced_*_*.fish call search('^$')
|
||||||
|
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
|
||||||
|
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
|
||||||
|
autocmd BufNewFile ~/.config/fish/functions/*.fish
|
||||||
|
\ call append(0, ['function '.expand('%:t:r'),
|
||||||
|
\'',
|
||||||
|
\'end']) |
|
||||||
|
\ 2
|
||||||
|
|
||||||
|
" git
|
||||||
|
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit
|
||||||
|
autocmd BufNewFile,BufRead *.git/config,.gitconfig,gitconfig,.gitmodules set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead */.config/git/config set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead *.git/modules/**/config set ft=gitconfig
|
||||||
|
autocmd BufNewFile,BufRead git-rebase-todo set ft=gitrebase
|
||||||
|
autocmd BufNewFile,BufRead .gitsendemail.* set ft=gitsendemail
|
||||||
|
|
||||||
|
" plantuml
|
||||||
|
autocmd BufRead,BufNewFile *.pu,*.uml,*.plantuml setfiletype plantuml | set filetype=plantuml
|
||||||
|
|
||||||
|
" scala
|
||||||
|
au BufRead,BufNewFile *.scala,*.sc set filetype=scala
|
||||||
|
au BufRead,BufNewFile *.sbt setfiletype sbt.scala
|
||||||
|
|
||||||
|
" swift
|
||||||
|
autocmd BufNewFile,BufRead *.swift set filetype=swift
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" apiblueprint:sheerun/apiblueprint.vim
|
" apiblueprint:sheerun/apiblueprint.vim
|
||||||
autocmd BufReadPost,BufNewFile *.apib set filetype=apiblueprint
|
autocmd BufReadPost,BufNewFile *.apib set filetype=apiblueprint
|
||||||
@@ -82,6 +138,11 @@ augroup filetypedetect
|
|||||||
au BufNewFile,BufRead Caddyfile set ft=caddyfile
|
au BufNewFile,BufRead Caddyfile set ft=caddyfile
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
" carp:hellerve/carp-vim
|
||||||
|
au BufRead,BufNewFile *.carp set filetype=carp
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" cjsx:mtscout6/vim-cjsx
|
" cjsx:mtscout6/vim-cjsx
|
||||||
augroup CJSX
|
augroup CJSX
|
||||||
@@ -99,39 +160,6 @@ augroup filetypedetect
|
|||||||
" cmake:pboettch/vim-cmake-syntax
|
" cmake:pboettch/vim-cmake-syntax
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" coffee-script:kchmck/vim-coffee-script
|
|
||||||
" Language: CoffeeScript
|
|
||||||
" Maintainer: Mick Koch <mick@kochm.co>
|
|
||||||
" URL: http://github.com/kchmck/vim-coffee-script
|
|
||||||
" License: WTFPL
|
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead *.coffee set filetype=coffee
|
|
||||||
autocmd BufNewFile,BufRead *Cakefile set filetype=coffee
|
|
||||||
autocmd BufNewFile,BufRead *.coffeekup,*.ck set filetype=coffee
|
|
||||||
autocmd BufNewFile,BufRead *._coffee set filetype=coffee
|
|
||||||
|
|
||||||
function! s:DetectCoffee()
|
|
||||||
if getline(1) =~ '^#!.*\<coffee\>'
|
|
||||||
set filetype=coffee
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead * call s:DetectCoffee()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" coffee-script:kchmck/vim-coffee-script
|
|
||||||
" Language: Literate CoffeeScript
|
|
||||||
" Maintainer: Michael Smith <michael@diglumi.com>
|
|
||||||
" URL: https://github.com/mintplant/vim-literate-coffeescript
|
|
||||||
" License: MIT
|
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead *.litcoffee set filetype=litcoffee
|
|
||||||
autocmd BufNewFile,BufRead *.coffee.md set filetype=litcoffee
|
|
||||||
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" cryptol:victoredwardocallaghan/cryptol.vim
|
" cryptol:victoredwardocallaghan/cryptol.vim
|
||||||
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
|
" Copyright © 2013 Edward O'Callaghan. All Rights Reserved.
|
||||||
@@ -173,23 +201,6 @@ augroup filetypedetect
|
|||||||
" dockerfile:docker/docker::/contrib/syntax/vim/
|
" dockerfile:docker/docker::/contrib/syntax/vim/
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" elixir:elixir-lang/vim-elixir
|
|
||||||
au BufRead,BufNewFile *.ex,*.exs call s:setf('elixir')
|
|
||||||
au BufRead,BufNewFile *.eex call s:setf('eelixir')
|
|
||||||
au BufRead,BufNewFile * call s:DetectElixir()
|
|
||||||
|
|
||||||
function! s:setf(filetype) abort
|
|
||||||
let &filetype = a:filetype
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:DetectElixir()
|
|
||||||
if getline(1) =~ '^#!.*\<elixir\>'
|
|
||||||
call s:setf('elixir')
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" elm:ElmCast/elm-vim
|
" elm:ElmCast/elm-vim
|
||||||
" detection for Elm (http://elm-lang.org/)
|
" detection for Elm (http://elm-lang.org/)
|
||||||
@@ -237,34 +248,7 @@ augroup END
|
|||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" erlang:vim-erlang/vim-erlang-runtime
|
" erlang:vim-erlang/vim-erlang-runtime
|
||||||
au BufNewFile,BufRead *.erl,*.hrl,rebar.config,*.app,*.app.src,*.yaws,*.xrl set ft=erlang
|
au BufNewFile,BufRead *.erl,*.hrl,rebar.config,*.app,*.app.src,*.yaws,*.xrl,*.escript set ft=erlang
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" fish:dag/vim-fish
|
|
||||||
autocmd BufRead,BufNewFile *.fish setfiletype fish
|
|
||||||
|
|
||||||
" Detect fish scripts by the shebang line.
|
|
||||||
autocmd BufRead *
|
|
||||||
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
|
|
||||||
\ setlocal filetype=fish |
|
|
||||||
\ endif
|
|
||||||
|
|
||||||
" Move cursor to first empty line when using funced.
|
|
||||||
autocmd BufRead fish_funced_*_*.fish call search('^$')
|
|
||||||
|
|
||||||
" Fish histories are YAML documents.
|
|
||||||
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
|
|
||||||
|
|
||||||
" Universal variable storages should not be hand edited.
|
|
||||||
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
|
|
||||||
|
|
||||||
" Mimic `funced` when manually creating functions.
|
|
||||||
autocmd BufNewFile ~/.config/fish/functions/*.fish
|
|
||||||
\ call append(0, ['function '.expand('%:t:r'),
|
|
||||||
\'',
|
|
||||||
\'end']) |
|
|
||||||
\ 2
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
@@ -273,31 +257,6 @@ augroup filetypedetect
|
|||||||
autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx set filetype=fsharp
|
autocmd BufNewFile,BufRead *.fs,*.fsi,*.fsx set filetype=fsharp
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" git:tpope/vim-git
|
|
||||||
" Git
|
|
||||||
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit
|
|
||||||
autocmd BufNewFile,BufRead *.git/config,.gitconfig,gitconfig,.gitmodules set ft=gitconfig
|
|
||||||
autocmd BufNewFile,BufRead */.config/git/config set ft=gitconfig
|
|
||||||
autocmd BufNewFile,BufRead *.git/modules/**/config set ft=gitconfig
|
|
||||||
autocmd BufNewFile,BufRead git-rebase-todo set ft=gitrebase
|
|
||||||
autocmd BufNewFile,BufRead .gitsendemail.* set ft=gitsendemail
|
|
||||||
autocmd BufNewFile,BufRead *.git/**
|
|
||||||
\ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
|
|
||||||
\ set ft=git |
|
|
||||||
\ endif
|
|
||||||
|
|
||||||
" This logic really belongs in scripts.vim
|
|
||||||
autocmd BufNewFile,BufRead,StdinReadPost *
|
|
||||||
\ if getline(1) =~ '^\(commit\|tree\|object\) \x\{40\}\>\|^tag \S\+$' |
|
|
||||||
\ set ft=git |
|
|
||||||
\ endif
|
|
||||||
autocmd BufNewFile,BufRead *
|
|
||||||
\ if getline(1) =~ '^From \x\{40\} Mon Sep 17 00:00:00 2001$' |
|
|
||||||
\ set filetype=gitsendemail |
|
|
||||||
\ endif
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" gmpl:maelvalais/gmpl.vim
|
" gmpl:maelvalais/gmpl.vim
|
||||||
au BufRead,BufNewFile *.mod set filetype=gmpl
|
au BufRead,BufNewFile *.mod set filetype=gmpl
|
||||||
@@ -321,6 +280,8 @@ augroup END
|
|||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" go:fatih/vim-go:_BASIC
|
" go:fatih/vim-go:_BASIC
|
||||||
|
" vint: -ProhibitAutocmdWithNoGroup
|
||||||
|
|
||||||
" We take care to preserve the user's fileencodings and fileformats,
|
" We take care to preserve the user's fileencodings and fileformats,
|
||||||
" because those settings are global (not buffer local), yet we want
|
" because those settings are global (not buffer local), yet we want
|
||||||
" to override them for loading Go files, which are defined to be UTF-8.
|
" to override them for loading Go files, which are defined to be UTF-8.
|
||||||
@@ -341,18 +302,16 @@ function! s:gofiletype_post()
|
|||||||
let &g:fileencodings = s:current_fileencodings
|
let &g:fileencodings = s:current_fileencodings
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
augroup vim-go-filetype
|
" Note: should not use augroup in ftdetect (see :help ftdetect)
|
||||||
autocmd!
|
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
|
||||||
au BufNewFile *.go setfiletype go | setlocal fileencoding=utf-8 fileformat=unix
|
au BufRead *.go call s:gofiletype_pre("go")
|
||||||
au BufRead *.go call s:gofiletype_pre("go")
|
au BufReadPost *.go call s:gofiletype_post()
|
||||||
au BufReadPost *.go call s:gofiletype_post()
|
|
||||||
|
|
||||||
au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix
|
au BufNewFile *.s setfiletype asm | setlocal fileencoding=utf-8 fileformat=unix
|
||||||
au BufRead *.s call s:gofiletype_pre("asm")
|
au BufRead *.s call s:gofiletype_pre("asm")
|
||||||
au BufReadPost *.s call s:gofiletype_post()
|
au BufReadPost *.s call s:gofiletype_post()
|
||||||
|
|
||||||
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
|
au BufRead,BufNewFile *.tmpl set filetype=gohtmltmpl
|
||||||
augroup end
|
|
||||||
|
|
||||||
" vim: sw=2 ts=2 et
|
" vim: sw=2 ts=2 et
|
||||||
augroup END
|
augroup END
|
||||||
@@ -437,11 +396,17 @@ augroup END
|
|||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" json:elzr/vim-json
|
" json:elzr/vim-json
|
||||||
autocmd BufNewFile,BufRead *.json setlocal filetype=json
|
autocmd BufNewFile,BufRead *.json setlocal filetype=json
|
||||||
|
autocmd BufNewFile,BufRead *.jsonl setlocal filetype=json
|
||||||
autocmd BufNewFile,BufRead *.jsonp setlocal filetype=json
|
autocmd BufNewFile,BufRead *.jsonp setlocal filetype=json
|
||||||
autocmd BufNewFile,BufRead *.geojson setlocal filetype=json
|
autocmd BufNewFile,BufRead *.geojson setlocal filetype=json
|
||||||
autocmd BufNewFile,BufRead *.template setlocal filetype=json
|
autocmd BufNewFile,BufRead *.template setlocal filetype=json
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
" json5:GutenYe/json5.vim
|
||||||
|
au BufNewFile,BufRead *.json5 setfiletype json5
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" jst:briancollins/vim-jst
|
" jst:briancollins/vim-jst
|
||||||
au BufNewFile,BufRead *.ejs set filetype=jst
|
au BufNewFile,BufRead *.ejs set filetype=jst
|
||||||
@@ -492,31 +457,6 @@ autocmd BufNewFile,BufRead *.js
|
|||||||
\ if <SID>EnableJSX() | set filetype=javascript.jsx | endif
|
\ if <SID>EnableJSX() | set filetype=javascript.jsx | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" julia:JuliaEditorSupport/julia-vim
|
|
||||||
if v:version < 704
|
|
||||||
" NOTE: this line fixes an issue with the default system-wide lisp ftplugin
|
|
||||||
" which didn't define b:undo_ftplugin on older Vim versions
|
|
||||||
" (*.jl files are recognized as lisp)
|
|
||||||
autocmd BufRead,BufNewFile *.jl let b:undo_ftplugin = "setlocal comments< define< formatoptions< iskeyword< lisp<"
|
|
||||||
endif
|
|
||||||
|
|
||||||
autocmd BufRead,BufNewFile *.jl set filetype=julia
|
|
||||||
|
|
||||||
autocmd FileType * call LaTeXtoUnicode#Refresh()
|
|
||||||
autocmd BufEnter * call LaTeXtoUnicode#Refresh()
|
|
||||||
|
|
||||||
" This autocommand is used to postpone the first initialization of LaTeXtoUnicode as much as possible,
|
|
||||||
" by calling LaTeXtoUnicode#SetTab amd LaTeXtoUnicode#SetAutoSub only at InsertEnter or later
|
|
||||||
function! s:L2UTrigger()
|
|
||||||
augroup L2UInit
|
|
||||||
autocmd!
|
|
||||||
autocmd InsertEnter * let g:did_insert_enter = 1 | call LaTeXtoUnicode#Init(0)
|
|
||||||
augroup END
|
|
||||||
endfunction
|
|
||||||
autocmd BufEnter * call s:L2UTrigger()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" kotlin:udalov/kotlin-vim
|
" kotlin:udalov/kotlin-vim
|
||||||
autocmd BufNewFile,BufRead *.kt setfiletype kotlin
|
autocmd BufNewFile,BufRead *.kt setfiletype kotlin
|
||||||
@@ -693,16 +633,6 @@ augroup filetypedetect
|
|||||||
" php:StanAngeloff/php.vim
|
" php:StanAngeloff/php.vim
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" plantuml:aklt/plantuml-syntax
|
|
||||||
if did_filetype()
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
autocmd BufRead,BufNewFile * :if getline(1) =~ '^.*startuml.*$'| setfiletype plantuml | set filetype=plantuml | endif
|
|
||||||
autocmd BufRead,BufNewFile *.pu,*.uml,*.plantuml setfiletype plantuml | set filetype=plantuml
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" powershell:PProvost/vim-ps1
|
" powershell:PProvost/vim-ps1
|
||||||
" Vim ftdetect plugin file
|
" Vim ftdetect plugin file
|
||||||
@@ -770,7 +700,7 @@ au FileType purescript let &l:commentstring='{--%s--}'
|
|||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" python:mitsuhiko/vim-python-combined
|
" python:vim-python/python-syntax
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
@@ -783,6 +713,10 @@ augroup filetypedetect
|
|||||||
autocmd FileType python compiler python
|
autocmd FileType python compiler python
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
" python-ident:Vimjas/vim-python-pep8-indent
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" qml:peterhoeg/vim-qml
|
" qml:peterhoeg/vim-qml
|
||||||
autocmd BufRead,BufNewFile *.qml setfiletype qml
|
autocmd BufRead,BufNewFile *.qml setfiletype qml
|
||||||
@@ -938,21 +872,6 @@ augroup filetypedetect
|
|||||||
au BufRead,BufNewFile *.sbt set filetype=sbt.scala
|
au BufRead,BufNewFile *.sbt set filetype=sbt.scala
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" scala:derekwyatt/vim-scala
|
|
||||||
fun! s:DetectScala()
|
|
||||||
if getline(1) =~# '^#!\(/usr\)\?/bin/env\s\+scalas\?'
|
|
||||||
set filetype=scala
|
|
||||||
endif
|
|
||||||
endfun
|
|
||||||
|
|
||||||
au BufRead,BufNewFile *.scala,*.sc set filetype=scala
|
|
||||||
au BufRead,BufNewFile * call s:DetectScala()
|
|
||||||
|
|
||||||
" Install vim-sbt for additional syntax highlighting.
|
|
||||||
au BufRead,BufNewFile *.sbt setfiletype sbt.scala
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" scss:cakebaker/scss-syntax.vim
|
" scss:cakebaker/scss-syntax.vim
|
||||||
au BufRead,BufNewFile *.scss setfiletype scss
|
au BufRead,BufNewFile *.scss setfiletype scss
|
||||||
@@ -981,22 +900,6 @@ autocmd BufNewFile,BufReadPost *.styl set filetype=stylus
|
|||||||
autocmd BufNewFile,BufReadPost *.stylus set filetype=stylus
|
autocmd BufNewFile,BufReadPost *.stylus set filetype=stylus
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
|
||||||
" swift:keith/swift.vim
|
|
||||||
autocmd BufNewFile,BufRead *.swift set filetype=swift
|
|
||||||
autocmd BufRead * call s:Swift()
|
|
||||||
function! s:Swift()
|
|
||||||
if !empty(&filetype)
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let line = getline(1)
|
|
||||||
if line =~ "^#!.*swift"
|
|
||||||
setfiletype swift
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" sxhkd:baskerville/vim-sxhkdrc
|
" sxhkd:baskerville/vim-sxhkdrc
|
||||||
if &compatible || v:version < 603
|
if &compatible || v:version < 603
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ansible') == -1
|
|||||||
if exists('+regexpengine') && ('®expengine' == 0)
|
if exists('+regexpengine') && ('®expengine' == 0)
|
||||||
setlocal regexpengine=1
|
setlocal regexpengine=1
|
||||||
endif
|
endif
|
||||||
set path+=./../templates,./../files
|
set path+=./../templates,./../files,templates,files
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -50,18 +50,17 @@ command! -buffer -nargs=* CrystalHierarchy echo crystal_lang#type_hierarchy(expa
|
|||||||
command! -buffer -nargs=? CrystalSpecSwitch call crystal_lang#switch_spec_file(<f-args>)
|
command! -buffer -nargs=? CrystalSpecSwitch call crystal_lang#switch_spec_file(<f-args>)
|
||||||
command! -buffer -nargs=? CrystalSpecRunAll call crystal_lang#run_all_spec(<f-args>)
|
command! -buffer -nargs=? CrystalSpecRunAll call crystal_lang#run_all_spec(<f-args>)
|
||||||
command! -buffer -nargs=? CrystalSpecRunCurrent call crystal_lang#run_current_spec(<f-args>)
|
command! -buffer -nargs=? CrystalSpecRunCurrent call crystal_lang#run_current_spec(<f-args>)
|
||||||
command! -buffer -nargs=* -bar CrystalFormat call crystal_lang#format(<q-args>)
|
command! -buffer -nargs=* -bar CrystalFormat call crystal_lang#format(<q-args>, 0)
|
||||||
|
|
||||||
nnoremap <Plug>(crystal-jump-to-definition) :<C-u>CrystalDef<CR>
|
nnoremap <buffer><Plug>(crystal-jump-to-definition) :<C-u>CrystalDef<CR>
|
||||||
nnoremap <Plug>(crystal-show-context) :<C-u>CrystalContext<CR>
|
nnoremap <buffer><Plug>(crystal-show-context) :<C-u>CrystalContext<CR>
|
||||||
nnoremap <Plug>(crystal-spec-switch) :<C-u>CrystalSpecSwitch<CR>
|
nnoremap <buffer><Plug>(crystal-spec-switch) :<C-u>CrystalSpecSwitch<CR>
|
||||||
nnoremap <Plug>(crystal-spec-run-all) :<C-u>CrystalSpecRunAll<CR>
|
nnoremap <buffer><Plug>(crystal-spec-run-all) :<C-u>CrystalSpecRunAll<CR>
|
||||||
nnoremap <Plug>(crystal-spec-run-current) :<C-u>CrystalSpecRunCurrent<CR>
|
nnoremap <buffer><Plug>(crystal-spec-run-current) :<C-u>CrystalSpecRunCurrent<CR>
|
||||||
nnoremap <Plug>(crystal-format) :<C-u>CrystalFormat<CR>
|
nnoremap <buffer><Plug>(crystal-format) :<C-u>CrystalFormat<CR>
|
||||||
|
|
||||||
augroup plugin-ft-crystal
|
augroup plugin-ft-crystal
|
||||||
autocmd!
|
autocmd BufWritePre <buffer> if g:crystal_auto_format | call crystal_lang#format('', 1) | endif
|
||||||
autocmd BufWritePre <buffer> if g:crystal_auto_format | CrystalFormat | endif
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
if get(g:, 'crystal_define_mappings', 1)
|
if get(g:, 'crystal_define_mappings', 1)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
|
||||||
|
|
||||||
if (exists("b:did_ftplugin"))
|
if exists('b:did_ftplugin')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_ftplugin = 1
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
" Matchit support
|
" Matchit support
|
||||||
if exists("loaded_matchit") && !exists("b:match_words")
|
if exists('loaded_matchit') && !exists('b:match_words')
|
||||||
let b:match_ignorecase = 0
|
let b:match_ignorecase = 0
|
||||||
|
|
||||||
let b:match_words = '\:\@<!\<\%(do\|fn\)\:\@!\>' .
|
let b:match_words = '\:\@<!\<\%(do\|fn\)\:\@!\>' .
|
||||||
@@ -32,9 +32,30 @@ let &l:path =
|
|||||||
setlocal includeexpr=elixir#util#get_filename(v:fname)
|
setlocal includeexpr=elixir#util#get_filename(v:fname)
|
||||||
setlocal suffixesadd=.ex,.exs,.eex,.erl,.yrl,.hrl
|
setlocal suffixesadd=.ex,.exs,.eex,.erl,.yrl,.hrl
|
||||||
|
|
||||||
|
if empty(&formatprg)
|
||||||
|
setlocal formatprg=mix\ format\ -
|
||||||
|
endif
|
||||||
|
|
||||||
|
let &l:define = 'def\(macro|guard|delegate\)p'
|
||||||
|
|
||||||
silent! setlocal formatoptions-=t formatoptions+=croqlj
|
silent! setlocal formatoptions-=t formatoptions+=croqlj
|
||||||
|
|
||||||
let b:undo_ftplugin = 'setlocal sw< sts< et< isk< com< cms< path< inex< sua< '.
|
let b:block_begin = '\<\(do$\|fn\>\)'
|
||||||
\ '| unlet! b:match_ignorecase b:match_words'
|
let b:block_end = '\<end\>'
|
||||||
|
|
||||||
|
nnoremap <buffer> <silent> <expr> ]] ':silent keeppatterns /'.b:block_begin.'<CR>'
|
||||||
|
nnoremap <buffer> <silent> <expr> [[ ':silent keeppatterns ?'.b:block_begin.'<CR>'
|
||||||
|
nnoremap <buffer> <silent> <expr> ][ ':silent keeppatterns /'.b:block_end .'<CR>'
|
||||||
|
nnoremap <buffer> <silent> <expr> [] ':silent keeppatterns ?'.b:block_end .'<CR>'
|
||||||
|
|
||||||
|
onoremap <buffer> <silent> <expr> ]] ':silent keeppatterns /'.b:block_begin.'<CR>'
|
||||||
|
onoremap <buffer> <silent> <expr> [[ ':silent keeppatterns ?'.b:block_begin.'<CR>'
|
||||||
|
onoremap <buffer> <silent> <expr> ][ ':silent keeppatterns /'.b:block_end .'<CR>'
|
||||||
|
onoremap <buffer> <silent> <expr> [] ':silent keeppatterns ?'.b:block_end .'<CR>'
|
||||||
|
|
||||||
|
silent! setlocal formatoptions-=t formatoptions+=croqlj
|
||||||
|
|
||||||
|
let b:undo_ftplugin = 'setlocal sw< sts< et< isk< com< cms< path< inex< sua< def<'.
|
||||||
|
\ '| unlet! b:match_ignorecase b:match_words b:block_begin b:block_end'
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
417
ftplugin/latex-box/common.vim
Normal file
417
ftplugin/latex-box/common.vim
Normal file
@@ -0,0 +1,417 @@
|
|||||||
|
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
|
||||||
936
ftplugin/latex-box/complete.vim
Normal file
936
ftplugin/latex-box/complete.vim
Normal file
@@ -0,0 +1,936 @@
|
|||||||
|
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
|
||||||
66
ftplugin/latex-box/findmain.vim
Normal file
66
ftplugin/latex-box/findmain.vim
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
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
|
||||||
382
ftplugin/latex-box/folding.vim
Normal file
382
ftplugin/latex-box/folding.vim
Normal file
@@ -0,0 +1,382 @@
|
|||||||
|
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
|
||||||
558
ftplugin/latex-box/latexmk.vim
Normal file
558
ftplugin/latex-box/latexmk.vim
Normal file
@@ -0,0 +1,558 @@
|
|||||||
|
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
|
||||||
110
ftplugin/latex-box/mappings.vim
Normal file
110
ftplugin/latex-box/mappings.vim
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
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
|
||||||
548
ftplugin/latex-box/motion.vim
Normal file
548
ftplugin/latex-box/motion.vim
Normal file
@@ -0,0 +1,548 @@
|
|||||||
|
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
|
||||||
206
ftplugin/latextoc.vim
Normal file
206
ftplugin/latextoc.vim
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
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
|
||||||
@@ -2,11 +2,13 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vifm') == -1
|
|||||||
|
|
||||||
" Mail file type extension to pick files for attachments via vifm
|
" Mail file type extension to pick files for attachments via vifm
|
||||||
" Maintainer: xaizek <xaizek@posteo.net>
|
" Maintainer: xaizek <xaizek@posteo.net>
|
||||||
" Last Change: January 23, 2016
|
" Last Change: January 02, 2018
|
||||||
|
|
||||||
" Insert attachment picked via vifm after 'Subject' header
|
" Insert attachment picked via vifm after 'Subject' header
|
||||||
function! s:AddMailAttacments()
|
function! s:AddMailAttachments()
|
||||||
" TODO: reduce duplication between this file and plugins/vifm.vim
|
call vifm#globals#Init()
|
||||||
|
|
||||||
|
" XXX: similar code is in plugins/vifm.vim, but it's different in details
|
||||||
let l:listf = tempname()
|
let l:listf = tempname()
|
||||||
|
|
||||||
if !has('nvim')
|
if !has('nvim')
|
||||||
@@ -26,7 +28,7 @@ function! s:AddMailAttacments()
|
|||||||
else
|
else
|
||||||
" Work around handicapped neovim...
|
" Work around handicapped neovim...
|
||||||
let callback = { 'listf': l:listf }
|
let callback = { 'listf': l:listf }
|
||||||
function! callback.on_exit(id, code)
|
function! callback.on_exit(id, code, event)
|
||||||
buffer #
|
buffer #
|
||||||
silent! bdelete! #
|
silent! bdelete! #
|
||||||
call s:HandleRunResults(a:code, self.listf)
|
call s:HandleRunResults(a:code, self.listf)
|
||||||
@@ -59,7 +61,7 @@ function! s:HandleRunResults(exitcode, listf)
|
|||||||
call delete(a:listf)
|
call delete(a:listf)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
nnoremap <buffer> <silent> <localleader>a :call <sid>AddMailAttacments()<cr>
|
nnoremap <buffer> <silent> <localleader>a :call <sid>AddMailAttachments()<cr>
|
||||||
|
|
||||||
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
|
||||||
|
|
||||||
|
|||||||
37
ftplugin/tex_LatexBox.vim
Normal file
37
ftplugin/tex_LatexBox.vim
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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
|
||||||
@@ -31,8 +31,6 @@ else
|
|||||||
endif
|
endif
|
||||||
unlet s:delims
|
unlet s:delims
|
||||||
|
|
||||||
let b:undo_ftplugin = ""
|
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ runtime! ftplugin/html.vim
|
|||||||
|
|
||||||
setlocal suffixesadd+=.vue
|
setlocal suffixesadd+=.vue
|
||||||
|
|
||||||
|
if !exists('g:no_plugin_maps') && !exists('g:no_vue_maps')
|
||||||
|
nnoremap <silent> <buffer> [[ :call search('^<\(template\<Bar>script\<Bar>style\)', 'bW')<CR>
|
||||||
|
nnoremap <silent> <buffer> ]] :call search('^<\(template\<Bar>script\<Bar>style\)', 'W')<CR>
|
||||||
|
nnoremap <silent> <buffer> [] :call search('^</\(template\<Bar>script\<Bar>style\)', 'bW')<CR>
|
||||||
|
nnoremap <silent> <buffer> ][ :call search('^</\(template\<Bar>script\<Bar>style\)', 'W')<CR>
|
||||||
|
endif
|
||||||
|
|
||||||
if exists('g:loaded_ale')
|
if exists('g:loaded_ale')
|
||||||
let g:ale_linters = get(g:, 'ale_linters', {})
|
let g:ale_linters = get(g:, 'ale_linters', {})
|
||||||
let g:ale_linters.vue = get(g:ale_linters, 'vue', ['eslint'])
|
let g:ale_linters.vue = get(g:ale_linters, 'vue', ['eslint'])
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ setlocal nolisp
|
|||||||
setlocal autoindent
|
setlocal autoindent
|
||||||
setlocal indentexpr=GetCaddyfileIndent(v:lnum)
|
setlocal indentexpr=GetCaddyfileIndent(v:lnum)
|
||||||
setlocal indentkeys+=<:>,0=},0=)
|
setlocal indentkeys+=<:>,0=},0=)
|
||||||
" setlocal cindent
|
|
||||||
|
|
||||||
if exists('*shiftwidth')
|
if exists('*shiftwidth')
|
||||||
func s:sw()
|
function! s:sw()
|
||||||
return shiftwidth()
|
return shiftwidth()
|
||||||
endfunc
|
endfunc
|
||||||
else
|
else
|
||||||
func s:sw()
|
function! s:sw()
|
||||||
return &sw
|
return &sw
|
||||||
endfunc
|
endfunc
|
||||||
endif
|
endif
|
||||||
|
|||||||
433
indent/cython.vim
Normal file
433
indent/cython.vim
Normal file
@@ -0,0 +1,433 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python-ident') == -1
|
||||||
|
|
||||||
|
" PEP8 compatible Python indent file
|
||||||
|
" Language: Python
|
||||||
|
" Maintainer: Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
" Prev Maintainer: Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Prev Maintainer: Eric Mc Sween <em@tomcom.de> (address invalid)
|
||||||
|
" Original Author: David Bustos <bustos@caltech.edu> (address invalid)
|
||||||
|
" License: CC0
|
||||||
|
"
|
||||||
|
" vim-python-pep8-indent - A nicer Python indentation style for vim.
|
||||||
|
" Written in 2004 by David Bustos <bustos@caltech.edu>
|
||||||
|
" Maintained from 2004-2005 by Eric Mc Sween <em@tomcom.de>
|
||||||
|
" Maintained from 2013 by Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Maintained from 2017 by Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
"
|
||||||
|
" To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
" and related and neighboring rights to this software to the public domain
|
||||||
|
" worldwide. This software is distributed without any warranty.
|
||||||
|
" You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
" with this software. If not, see
|
||||||
|
" <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
|
||||||
|
" Only load this indent file when no other was loaded.
|
||||||
|
if exists('b:did_indent')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
||||||
|
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
||||||
|
|
||||||
|
if !exists('g:python_pep8_indent_multiline_string')
|
||||||
|
let g:python_pep8_indent_multiline_string = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:block_rules = {
|
||||||
|
\ '^\s*elif\>': ['if', 'elif'],
|
||||||
|
\ '^\s*except\>': ['try', 'except'],
|
||||||
|
\ '^\s*finally\>': ['try', 'except', 'else']
|
||||||
|
\ }
|
||||||
|
let s:block_rules_multiple = {
|
||||||
|
\ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
|
||||||
|
\ }
|
||||||
|
" Pairs to look for when searching for opening parenthesis.
|
||||||
|
" The value is the maximum offset in lines.
|
||||||
|
let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000}
|
||||||
|
|
||||||
|
if &filetype ==# 'pyrex' || &filetype ==# 'cython'
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
|
||||||
|
else
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except)>'
|
||||||
|
endif
|
||||||
|
let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
||||||
|
|
||||||
|
" Skip strings and comments. Return 1 for chars to skip.
|
||||||
|
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
|
||||||
|
" are inserted temporarily into the buffer.
|
||||||
|
let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vstring|comment|jedi\\S"'
|
||||||
|
|
||||||
|
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vcomment|jedi\\S"'
|
||||||
|
|
||||||
|
" Also ignore anything concealed.
|
||||||
|
" Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI).
|
||||||
|
function! s:is_concealed(line, col)
|
||||||
|
let concealed = synconcealed(a:line, a:col)
|
||||||
|
return len(concealed) && concealed[0]
|
||||||
|
endfunction
|
||||||
|
if has('conceal')
|
||||||
|
let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
let s:skip_search = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "comment"'
|
||||||
|
|
||||||
|
" Use 'shiftwidth()' instead of '&sw'.
|
||||||
|
" (Since Vim patch 7.3.629, 'shiftwidth' can be set to 0 to follow 'tabstop').
|
||||||
|
if exists('*shiftwidth')
|
||||||
|
function! s:sw()
|
||||||
|
return shiftwidth()
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:sw()
|
||||||
|
return &shiftwidth
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:pair_sort(x, y)
|
||||||
|
if a:x[0] == a:y[0]
|
||||||
|
return a:x[1] == a:y[1] ? 0 : a:x[1] > a:y[1] ? 1 : -1
|
||||||
|
else
|
||||||
|
return a:x[0] > a:y[0] ? 1 : -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find backwards the closest open parenthesis/bracket/brace.
|
||||||
|
function! s:find_opening_paren(...)
|
||||||
|
" optional arguments: line and column (defaults to 1) to search around
|
||||||
|
if a:0 > 0
|
||||||
|
let view = winsaveview()
|
||||||
|
call cursor(a:1, a:0 > 1 ? a:2 : 1)
|
||||||
|
let ret = s:find_opening_paren()
|
||||||
|
call winrestview(view)
|
||||||
|
return ret
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Return if cursor is in a comment.
|
||||||
|
exe 'if' s:skip_search '| return [0, 0] | endif'
|
||||||
|
|
||||||
|
let nearest = [0, 0]
|
||||||
|
for [p, maxoff] in items(s:paren_pairs)
|
||||||
|
let stopline = max([0, line('.') - maxoff, nearest[0]])
|
||||||
|
let next = searchpairpos(
|
||||||
|
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
|
||||||
|
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
|
||||||
|
let nearest = next
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return nearest
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find the start of a multi-line statement
|
||||||
|
function! s:find_start_of_multiline_statement(lnum)
|
||||||
|
let lnum = a:lnum
|
||||||
|
while lnum > 0
|
||||||
|
if getline(lnum - 1) =~# '\\$'
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
else
|
||||||
|
let [paren_lnum, _] = s:find_opening_paren(lnum)
|
||||||
|
if paren_lnum < 1
|
||||||
|
return lnum
|
||||||
|
else
|
||||||
|
let lnum = paren_lnum
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find possible indent(s) of the block starter that matches the current line.
|
||||||
|
function! s:find_start_of_block(lnum, types, multiple)
|
||||||
|
let r = []
|
||||||
|
let types = copy(a:types)
|
||||||
|
let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>'
|
||||||
|
let lnum = a:lnum
|
||||||
|
let last_indent = indent(lnum) + 1
|
||||||
|
while lnum > 0 && last_indent > 0
|
||||||
|
let indent = indent(lnum)
|
||||||
|
if indent < last_indent
|
||||||
|
for type in types
|
||||||
|
let re = '\v^\s*'.type.'>'
|
||||||
|
if getline(lnum) =~# re
|
||||||
|
if !a:multiple
|
||||||
|
return [indent]
|
||||||
|
endif
|
||||||
|
if index(r, indent) == -1
|
||||||
|
let r += [indent]
|
||||||
|
endif
|
||||||
|
" Remove any handled type, e.g. 'if'.
|
||||||
|
call remove(types, index(types, type))
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let last_indent = indent(lnum)
|
||||||
|
endif
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
endwhile
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is "expr" true for every position in "lnum", beginning at "start"?
|
||||||
|
" (optionally up to a:1 / 4th argument)
|
||||||
|
function! s:match_expr_on_line(expr, lnum, start, ...)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
let end = a:0 ? a:1 : len(text)
|
||||||
|
if a:start > end
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
let save_pos = getpos('.')
|
||||||
|
let r = 1
|
||||||
|
for i in range(a:start, end)
|
||||||
|
call cursor(a:lnum, i)
|
||||||
|
if !(eval(a:expr) || text[i-1] =~# '\s')
|
||||||
|
let r = 0
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call setpos('.', save_pos)
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Line up with open parenthesis/bracket/brace.
|
||||||
|
function! s:indent_like_opening_paren(lnum)
|
||||||
|
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum)
|
||||||
|
if paren_lnum <= 0
|
||||||
|
return -2
|
||||||
|
endif
|
||||||
|
let text = getline(paren_lnum)
|
||||||
|
let base = indent(paren_lnum)
|
||||||
|
|
||||||
|
let nothing_after_opening_paren = s:match_expr_on_line(
|
||||||
|
\ s:skip_after_opening_paren, paren_lnum, paren_col+1)
|
||||||
|
let starts_with_closing_paren = getline(a:lnum) =~# '^\s*[])}]'
|
||||||
|
|
||||||
|
if nothing_after_opening_paren
|
||||||
|
if starts_with_closing_paren
|
||||||
|
let res = base
|
||||||
|
else
|
||||||
|
let res = base + s:sw()
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
" Indent to match position of opening paren.
|
||||||
|
let res = paren_col
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if text =~# b:control_statement && res == base + s:sw()
|
||||||
|
return base + s:sw() * 2
|
||||||
|
else
|
||||||
|
return res
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Match indent of first block of this type.
|
||||||
|
function! s:indent_like_block(lnum)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
for [multiple, block_rules] in [
|
||||||
|
\ [0, s:block_rules],
|
||||||
|
\ [1, s:block_rules_multiple]]
|
||||||
|
for [line_re, blocks] in items(block_rules)
|
||||||
|
if text !~# line_re
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple)
|
||||||
|
if !len(indents)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
if len(indents) == 1
|
||||||
|
return indents[0]
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Multiple valid indents, e.g. for 'else' with both try and if.
|
||||||
|
let indent = indent(a:lnum)
|
||||||
|
if index(indents, indent) != -1
|
||||||
|
" The indent is valid, keep it.
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
" Fallback to the first/nearest one.
|
||||||
|
return indents[0]
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
return -2
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:indent_like_previous_line(lnum)
|
||||||
|
let lnum = prevnonblank(a:lnum - 1)
|
||||||
|
|
||||||
|
" No previous line, keep current indent.
|
||||||
|
if lnum < 1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let text = getline(lnum)
|
||||||
|
let start = s:find_start_of_multiline_statement(lnum)
|
||||||
|
let base = indent(start)
|
||||||
|
let current = indent(a:lnum)
|
||||||
|
|
||||||
|
" Jump to last character in previous line.
|
||||||
|
call cursor(lnum, len(text))
|
||||||
|
let ignore_last_char = eval(s:skip_special_chars)
|
||||||
|
|
||||||
|
" Search for final colon that is not inside something to be ignored.
|
||||||
|
while 1
|
||||||
|
let curpos = getpos('.')[2]
|
||||||
|
if curpos == 1 | break | endif
|
||||||
|
if eval(s:skip_special_chars) || text[curpos-1] =~# '\s'
|
||||||
|
normal! h
|
||||||
|
continue
|
||||||
|
elseif text[curpos-1] ==# ':'
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
break
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if text =~# '\\$' && !ignore_last_char
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if getline(start) =~# b:control_statement
|
||||||
|
return base + s:sw() * 2
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Nest (other) explicit continuations only one level deeper.
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let empty = getline(a:lnum) =~# '^\s*$'
|
||||||
|
|
||||||
|
" Current and prev line are empty, next is not -> indent like next.
|
||||||
|
if empty && a:lnum > 1 &&
|
||||||
|
\ (getline(a:lnum - 1) =~# '^\s*$') &&
|
||||||
|
\ !(getline(a:lnum + 1) =~# '^\s*$')
|
||||||
|
return indent(a:lnum + 1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the previous statement was a stop-execution statement or a pass
|
||||||
|
if getline(start) =~# s:stop_statement
|
||||||
|
" Remove one level of indentation if the user hasn't already dedented
|
||||||
|
if empty || current > base - s:sw()
|
||||||
|
return base - s:sw()
|
||||||
|
endif
|
||||||
|
" Otherwise, trust the user
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !empty && s:is_dedented_already(current, base)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" In all other cases, line up with the start of the previous statement.
|
||||||
|
return base
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" If this line is dedented and the number of indent spaces is valid
|
||||||
|
" (multiple of the indentation size), trust the user.
|
||||||
|
function! s:is_dedented_already(current, base)
|
||||||
|
let dedent_size = a:current - a:base
|
||||||
|
return (dedent_size < 0 && a:current % s:sw() == 0) ? 1 : 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is the syntax at lnum (and optionally cnum) a python string?
|
||||||
|
function! s:is_python_string(lnum, ...)
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let linelen = len(line)
|
||||||
|
if linelen < 1
|
||||||
|
let linelen = 1
|
||||||
|
endif
|
||||||
|
let cols = a:0 ? type(a:1) != type([]) ? [a:1] : a:1 : range(1, linelen)
|
||||||
|
for cnum in cols
|
||||||
|
if match(map(synstack(a:lnum, cnum),
|
||||||
|
\ "synIDattr(v:val, 'name')"), 'python\S*String') == -1
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GetPythonPEPIndent(lnum)
|
||||||
|
" First line has indent 0
|
||||||
|
if a:lnum == 1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let prevline = getline(a:lnum-1)
|
||||||
|
|
||||||
|
" Multilinestrings: continous, docstring or starting.
|
||||||
|
if s:is_python_string(a:lnum-1, len(prevline))
|
||||||
|
\ && (s:is_python_string(a:lnum, 1)
|
||||||
|
\ || match(line, '^\%("""\|''''''\)') != -1)
|
||||||
|
|
||||||
|
" Indent closing quotes as the line with the opening ones.
|
||||||
|
let match_quotes = match(line, '^\s*\zs\%("""\|''''''\)')
|
||||||
|
if match_quotes != -1
|
||||||
|
" closing multiline string
|
||||||
|
let quotes = line[match_quotes:(match_quotes+2)]
|
||||||
|
let pairpos = searchpairpos(quotes, '', quotes, 'b')
|
||||||
|
if pairpos[0] != 0
|
||||||
|
return indent(pairpos[0])
|
||||||
|
else
|
||||||
|
" TODO: test to cover this!
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:is_python_string(a:lnum-1)
|
||||||
|
" Previous line is (completely) a string.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if match(prevline, '^\s*\%("""\|''''''\)') != -1
|
||||||
|
" docstring.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indent_multi = get(b:, 'python_pep8_indent_multiline_string',
|
||||||
|
\ get(g:, 'python_pep8_indent_multiline_string', 0))
|
||||||
|
if match(prevline, '\v%("""|'''''')$') != -1
|
||||||
|
" Opening multiline string, started in previous line.
|
||||||
|
if (&autoindent && indent(a:lnum) == indent(a:lnum-1))
|
||||||
|
\ || match(line, '\v^\s+$') != -1
|
||||||
|
" <CR> with empty line or to split up 'foo("""bar' into
|
||||||
|
" 'foo("""' and 'bar'.
|
||||||
|
if indent_multi == -2
|
||||||
|
return indent(a:lnum-1) + s:sw()
|
||||||
|
endif
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Keep existing indent.
|
||||||
|
if match(line, '\v^\s*\S') != -1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if indent_multi != -2
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_opening_paren(a:lnum)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Parens: If we can find an open parenthesis/bracket/brace, line up with it.
|
||||||
|
let indent = s:indent_like_opening_paren(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Blocks: Match indent of first block of this type.
|
||||||
|
let indent = s:indent_like_block(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_previous_line(a:lnum)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -296,9 +296,20 @@ function! GetHaskellIndent()
|
|||||||
|
|
||||||
"" where foo
|
"" where foo
|
||||||
"" >>>>>>bar
|
"" >>>>>>bar
|
||||||
|
""
|
||||||
|
"" where foo :: Int
|
||||||
|
"" >>>>>>>>>>-> Int
|
||||||
|
""
|
||||||
|
"" where foo x
|
||||||
|
"" >>>>>>>>|
|
||||||
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
||||||
if l:line =~ '^\s*[=-]>\s' && l:prevline =~ ' :: '
|
if l:line =~ '^\s*[=-]>\s' && l:prevline =~ ' :: '
|
||||||
return match(l:prevline, ':: ')
|
return match(l:prevline, ':: ')
|
||||||
|
elseif l:line =~ '^\s*|\s'
|
||||||
|
let l:s = match(l:prevline, '\C\<where\>')
|
||||||
|
if s:isSYN('haskellWhere', v:lnum - 1, l:s + 1)
|
||||||
|
return l:s + g:haskell_indent_where + g:haskell_indent_guard
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let l:s = match(l:prevline, '\C\<where\>')
|
let l:s = match(l:prevline, '\C\<where\>')
|
||||||
if s:isSYN('haskellWhere', v:lnum - 1, l:s + 1)
|
if s:isSYN('haskellWhere', v:lnum - 1, l:s + 1)
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ function s:Balanced(lnum,line)
|
|||||||
let pos = match(a:line, '[][(){}]')
|
let pos = match(a:line, '[][(){}]')
|
||||||
while pos != -1
|
while pos != -1
|
||||||
if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom
|
if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom
|
||||||
let l:open += match(' ' . a:line[pos],'[[({]')
|
let l:open += matchend(a:line[pos],'[[({]')
|
||||||
if l:open < 0
|
if l:open < 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -271,10 +271,7 @@ function s:OneScope()
|
|||||||
return s:Pure('s:PreviousToken') != '.'
|
return s:Pure('s:PreviousToken') != '.'
|
||||||
elseif strpart(getline('.'),col('.')-2,2) == '=>'
|
elseif strpart(getline('.'),col('.')-2,2) == '=>'
|
||||||
call cursor(0,col('.')-1)
|
call cursor(0,col('.')-1)
|
||||||
if s:PreviousToken() == ')'
|
return s:PreviousToken() != ')' || s:GetPair('(', ')', 'bW', s:skip_expr)
|
||||||
return s:GetPair('(', ')', 'bW', s:skip_expr)
|
|
||||||
endif
|
|
||||||
return 1
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -299,9 +296,9 @@ endfunction
|
|||||||
" encloses the entire context, 'cont' if whether a:firstline is a continued
|
" encloses the entire context, 'cont' if whether a:firstline is a continued
|
||||||
" expression, which could have started in a braceless context
|
" expression, which could have started in a braceless context
|
||||||
function s:IsContOne(cont)
|
function s:IsContOne(cont)
|
||||||
let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0]
|
let [l:num, pind] = b:js_cache[1] ?
|
||||||
let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0
|
\ [b:js_cache[1], indent(b:js_cache[1]) + s:sw()] : [1,0]
|
||||||
let ind = indent('.') + !a:cont
|
let [ind, b_l] = [indent('.') + !a:cont, 0]
|
||||||
while line('.') > l:num && ind > pind || line('.') == l:num
|
while line('.') > l:num && ind > pind || line('.') == l:num
|
||||||
if indent('.') < ind && s:OneScope()
|
if indent('.') < ind && s:OneScope()
|
||||||
let b_l += 1
|
let b_l += 1
|
||||||
@@ -319,8 +316,8 @@ function s:IsContOne(cont)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function s:IsSwitch()
|
function s:IsSwitch()
|
||||||
call call('cursor',b:js_cache[1:])
|
return search('\m\C\%'.join(b:js_cache[1:],'l\%').
|
||||||
return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z)
|
\ 'c{\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nW'.s:z)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
|
" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader
|
||||||
@@ -360,10 +357,8 @@ function GetJavascriptIndent()
|
|||||||
|
|
||||||
" start with strings,comments,etc.
|
" start with strings,comments,etc.
|
||||||
if s:stack[-1] =~? 'comment\|doc'
|
if s:stack[-1] =~? 'comment\|doc'
|
||||||
if l:line =~ '^\s*\*'
|
if l:line !~ '^\s*\/[/*]'
|
||||||
return cindent(v:lnum)
|
return l:line =~ '^\s*\*' ? cindent(v:lnum) : -1
|
||||||
elseif l:line !~ '^\s*\/[/*]'
|
|
||||||
return -1
|
|
||||||
endif
|
endif
|
||||||
elseif s:stack[-1] =~? b:syng_str
|
elseif s:stack[-1] =~? b:syng_str
|
||||||
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))
|
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))
|
||||||
@@ -378,7 +373,7 @@ function GetJavascriptIndent()
|
|||||||
if s:PreviousToken() is ''
|
if s:PreviousToken() is ''
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]]
|
let [l:lnum, lcol, pline] = getpos('.')[1:2] + [getline('.')[:col('.')-1]]
|
||||||
|
|
||||||
let l:line = substitute(l:line,'^\s*','','')
|
let l:line = substitute(l:line,'^\s*','','')
|
||||||
let l:line_raw = l:line
|
let l:line_raw = l:line
|
||||||
@@ -431,7 +426,7 @@ function GetJavascriptIndent()
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if idx == -1 && pline[-1:] !~ '[{;]'
|
if idx == -1 && pline[-1:] !~ '[{;]'
|
||||||
call cursor(l:lnum, len(pline))
|
call cursor(l:lnum, lcol)
|
||||||
let sol = matchstr(l:line,s:opfirst)
|
let sol = matchstr(l:line,s:opfirst)
|
||||||
if sol is '' || sol == '/' && s:SynAt(v:lnum,
|
if sol is '' || sol == '/' && s:SynAt(v:lnum,
|
||||||
\ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex'
|
\ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex'
|
||||||
@@ -447,10 +442,11 @@ function GetJavascriptIndent()
|
|||||||
else
|
else
|
||||||
let is_op = s:sw()
|
let is_op = s:sw()
|
||||||
endif
|
endif
|
||||||
call cursor(l:lnum, len(pline))
|
call cursor(l:lnum, lcol)
|
||||||
let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw()
|
let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw()
|
||||||
endif
|
endif
|
||||||
elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U'))
|
elseif idx == -1 && s:LookingAt() == '(' && &cino =~ '(' &&
|
||||||
|
\ (search('\m\S','nbW',num) || s:ParseCino('U'))
|
||||||
let pval = s:ParseCino('(')
|
let pval = s:ParseCino('(')
|
||||||
if !pval
|
if !pval
|
||||||
let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')]
|
let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')]
|
||||||
@@ -475,6 +471,10 @@ function GetJavascriptIndent()
|
|||||||
elseif num
|
elseif num
|
||||||
return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op)
|
return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op)
|
||||||
endif
|
endif
|
||||||
|
let nest = get(get(b:,'hi_indent',{}),'blocklnr')
|
||||||
|
if nest
|
||||||
|
return indent(nest) + s:sw() + b_l + is_op
|
||||||
|
endif
|
||||||
return b_l + is_op
|
return b_l + is_op
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
79
indent/markdown.vim
Normal file
79
indent/markdown.vim
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'markdown') == -1
|
||||||
|
|
||||||
|
if exists("b:did_indent") | finish | endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal indentexpr=GetMarkdownIndent()
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal autoindent
|
||||||
|
|
||||||
|
" Automatically insert bullets
|
||||||
|
setlocal formatoptions+=r
|
||||||
|
" Do not automatically insert bullets when auto-wrapping with text-width
|
||||||
|
setlocal formatoptions-=c
|
||||||
|
" Accept various markers as bullets
|
||||||
|
setlocal comments=b:*,b:+,b:-
|
||||||
|
|
||||||
|
" Automatically continue blockquote on line break
|
||||||
|
setlocal comments+=b:>
|
||||||
|
|
||||||
|
" Only define the function once
|
||||||
|
if exists("*GetMarkdownIndent") | finish | endif
|
||||||
|
|
||||||
|
function! s:IsMkdCode(lnum)
|
||||||
|
let name = synIDattr(synID(a:lnum, 1, 0), 'name')
|
||||||
|
return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:IsLiStart(line)
|
||||||
|
return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
|
||||||
|
\ a:line =~ '^\s*[*+-] \+'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:IsHeaderLine(line)
|
||||||
|
return a:line =~ '^\s*#'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:IsBlankLine(line)
|
||||||
|
return a:line =~ '^$'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:PrevNonBlank(lnum)
|
||||||
|
let i = a:lnum
|
||||||
|
while i > 1 && s:IsBlankLine(getline(i))
|
||||||
|
let i -= 1
|
||||||
|
endwhile
|
||||||
|
return i
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function GetMarkdownIndent()
|
||||||
|
if v:lnum > 2 && s:IsBlankLine(getline(v:lnum - 1)) && s:IsBlankLine(getline(v:lnum - 2))
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
let list_ind = get(g:, "vim_markdown_new_list_item_indent", 4)
|
||||||
|
" Find a non-blank line above the current line.
|
||||||
|
let lnum = s:PrevNonBlank(v:lnum - 1)
|
||||||
|
" At the start of the file use zero indent.
|
||||||
|
if lnum == 0 | return 0 | endif
|
||||||
|
let ind = indent(lnum)
|
||||||
|
let line = getline(lnum) " Last line
|
||||||
|
let cline = getline(v:lnum) " Current line
|
||||||
|
if s:IsLiStart(cline)
|
||||||
|
" Current line is the first line of a list item, do not change indent
|
||||||
|
return indent(v:lnum)
|
||||||
|
elseif s:IsHeaderLine(cline) && !s:IsMkdCode(v:lnum)
|
||||||
|
" Current line is the header, do not indent
|
||||||
|
return 0
|
||||||
|
elseif s:IsLiStart(line)
|
||||||
|
if s:IsMkdCode(lnum)
|
||||||
|
return ind
|
||||||
|
else
|
||||||
|
" Last line is the first line of a list item, increase indent
|
||||||
|
return ind + list_ind
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return ind
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -1,217 +1,433 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python-ident') == -1
|
||||||
|
|
||||||
" PEP8 compatible Python indent file
|
" PEP8 compatible Python indent file
|
||||||
|
" Language: Python
|
||||||
|
" Maintainer: Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
" Prev Maintainer: Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Prev Maintainer: Eric Mc Sween <em@tomcom.de> (address invalid)
|
||||||
|
" Original Author: David Bustos <bustos@caltech.edu> (address invalid)
|
||||||
|
" License: CC0
|
||||||
|
"
|
||||||
|
" vim-python-pep8-indent - A nicer Python indentation style for vim.
|
||||||
|
" Written in 2004 by David Bustos <bustos@caltech.edu>
|
||||||
|
" Maintained from 2004-2005 by Eric Mc Sween <em@tomcom.de>
|
||||||
|
" Maintained from 2013 by Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Maintained from 2017 by Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
"
|
||||||
|
" To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
" and related and neighboring rights to this software to the public domain
|
||||||
|
" worldwide. This software is distributed without any warranty.
|
||||||
|
" You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
" with this software. If not, see
|
||||||
|
" <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
" Only load this indent file when no other was loaded.
|
||||||
if exists("b:did_indent")
|
if exists('b:did_indent')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
setlocal expandtab
|
|
||||||
setlocal nolisp
|
setlocal nolisp
|
||||||
setlocal autoindent
|
setlocal autoindent
|
||||||
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
||||||
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
||||||
|
|
||||||
let s:maxoff = 50
|
if !exists('g:python_pep8_indent_multiline_string')
|
||||||
|
let g:python_pep8_indent_multiline_string = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:block_rules = {
|
||||||
|
\ '^\s*elif\>': ['if', 'elif'],
|
||||||
|
\ '^\s*except\>': ['try', 'except'],
|
||||||
|
\ '^\s*finally\>': ['try', 'except', 'else']
|
||||||
|
\ }
|
||||||
|
let s:block_rules_multiple = {
|
||||||
|
\ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
|
||||||
|
\ }
|
||||||
|
" Pairs to look for when searching for opening parenthesis.
|
||||||
|
" The value is the maximum offset in lines.
|
||||||
|
let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000}
|
||||||
|
|
||||||
|
if &filetype ==# 'pyrex' || &filetype ==# 'cython'
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
|
||||||
|
else
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except)>'
|
||||||
|
endif
|
||||||
|
let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
||||||
|
|
||||||
|
" Skip strings and comments. Return 1 for chars to skip.
|
||||||
|
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
|
||||||
|
" are inserted temporarily into the buffer.
|
||||||
|
let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vstring|comment|jedi\\S"'
|
||||||
|
|
||||||
|
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vcomment|jedi\\S"'
|
||||||
|
|
||||||
|
" Also ignore anything concealed.
|
||||||
|
" Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI).
|
||||||
|
function! s:is_concealed(line, col)
|
||||||
|
let concealed = synconcealed(a:line, a:col)
|
||||||
|
return len(concealed) && concealed[0]
|
||||||
|
endfunction
|
||||||
|
if has('conceal')
|
||||||
|
let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
let s:skip_search = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "comment"'
|
||||||
|
|
||||||
|
" Use 'shiftwidth()' instead of '&sw'.
|
||||||
|
" (Since Vim patch 7.3.629, 'shiftwidth' can be set to 0 to follow 'tabstop').
|
||||||
|
if exists('*shiftwidth')
|
||||||
|
function! s:sw()
|
||||||
|
return shiftwidth()
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:sw()
|
||||||
|
return &shiftwidth
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:pair_sort(x, y)
|
||||||
|
if a:x[0] == a:y[0]
|
||||||
|
return a:x[1] == a:y[1] ? 0 : a:x[1] > a:y[1] ? 1 : -1
|
||||||
|
else
|
||||||
|
return a:x[0] > a:y[0] ? 1 : -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Find backwards the closest open parenthesis/bracket/brace.
|
" Find backwards the closest open parenthesis/bracket/brace.
|
||||||
function! s:SearchParensPair()
|
function! s:find_opening_paren(...)
|
||||||
let line = line('.')
|
" optional arguments: line and column (defaults to 1) to search around
|
||||||
let col = col('.')
|
if a:0 > 0
|
||||||
|
let view = winsaveview()
|
||||||
|
call cursor(a:1, a:0 > 1 ? a:2 : 1)
|
||||||
|
let ret = s:find_opening_paren()
|
||||||
|
call winrestview(view)
|
||||||
|
return ret
|
||||||
|
endif
|
||||||
|
|
||||||
" Skip strings and comments and don't look too far
|
" Return if cursor is in a comment.
|
||||||
let skip = "line('.') < " . (line - s:maxoff) . " ? dummy :" .
|
exe 'if' s:skip_search '| return [0, 0] | endif'
|
||||||
\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? ' .
|
|
||||||
\ '"string\\|comment"'
|
|
||||||
|
|
||||||
" Search for parentheses
|
let nearest = [0, 0]
|
||||||
call cursor(line, col)
|
for [p, maxoff] in items(s:paren_pairs)
|
||||||
let parlnum = searchpair('(', '', ')', 'bW', skip)
|
let stopline = max([0, line('.') - maxoff, nearest[0]])
|
||||||
let parcol = col('.')
|
let next = searchpairpos(
|
||||||
|
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
|
||||||
" Search for brackets
|
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
|
||||||
call cursor(line, col)
|
let nearest = next
|
||||||
let par2lnum = searchpair('\[', '', '\]', 'bW', skip)
|
endif
|
||||||
let par2col = col('.')
|
endfor
|
||||||
|
return nearest
|
||||||
" Search for braces
|
|
||||||
call cursor(line, col)
|
|
||||||
let par3lnum = searchpair('{', '', '}', 'bW', skip)
|
|
||||||
let par3col = col('.')
|
|
||||||
|
|
||||||
" Get the closest match
|
|
||||||
if par2lnum > parlnum || (par2lnum == parlnum && par2col > parcol)
|
|
||||||
let parlnum = par2lnum
|
|
||||||
let parcol = par2col
|
|
||||||
endif
|
|
||||||
if par3lnum > parlnum || (par3lnum == parlnum && par3col > parcol)
|
|
||||||
let parlnum = par3lnum
|
|
||||||
let parcol = par3col
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Put the cursor on the match
|
|
||||||
if parlnum > 0
|
|
||||||
call cursor(parlnum, parcol)
|
|
||||||
endif
|
|
||||||
return parlnum
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Find the start of a multi-line statement
|
" Find the start of a multi-line statement
|
||||||
function! s:StatementStart(lnum)
|
function! s:find_start_of_multiline_statement(lnum)
|
||||||
let lnum = a:lnum
|
let lnum = a:lnum
|
||||||
while 1
|
while lnum > 0
|
||||||
if getline(lnum - 1) =~ '\\$'
|
if getline(lnum - 1) =~# '\\$'
|
||||||
let lnum = lnum - 1
|
let lnum = prevnonblank(lnum - 1)
|
||||||
else
|
else
|
||||||
call cursor(lnum, 1)
|
let [paren_lnum, _] = s:find_opening_paren(lnum)
|
||||||
let maybe_lnum = s:SearchParensPair()
|
if paren_lnum < 1
|
||||||
if maybe_lnum < 1
|
return lnum
|
||||||
return lnum
|
else
|
||||||
else
|
let lnum = paren_lnum
|
||||||
let lnum = maybe_lnum
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endwhile
|
||||||
endwhile
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Find the block starter that matches the current line
|
" Find possible indent(s) of the block starter that matches the current line.
|
||||||
function! s:BlockStarter(lnum, block_start_re)
|
function! s:find_start_of_block(lnum, types, multiple)
|
||||||
let lnum = a:lnum
|
let r = []
|
||||||
let maxindent = 10000 " whatever
|
let types = copy(a:types)
|
||||||
while lnum > 1
|
let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>'
|
||||||
let lnum = prevnonblank(lnum - 1)
|
let lnum = a:lnum
|
||||||
if indent(lnum) < maxindent
|
let last_indent = indent(lnum) + 1
|
||||||
if getline(lnum) =~ a:block_start_re
|
while lnum > 0 && last_indent > 0
|
||||||
return lnum
|
let indent = indent(lnum)
|
||||||
else
|
if indent < last_indent
|
||||||
let maxindent = indent(lnum)
|
for type in types
|
||||||
" It's not worth going further if we reached the top level
|
let re = '\v^\s*'.type.'>'
|
||||||
if maxindent == 0
|
if getline(lnum) =~# re
|
||||||
return -1
|
if !a:multiple
|
||||||
|
return [indent]
|
||||||
|
endif
|
||||||
|
if index(r, indent) == -1
|
||||||
|
let r += [indent]
|
||||||
|
endif
|
||||||
|
" Remove any handled type, e.g. 'if'.
|
||||||
|
call remove(types, index(types, type))
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let last_indent = indent(lnum)
|
||||||
endif
|
endif
|
||||||
endif
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
endwhile
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is "expr" true for every position in "lnum", beginning at "start"?
|
||||||
|
" (optionally up to a:1 / 4th argument)
|
||||||
|
function! s:match_expr_on_line(expr, lnum, start, ...)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
let end = a:0 ? a:1 : len(text)
|
||||||
|
if a:start > end
|
||||||
|
return 1
|
||||||
endif
|
endif
|
||||||
endwhile
|
let save_pos = getpos('.')
|
||||||
return -1
|
let r = 1
|
||||||
|
for i in range(a:start, end)
|
||||||
|
call cursor(a:lnum, i)
|
||||||
|
if !(eval(a:expr) || text[i-1] =~# '\s')
|
||||||
|
let r = 0
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call setpos('.', save_pos)
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Line up with open parenthesis/bracket/brace.
|
||||||
|
function! s:indent_like_opening_paren(lnum)
|
||||||
|
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum)
|
||||||
|
if paren_lnum <= 0
|
||||||
|
return -2
|
||||||
|
endif
|
||||||
|
let text = getline(paren_lnum)
|
||||||
|
let base = indent(paren_lnum)
|
||||||
|
|
||||||
|
let nothing_after_opening_paren = s:match_expr_on_line(
|
||||||
|
\ s:skip_after_opening_paren, paren_lnum, paren_col+1)
|
||||||
|
let starts_with_closing_paren = getline(a:lnum) =~# '^\s*[])}]'
|
||||||
|
|
||||||
|
if nothing_after_opening_paren
|
||||||
|
if starts_with_closing_paren
|
||||||
|
let res = base
|
||||||
|
else
|
||||||
|
let res = base + s:sw()
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
" Indent to match position of opening paren.
|
||||||
|
let res = paren_col
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if text =~# b:control_statement && res == base + s:sw()
|
||||||
|
return base + s:sw() * 2
|
||||||
|
else
|
||||||
|
return res
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Match indent of first block of this type.
|
||||||
|
function! s:indent_like_block(lnum)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
for [multiple, block_rules] in [
|
||||||
|
\ [0, s:block_rules],
|
||||||
|
\ [1, s:block_rules_multiple]]
|
||||||
|
for [line_re, blocks] in items(block_rules)
|
||||||
|
if text !~# line_re
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple)
|
||||||
|
if !len(indents)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
if len(indents) == 1
|
||||||
|
return indents[0]
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Multiple valid indents, e.g. for 'else' with both try and if.
|
||||||
|
let indent = indent(a:lnum)
|
||||||
|
if index(indents, indent) != -1
|
||||||
|
" The indent is valid, keep it.
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
" Fallback to the first/nearest one.
|
||||||
|
return indents[0]
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
return -2
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:indent_like_previous_line(lnum)
|
||||||
|
let lnum = prevnonblank(a:lnum - 1)
|
||||||
|
|
||||||
|
" No previous line, keep current indent.
|
||||||
|
if lnum < 1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let text = getline(lnum)
|
||||||
|
let start = s:find_start_of_multiline_statement(lnum)
|
||||||
|
let base = indent(start)
|
||||||
|
let current = indent(a:lnum)
|
||||||
|
|
||||||
|
" Jump to last character in previous line.
|
||||||
|
call cursor(lnum, len(text))
|
||||||
|
let ignore_last_char = eval(s:skip_special_chars)
|
||||||
|
|
||||||
|
" Search for final colon that is not inside something to be ignored.
|
||||||
|
while 1
|
||||||
|
let curpos = getpos('.')[2]
|
||||||
|
if curpos == 1 | break | endif
|
||||||
|
if eval(s:skip_special_chars) || text[curpos-1] =~# '\s'
|
||||||
|
normal! h
|
||||||
|
continue
|
||||||
|
elseif text[curpos-1] ==# ':'
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
break
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if text =~# '\\$' && !ignore_last_char
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if getline(start) =~# b:control_statement
|
||||||
|
return base + s:sw() * 2
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Nest (other) explicit continuations only one level deeper.
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let empty = getline(a:lnum) =~# '^\s*$'
|
||||||
|
|
||||||
|
" Current and prev line are empty, next is not -> indent like next.
|
||||||
|
if empty && a:lnum > 1 &&
|
||||||
|
\ (getline(a:lnum - 1) =~# '^\s*$') &&
|
||||||
|
\ !(getline(a:lnum + 1) =~# '^\s*$')
|
||||||
|
return indent(a:lnum + 1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the previous statement was a stop-execution statement or a pass
|
||||||
|
if getline(start) =~# s:stop_statement
|
||||||
|
" Remove one level of indentation if the user hasn't already dedented
|
||||||
|
if empty || current > base - s:sw()
|
||||||
|
return base - s:sw()
|
||||||
|
endif
|
||||||
|
" Otherwise, trust the user
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !empty && s:is_dedented_already(current, base)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" In all other cases, line up with the start of the previous statement.
|
||||||
|
return base
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" If this line is dedented and the number of indent spaces is valid
|
||||||
|
" (multiple of the indentation size), trust the user.
|
||||||
|
function! s:is_dedented_already(current, base)
|
||||||
|
let dedent_size = a:current - a:base
|
||||||
|
return (dedent_size < 0 && a:current % s:sw() == 0) ? 1 : 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is the syntax at lnum (and optionally cnum) a python string?
|
||||||
|
function! s:is_python_string(lnum, ...)
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let linelen = len(line)
|
||||||
|
if linelen < 1
|
||||||
|
let linelen = 1
|
||||||
|
endif
|
||||||
|
let cols = a:0 ? type(a:1) != type([]) ? [a:1] : a:1 : range(1, linelen)
|
||||||
|
for cnum in cols
|
||||||
|
if match(map(synstack(a:lnum, cnum),
|
||||||
|
\ "synIDattr(v:val, 'name')"), 'python\S*String') == -1
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! GetPythonPEPIndent(lnum)
|
function! GetPythonPEPIndent(lnum)
|
||||||
let scol = col('.')
|
" First line has indent 0
|
||||||
|
if a:lnum == 1
|
||||||
" First line has indent 0
|
return 0
|
||||||
if a:lnum == 1
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If we can find an open parenthesis/bracket/brace, line up with it.
|
|
||||||
call cursor(a:lnum, 1)
|
|
||||||
let parlnum = s:SearchParensPair()
|
|
||||||
if parlnum > 0
|
|
||||||
let parcol = col('.')
|
|
||||||
let matches = matchlist(getline(a:lnum), '^\(\s*\)[])}]')
|
|
||||||
if len(matches) == 0
|
|
||||||
let closing_paren = 0
|
|
||||||
let closing_paren_pos = 0
|
|
||||||
else
|
|
||||||
let closing_paren = 1
|
|
||||||
let closing_paren_pos = len(matches[1])
|
|
||||||
endif
|
endif
|
||||||
if match(getline(parlnum), '[([{]\s*$', parcol - 1) != -1
|
|
||||||
if closing_paren
|
let line = getline(a:lnum)
|
||||||
return indent(parlnum)
|
let prevline = getline(a:lnum-1)
|
||||||
else
|
|
||||||
return indent(parlnum) + &shiftwidth
|
" Multilinestrings: continous, docstring or starting.
|
||||||
endif
|
if s:is_python_string(a:lnum-1, len(prevline))
|
||||||
elseif a:lnum - 1 != parlnum
|
\ && (s:is_python_string(a:lnum, 1)
|
||||||
if closing_paren && closing_paren_pos > scol
|
\ || match(line, '^\%("""\|''''''\)') != -1)
|
||||||
return indent(parlnum)
|
|
||||||
else
|
" Indent closing quotes as the line with the opening ones.
|
||||||
let lastindent = match(getline(a:lnum - 1), '\S')
|
let match_quotes = match(line, '^\s*\zs\%("""\|''''''\)')
|
||||||
if lastindent != -1 && lastindent < parcol
|
if match_quotes != -1
|
||||||
return lastindent
|
" closing multiline string
|
||||||
|
let quotes = line[match_quotes:(match_quotes+2)]
|
||||||
|
let pairpos = searchpairpos(quotes, '', quotes, 'b')
|
||||||
|
if pairpos[0] != 0
|
||||||
|
return indent(pairpos[0])
|
||||||
|
else
|
||||||
|
" TODO: test to cover this!
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
if s:is_python_string(a:lnum-1)
|
||||||
|
" Previous line is (completely) a string.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if match(prevline, '^\s*\%("""\|''''''\)') != -1
|
||||||
|
" docstring.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indent_multi = get(b:, 'python_pep8_indent_multiline_string',
|
||||||
|
\ get(g:, 'python_pep8_indent_multiline_string', 0))
|
||||||
|
if match(prevline, '\v%("""|'''''')$') != -1
|
||||||
|
" Opening multiline string, started in previous line.
|
||||||
|
if (&autoindent && indent(a:lnum) == indent(a:lnum-1))
|
||||||
|
\ || match(line, '\v^\s+$') != -1
|
||||||
|
" <CR> with empty line or to split up 'foo("""bar' into
|
||||||
|
" 'foo("""' and 'bar'.
|
||||||
|
if indent_multi == -2
|
||||||
|
return indent(a:lnum-1) + s:sw()
|
||||||
|
endif
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Keep existing indent.
|
||||||
|
if match(line, '\v^\s*\S') != -1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if indent_multi != -2
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_opening_paren(a:lnum)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If we line up with an opening column there is a special case
|
" Parens: If we can find an open parenthesis/bracket/brace, line up with it.
|
||||||
" we want to handle: a docstring as argument. In that case we
|
let indent = s:indent_like_opening_paren(a:lnum)
|
||||||
" don't want to line up with the paren but with the statement
|
if indent >= -1
|
||||||
" imagine foo(doc=""" as example
|
return indent
|
||||||
echo getline(parlnum)
|
|
||||||
if match(getline(parlnum), '\("""\|' . "'''" . '\)\s*$') != -1
|
|
||||||
return indent(parlnum)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return parcol
|
" Blocks: Match indent of first block of this type.
|
||||||
endif
|
let indent = s:indent_like_block(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
" Examine this line
|
return indent
|
||||||
let thisline = getline(a:lnum)
|
|
||||||
let thisindent = indent(a:lnum)
|
|
||||||
|
|
||||||
" If the line starts with 'elif' or 'else', line up with 'if' or 'elif'
|
|
||||||
if thisline =~ '^\s*\(elif\|else\)\>'
|
|
||||||
let bslnum = s:BlockStarter(a:lnum, '^\s*\(if\|elif\)\>')
|
|
||||||
if bslnum > 0
|
|
||||||
return indent(bslnum)
|
|
||||||
else
|
|
||||||
return -1
|
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
" If the line starts with 'except' or 'finally', line up with 'try'
|
return s:indent_like_previous_line(a:lnum)
|
||||||
" or 'except'
|
|
||||||
if thisline =~ '^\s*\(except\|finally\)\>'
|
|
||||||
let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\)\>')
|
|
||||||
if bslnum > 0
|
|
||||||
return indent(bslnum)
|
|
||||||
else
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Examine previous line
|
|
||||||
let plnum = a:lnum - 1
|
|
||||||
let pline = getline(plnum)
|
|
||||||
let sslnum = s:StatementStart(plnum)
|
|
||||||
|
|
||||||
" If the previous line is blank, keep the same indentation
|
|
||||||
if pline =~ '^\s*$'
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If this line is explicitly joined, try to find an indentation that looks
|
|
||||||
" good.
|
|
||||||
if pline =~ '\\$'
|
|
||||||
let compound_statement = '^\s*\(if\|while\|from\|import\|for\s.*\sin\|except\)\s*'
|
|
||||||
let maybe_indent = matchend(getline(sslnum), compound_statement)
|
|
||||||
if maybe_indent != -1
|
|
||||||
return maybe_indent
|
|
||||||
else
|
|
||||||
return indent(sslnum) + &sw * 2
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If the previous line ended with a colon and is not a comment, indent
|
|
||||||
" relative to statement start.
|
|
||||||
if pline =~ '^[^#]*:\s*\(#.*\)\?$'
|
|
||||||
return indent(sslnum) + &sw
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If the previous line was a stop-execution statement or a pass
|
|
||||||
if getline(sslnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
|
||||||
" See if the user has already dedented
|
|
||||||
if indent(a:lnum) > indent(sslnum) - &sw
|
|
||||||
" If not, recommend one dedent
|
|
||||||
return indent(sslnum) - &sw
|
|
||||||
endif
|
|
||||||
" Otherwise, trust the user
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
|
|
||||||
" In all other cases, line up with the start of the previous statement.
|
|
||||||
return indent(sslnum)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
140
indent/tex.vim
Normal file
140
indent/tex.vim
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||||
|
|
||||||
|
" LaTeX indent file (part of LaTeX Box)
|
||||||
|
" Maintainer: David Munger (mungerd@gmail.com)
|
||||||
|
|
||||||
|
if exists("g:LatexBox_custom_indent") && ! g:LatexBox_custom_indent
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
if exists("b:did_indent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal indentexpr=LatexBox_TexIndent()
|
||||||
|
setlocal indentkeys=0=\\end,0=\\end{enumerate},0=\\end{itemize},0=\\end{description},0=\\right,0=\\item,0=\\),0=\\],0},o,O,0\\
|
||||||
|
|
||||||
|
let s:list_envs = ['itemize', 'enumerate', 'description']
|
||||||
|
" indent on \left( and on \(, but not on (
|
||||||
|
" indent on \left[ and on \[, but not on [
|
||||||
|
" indent on \left\{ and on {, but not on \{
|
||||||
|
let s:open_pat = '\\\@<!\%(\\begin\|\\left\a\@!\|\\(\|\\\[\|{\)'
|
||||||
|
let s:close_pat = '\\\@<!\%(\\end\|\\right\a\@!\|\\)\|\\\]\|}\)'
|
||||||
|
let s:list_open_pat = '\\\@<!\\begin{\%(' . join(s:list_envs, '\|') . '\)}'
|
||||||
|
let s:list_close_pat = '\\\@<!\\end{\%(' . join(s:list_envs, '\|') . '\)}'
|
||||||
|
|
||||||
|
function! s:CountMatches(str, pat)
|
||||||
|
return len(substitute(substitute(a:str, a:pat, "\n", 'g'), "[^\n]", '', 'g'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" TexIndent {{{
|
||||||
|
function! LatexBox_TexIndent()
|
||||||
|
|
||||||
|
let lnum_curr = v:lnum
|
||||||
|
let lnum_prev = prevnonblank(lnum_curr - 1)
|
||||||
|
|
||||||
|
if lnum_prev == 0
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let line_curr = getline(lnum_curr)
|
||||||
|
let line_prev = getline(lnum_prev)
|
||||||
|
|
||||||
|
" remove \\
|
||||||
|
let line_curr = substitute(line_curr, '\\\\', '', 'g')
|
||||||
|
let line_prev = substitute(line_prev, '\\\\', '', 'g')
|
||||||
|
|
||||||
|
" strip comments
|
||||||
|
let line_curr = substitute(line_curr, '\\\@<!%.*$', '', 'g')
|
||||||
|
let line_prev = substitute(line_prev, '\\\@<!%.*$', '', 'g')
|
||||||
|
|
||||||
|
" find unmatched opening patterns on previous line
|
||||||
|
let n = s:CountMatches(line_prev, s:open_pat)-s:CountMatches(line_prev, s:close_pat)
|
||||||
|
let n += s:CountMatches(line_prev, s:list_open_pat)-s:CountMatches(line_prev, s:list_close_pat)
|
||||||
|
|
||||||
|
" reduce indentation if current line starts with a closing pattern
|
||||||
|
if line_curr =~ '^\s*\%(' . s:close_pat . '\)'
|
||||||
|
let n -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" compensate indentation if previous line starts with a closing pattern
|
||||||
|
if line_prev =~ '^\s*\%(' . s:close_pat . '\)'
|
||||||
|
let n += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" reduce indentation if current line starts with a closing list
|
||||||
|
if line_curr =~ '^\s*\%(' . s:list_close_pat . '\)'
|
||||||
|
let n -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" compensate indentation if previous line starts with a closing list
|
||||||
|
if line_prev =~ '^\s*\%(' . s:list_close_pat . '\)'
|
||||||
|
let n += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" reduce indentation if previous line is \begin{document}
|
||||||
|
if line_prev =~ '\\begin\s*{document}'
|
||||||
|
let n -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" less shift for lines starting with \item
|
||||||
|
let item_here = line_curr =~ '^\s*\\item'
|
||||||
|
let item_above = line_prev =~ '^\s*\\item'
|
||||||
|
if !item_here && item_above
|
||||||
|
let n += 1
|
||||||
|
elseif item_here && !item_above
|
||||||
|
let n -= 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
return indent(lnum_prev) + n * &sw
|
||||||
|
endfunction
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
" Restore cursor position, window position, and last search after running a
|
||||||
|
" command.
|
||||||
|
function! Latexbox_CallIndent()
|
||||||
|
" Save the current cursor position.
|
||||||
|
let cursor = getpos('.')
|
||||||
|
|
||||||
|
" Save the current window position.
|
||||||
|
normal! H
|
||||||
|
let window = getpos('.')
|
||||||
|
call setpos('.', cursor)
|
||||||
|
|
||||||
|
" Get first non-whitespace character of current line.
|
||||||
|
let line_start_char = matchstr(getline('.'), '\S')
|
||||||
|
|
||||||
|
" Get initial tab position.
|
||||||
|
let initial_tab = stridx(getline('.'), line_start_char)
|
||||||
|
|
||||||
|
" Execute the command.
|
||||||
|
execute 'normal! =='
|
||||||
|
|
||||||
|
" Get tab position difference.
|
||||||
|
let difference = stridx(getline('.'), line_start_char) - initial_tab
|
||||||
|
|
||||||
|
" Set new cursor Y position based on calculated difference.
|
||||||
|
let cursor[2] = cursor[2] + difference
|
||||||
|
|
||||||
|
" Restore the previous window position.
|
||||||
|
call setpos('.', window)
|
||||||
|
normal! zt
|
||||||
|
|
||||||
|
" Restore the previous cursor position.
|
||||||
|
call setpos('.', cursor)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" autocmd to call indent after completion
|
||||||
|
" 7.3.598
|
||||||
|
if v:version > 703 || (v:version == 703 && has('patch598'))
|
||||||
|
augroup LatexBox_Completion
|
||||||
|
autocmd!
|
||||||
|
autocmd CompleteDone <buffer> call Latexbox_CallIndent()
|
||||||
|
augroup END
|
||||||
|
endif
|
||||||
|
|
||||||
|
" vim:fdm=marker:ff=unix:noet:ts=4:sw=4
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -7,7 +7,7 @@ if exists("b:current_syntax")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syn match caddyDirective "^\s*\([a-z]\+\)" nextgroup=caddyDirectiveArgs skipwhite
|
syn match caddyDirective "^\s*\([a-zA-Z0-9_]\+\)" nextgroup=caddyDirectiveArgs skipwhite
|
||||||
syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString nextgroup=caddyDirectiveBlock skipwhite
|
syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString nextgroup=caddyDirectiveBlock skipwhite
|
||||||
syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment
|
syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment
|
||||||
|
|
||||||
|
|||||||
142
syntax/carp.vim
Normal file
142
syntax/carp.vim
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'carp') == -1
|
||||||
|
|
||||||
|
" Vim syntax file
|
||||||
|
" Language: Carp
|
||||||
|
" Maintainer: Veit Heller <veit@veitheller.de>
|
||||||
|
" URL: http://github.com/hellerve/carp-vim.git
|
||||||
|
" Description: Contains all of the keywords in #lang carp
|
||||||
|
|
||||||
|
if exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
syn match carpError ,[]})],
|
||||||
|
|
||||||
|
if version < 600
|
||||||
|
set iskeyword=33,35-39,42-43,45-58,60-63,65-90,94,95,97-122,124,126,_
|
||||||
|
else
|
||||||
|
setlocal iskeyword=33,35-39,42-43,45-58,60-63,65-90,94,95,97-122,124,126,_
|
||||||
|
endif
|
||||||
|
|
||||||
|
syn keyword carpSyntax def defn let do if while ref address set! the
|
||||||
|
syn keyword carpSyntax defmacro defdynamic quote cons list array
|
||||||
|
syn keyword carpSyntax expand deftype register system-include register-type
|
||||||
|
syn keyword carpSyntax defmodule copy use module defalias definterface eval
|
||||||
|
syn keyword carpSyntax expand instantiate type info help quit env build run
|
||||||
|
syn keyword carpSyntax cat use project-set! local-include system-include
|
||||||
|
syn keyword carpSyntax add-cflag add-lib project load reload let-do ignore
|
||||||
|
syn keyword carpSyntax fmt mac-only linux-only windows-only use-all when
|
||||||
|
syn keyword carpSyntax unless defn-do comment forever-do case and* or*
|
||||||
|
syn keyword carpSyntax str* println*
|
||||||
|
syn match carpSyntax "\vc(a|d){1,4}r"
|
||||||
|
|
||||||
|
syn keyword carpFunc Int Float Double Bool String Char Array Fn Ref Long λ
|
||||||
|
syn keyword carpFunc not or and + - * / = /= >= <= > < inc dec
|
||||||
|
syn keyword carpFunc println print get-line from-string mod seed random
|
||||||
|
syn keyword carpFunc random-between str mask delete append count duplicate
|
||||||
|
syn keyword carpFunc cstr chars from-chars to-int from-int sin cos sqrt acos
|
||||||
|
syn keyword carpFunc atan2 exit time srand for cond floor abs sort-with
|
||||||
|
syn keyword carpFunc subarray prefix-array suffix-array reverse sum min max
|
||||||
|
syn keyword carpFunc first last reduce format zero read-file bit-shift-left
|
||||||
|
syn keyword carpFunc bit-shift-right bit-and bit-or bit-xor bit-not safe-add
|
||||||
|
syn keyword carpFunc safe-sub safe-mul even? odd? cmp allocate repeat-indexed
|
||||||
|
syn keyword carpFunc sanitize-addresses memory-balance reset-memory-balance!
|
||||||
|
syn keyword carpFunc log-memory-balance! memory-logged assert-balanced trace
|
||||||
|
syn keyword carpFunc pi e swaop! update! char-at tail head split-by words lines
|
||||||
|
syn keyword carpFunc pad-left pad-right count-char empty? random-sized substring
|
||||||
|
syn keyword carpFunc prefix-string suffix-string starts-with? ends-with?
|
||||||
|
syn keyword carpFunc string-join free sleep-seconds sleep-micros
|
||||||
|
syn keyword carpFunc atan2 exit time srand for cond floor abs neg to-float
|
||||||
|
syn keyword carpFunc from-float tan asin atan cosh sinh tanh exp frexp ldexp
|
||||||
|
syn keyword carpFunc log log10 modf pow ceil clamp approx refstr foreach
|
||||||
|
syn keyword carpFunc => ==> repeat nth replicate range raw aset aset! count
|
||||||
|
syn keyword carpFunc push-back pop-back sort index-of element-count
|
||||||
|
|
||||||
|
|
||||||
|
syn match carpSymbol ,\k+, contained
|
||||||
|
syn match carpTodo /\v<(FIXME|NOTE|TODO|OPTIMIZE)/ containedin=carpComment,carpString
|
||||||
|
|
||||||
|
syn cluster carpNormal contains=carpSyntax,carpFunc,carpDelimiter
|
||||||
|
syn cluster carpQuotedStuff contains=carpSymbol
|
||||||
|
syn cluster carpQuotedOrNormal contains=carpDelimiter
|
||||||
|
|
||||||
|
syn region carpQuotedStruc start="@("rs=s+2 end=")"re=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal contained
|
||||||
|
syn region carpQuotedStruc start="&("rs=s+2 end=")"re=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal contained
|
||||||
|
syn region carpQuotedStruc start="("rs=s+1 end=")"re=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal contained
|
||||||
|
syn region carpQuotedStruc start="\["rs=s+1 end="\]"re=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal contained
|
||||||
|
|
||||||
|
syn cluster carpQuotedStuff add=carpQuotedStruc
|
||||||
|
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="@("rs=s+2 matchgroup=Delimiter end=")"re=e-1 contains=@carpNormal
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="&("rs=s+2 matchgroup=Delimiter end=")"re=e-1 contains=@carpNormal
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="&"rs=s+1 end=![ \t()\[\]";]!me=e-1 contains=@carpNormal
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="@"rs=s+1 end=![ \t()\[\]";]!me=e-1 contains=@carpNormal
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="("rs=s+1 matchgroup=Delimiter end=")"re=e-1 contains=@carpNormal
|
||||||
|
syn region carpStruc matchgroup=Delimiter start="\["rs=s+1 matchgroup=Delimiter end="\]"re=e-1 contains=@carpNormal
|
||||||
|
|
||||||
|
syn region carpString start=/\%(\\\)\@<!"/ skip=/\\[\\"]/ end=/"/
|
||||||
|
|
||||||
|
syn cluster carpNormal add=carpError,carpStruc,carpString
|
||||||
|
syn cluster carpQuotedOrNormal add=carpString
|
||||||
|
|
||||||
|
syn match carpNumber "\<[-+]\?\(\d\+\|\d\+#*\.\|\d*\.\d\+\)#*\(/\d\+#*\)\?[lf]\?\>" contains=carpContainedNumberError
|
||||||
|
syn match carpNumber "\<[-+]\?\d\+/\d\+[lf]\?\>" contains=carpContainedNumberError
|
||||||
|
|
||||||
|
|
||||||
|
syn keyword carpBoolean true false
|
||||||
|
|
||||||
|
syn match carpChar "\<\\.\w\@!"
|
||||||
|
|
||||||
|
syn region carpQuoted matchgroup=Delimiter start="['`]" end=![ \t()\[\]";]!me=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal
|
||||||
|
syn region carpQuoted matchgroup=Delimiter start="['`](" matchgroup=Delimiter end=")" contains=@carpQuotedStuff,@carpQuotedOrNormal
|
||||||
|
|
||||||
|
syn cluster carpNormal add=carpNumber,carpBoolean,carpChar
|
||||||
|
syn cluster carpQuotedOrNormal add=carpNumber,carpBoolean
|
||||||
|
|
||||||
|
syn match carpComment /;.*$/ contains=@Spell
|
||||||
|
|
||||||
|
syn region carpQuoted matchgroup=Delimiter start="#['`]"rs=s+2 end=![ \t()\[\]";]!re=e-1,me=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal
|
||||||
|
syn region carpQuoted matchgroup=Delimiter start="#['`]("rs=s+3 matchgroup=Delimiter end=")"re=e-1 contains=@carpQuotedStuff,@carpQuotedOrNormal
|
||||||
|
|
||||||
|
syn cluster carpNormal add=carpQuoted,carpComment
|
||||||
|
syn cluster carpQuotedOrNormal add=carpComment
|
||||||
|
|
||||||
|
syn sync match matchPlace grouphere NONE "^[^ \t]"
|
||||||
|
|
||||||
|
if version >= 508 || !exists("carp_syntax_init")
|
||||||
|
if version < 508
|
||||||
|
let carp_syntax_init = 1
|
||||||
|
command -nargs=+ HiLink hi link <args>
|
||||||
|
else
|
||||||
|
command -nargs=+ HiLink hi def link <args>
|
||||||
|
endif
|
||||||
|
|
||||||
|
HiLink carpSyntax Statement
|
||||||
|
HiLink carpFunc Function
|
||||||
|
HiLink carpCopy Function
|
||||||
|
|
||||||
|
HiLink carpString String
|
||||||
|
HiLink carpChar Character
|
||||||
|
HiLink carpBoolean Boolean
|
||||||
|
|
||||||
|
HiLink carpNumber Number
|
||||||
|
HiLink carpNumberError Error
|
||||||
|
HiLink carpContainedNumberError Error
|
||||||
|
|
||||||
|
HiLink carpQuoted Structure
|
||||||
|
HiLink carpQuotedStruc Structure
|
||||||
|
HiLink carpSymbol Structure
|
||||||
|
HiLink carpAtom Structure
|
||||||
|
|
||||||
|
HiLink carpDelimiter Delimiter
|
||||||
|
HiLink carpConstant Constant
|
||||||
|
|
||||||
|
HiLink carpTodo Todo
|
||||||
|
HiLink carpComment Comment
|
||||||
|
HiLink carpError Error
|
||||||
|
delcommand HiLink
|
||||||
|
endif
|
||||||
|
|
||||||
|
let b:current_syntax = "carp"
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -64,9 +64,10 @@ syn match elixirVariable '&\d\+'
|
|||||||
|
|
||||||
syn keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__
|
syn keyword elixirPseudoVariable __FILE__ __DIR__ __MODULE__ __ENV__ __CALLER__
|
||||||
|
|
||||||
syn match elixirNumber '\<\d\(_\?\d\)*\(\.[^[:space:][:digit:]]\@!\(_\?\d\)*\)\?\([eE][-+]\?\d\(_\?\d\)*\)\?\>'
|
syn match elixirNumber '\<-\?\d\(_\?\d\)*\(\.[^[:space:][:digit:]]\@!\(_\?\d\)*\)\?\([eE][-+]\?\d\(_\?\d\)*\)\?\>'
|
||||||
syn match elixirNumber '\<0[xX][0-9A-Fa-f]\+\>'
|
syn match elixirNumber '\<-\?0[xX][0-9A-Fa-f]\+\>'
|
||||||
syn match elixirNumber '\<0[bB][01]\+\>'
|
syn match elixirNumber '\<-\?0[oO][0-7]\+\>'
|
||||||
|
syn match elixirNumber '\<-\?0[bB][01]\+\>'
|
||||||
|
|
||||||
syn match elixirRegexEscape "\\\\\|\\[aAbBcdDefGhHnrsStvVwW]\|\\\d\{3}\|\\x[0-9a-fA-F]\{2}" contained
|
syn match elixirRegexEscape "\\\\\|\\[aAbBcdDefGhHnrsStvVwW]\|\\\d\{3}\|\\x[0-9a-fA-F]\{2}" contained
|
||||||
syn match elixirRegexEscapePunctuation "?\|\\.\|*\|\\\[\|\\\]\|+\|\\^\|\\\$\|\\|\|\\(\|\\)\|\\{\|\\}" contained
|
syn match elixirRegexEscapePunctuation "?\|\\.\|*\|\\\[\|\\\]\|+\|\\^\|\\\$\|\\|\|\\(\|\\)\|\\{\|\\}" contained
|
||||||
@@ -142,6 +143,8 @@ syn region elixirDocString matchgroup=elixirSigilDelimiter start=+\%(@\w*doc\s\
|
|||||||
" Defines
|
" Defines
|
||||||
syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
||||||
syn match elixirPrivateDefine '\<defp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
syn match elixirPrivateDefine '\<defp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
||||||
|
syn match elixirGuard '\<defguard\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
||||||
|
syn match elixirPrivateGuard '\<defguardp\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl
|
||||||
syn match elixirModuleDefine '\<defmodule\>\(:\)\@!' nextgroup=elixirModuleDeclaration skipwhite skipnl
|
syn match elixirModuleDefine '\<defmodule\>\(:\)\@!' nextgroup=elixirModuleDeclaration skipwhite skipnl
|
||||||
syn match elixirProtocolDefine '\<defprotocol\>\(:\)\@!' nextgroup=elixirProtocolDeclaration skipwhite skipnl
|
syn match elixirProtocolDefine '\<defprotocol\>\(:\)\@!' nextgroup=elixirProtocolDeclaration skipwhite skipnl
|
||||||
syn match elixirImplDefine '\<defimpl\>\(:\)\@!' nextgroup=elixirImplDeclaration skipwhite skipnl
|
syn match elixirImplDefine '\<defimpl\>\(:\)\@!' nextgroup=elixirImplDeclaration skipwhite skipnl
|
||||||
@@ -176,6 +179,8 @@ syn match elixirExUnitAssert "\(^\s*\)\@<=\<\(catch_exit\|catch_throw\|flunk\|r
|
|||||||
hi def link elixirBlockDefinition Keyword
|
hi def link elixirBlockDefinition Keyword
|
||||||
hi def link elixirDefine Define
|
hi def link elixirDefine Define
|
||||||
hi def link elixirPrivateDefine Define
|
hi def link elixirPrivateDefine Define
|
||||||
|
hi def link elixirGuard Define
|
||||||
|
hi def link elixirPrivateGuard Define
|
||||||
hi def link elixirModuleDefine Define
|
hi def link elixirModuleDefine Define
|
||||||
hi def link elixirProtocolDefine Define
|
hi def link elixirProtocolDefine Define
|
||||||
hi def link elixirImplDefine Define
|
hi def link elixirImplDefine Define
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ if !exists("g:go_highlight_functions")
|
|||||||
let g:go_highlight_functions = 0
|
let g:go_highlight_functions = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:go_highlight_methods")
|
if !exists("g:go_highlight_function_arguments")
|
||||||
let g:go_highlight_methods = 0
|
let g:go_highlight_function_arguments = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("g:go_highlight_function_calls")
|
||||||
|
let g:go_highlight_function_calls = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:go_highlight_fields")
|
if !exists("g:go_highlight_fields")
|
||||||
@@ -96,7 +100,7 @@ if exists("g:go_fold_enable")
|
|||||||
if index(g:go_fold_enable, 'package_comment') == -1
|
if index(g:go_fold_enable, 'package_comment') == -1
|
||||||
let s:fold_package_comment = 0
|
let s:fold_package_comment = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Disabled by default.
|
" Disabled by default.
|
||||||
if index(g:go_fold_enable, 'comment') > -1
|
if index(g:go_fold_enable, 'comment') > -1
|
||||||
let s:fold_comment = 1
|
let s:fold_comment = 1
|
||||||
@@ -200,7 +204,19 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if g:go_highlight_format_strings != 0
|
if g:go_highlight_format_strings != 0
|
||||||
syn match goFormatSpecifier /\([^%]\(%%\)*\)\@<=%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
" [n] notation is valid for specifying explicit argument indexes
|
||||||
|
" 1. Match a literal % not preceded by a %.
|
||||||
|
" 2. Match any number of -, #, 0, space, or +
|
||||||
|
" 3. Match * or [n]* or any number or nothing before a .
|
||||||
|
" 4. Match * or [n]* or any number or nothing after a .
|
||||||
|
" 5. Match [n] or nothing before a verb
|
||||||
|
" 6. Match a formatting verb
|
||||||
|
syn match goFormatSpecifier /\
|
||||||
|
\([^%]\(%%\)*\)\
|
||||||
|
\@<=%[-#0 +]*\
|
||||||
|
\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\
|
||||||
|
\%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\
|
||||||
|
\%(\[\d\+\]\)\=[vTtbcdoqxXUeEfFgGsp]/ contained containedin=goString,goRawString
|
||||||
hi def link goFormatSpecifier goSpecialString
|
hi def link goFormatSpecifier goSpecialString
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -231,14 +247,14 @@ endif
|
|||||||
" var, const
|
" var, const
|
||||||
if s:fold_varconst
|
if s:fold_varconst
|
||||||
syn region goVar start='var (' end='^\s*)$' transparent fold
|
syn region goVar start='var (' end='^\s*)$' transparent fold
|
||||||
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
|
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments
|
||||||
syn region goConst start='const (' end='^\s*)$' transparent fold
|
syn region goConst start='const (' end='^\s*)$' transparent fold
|
||||||
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
|
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments
|
||||||
else
|
else
|
||||||
syn region goVar start='var (' end='^\s*)$' transparent
|
syn region goVar start='var (' end='^\s*)$' transparent
|
||||||
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
|
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments
|
||||||
syn region goConst start='const (' end='^\s*)$' transparent
|
syn region goConst start='const (' end='^\s*)$' transparent
|
||||||
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
|
\ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goArgumentName,goArgumentType,goSimpleArguments
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Single-line var, const, and import.
|
" Single-line var, const, and import.
|
||||||
@@ -345,25 +361,31 @@ endif
|
|||||||
hi def link goOperator Operator
|
hi def link goOperator Operator
|
||||||
|
|
||||||
" Functions;
|
" Functions;
|
||||||
if g:go_highlight_functions != 0
|
if g:go_highlight_functions isnot 0 || g:go_highlight_function_arguments isnot 0
|
||||||
syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction skipwhite skipnl
|
syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleArguments skipwhite skipnl
|
||||||
syn match goReceiver /(\(\w\|[ *]\)\+)/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
|
syn match goReceiverVar /\w\+\ze\s\+\(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
|
||||||
syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
|
|
||||||
syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
|
syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
|
||||||
|
syn match goFunction /\w\+/ nextgroup=goSimpleArguments contained skipwhite skipnl
|
||||||
syn match goReceiverType /\w\+/ contained
|
syn match goReceiverType /\w\+/ contained
|
||||||
syn match goFunction /\w\+/ contained
|
if g:go_highlight_function_arguments isnot 0
|
||||||
syn match goFunctionCall /\w\+\ze(/ contains=GoBuiltins,goDeclaration
|
syn match goSimpleArguments /(\(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goArgumentName nextgroup=goSimpleArguments skipwhite skipnl
|
||||||
|
syn match goArgumentName /\w\+\(\s*,\s*\w\+\)*\ze\s\+\(\w\|\.\|\*\|\[\)/ contained nextgroup=goArgumentType skipwhite skipnl
|
||||||
|
syn match goArgumentType /\([^,)]\|\_s\)\+,\?/ contained nextgroup=goArgumentName skipwhite skipnl
|
||||||
|
\ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock
|
||||||
|
hi def link goReceiverVar goArgumentName
|
||||||
|
hi def link goArgumentName Identifier
|
||||||
|
endif
|
||||||
|
syn match goReceiver /(\s*\w\+\(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
|
||||||
else
|
else
|
||||||
syn keyword goDeclaration func
|
syn keyword goDeclaration func
|
||||||
endif
|
endif
|
||||||
hi def link goFunction Function
|
hi def link goFunction Function
|
||||||
hi def link goFunctionCall Type
|
|
||||||
|
|
||||||
" Methods;
|
" Function calls;
|
||||||
if g:go_highlight_methods != 0
|
if g:go_highlight_function_calls != 0
|
||||||
syn match goMethodCall /\.\w\+\ze(/hs=s+1
|
syn match goFunctionCall /\w\+\ze(/ contains=goBuiltins,goDeclaration
|
||||||
endif
|
endif
|
||||||
hi def link goMethodCall Type
|
hi def link goFunctionCall Type
|
||||||
|
|
||||||
" Fields;
|
" Fields;
|
||||||
if g:go_highlight_fields != 0
|
if g:go_highlight_fields != 0
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ syn keyword htmlArg contained async
|
|||||||
" <content>
|
" <content>
|
||||||
syn keyword htmlArg contained select
|
syn keyword htmlArg contained select
|
||||||
" <iframe>
|
" <iframe>
|
||||||
syn keyword htmlArg contained seamless srcdoc sandbox allowfullscreen allowusermedia allowpaymentrequest
|
syn keyword htmlArg contained seamless srcdoc sandbox allowfullscreen allowusermedia allowpaymentrequest allowpresentation
|
||||||
" <picture>
|
" <picture>
|
||||||
syn keyword htmlArg contained srcset sizes
|
syn keyword htmlArg contained srcset sizes
|
||||||
" <a>
|
" <a>
|
||||||
|
|||||||
@@ -73,10 +73,12 @@ if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
|
|||||||
syn match jsonTrailingCommaError ",\_s*[}\]]"
|
syn match jsonTrailingCommaError ",\_s*[}\]]"
|
||||||
|
|
||||||
" Syntax: Watch out for missing commas between elements
|
" Syntax: Watch out for missing commas between elements
|
||||||
syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
|
syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
|
||||||
syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
|
syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
|
||||||
syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
|
if (expand('%:e') !=? 'jsonl')
|
||||||
syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
|
syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
|
||||||
|
endif
|
||||||
|
syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" ********************************************** END OF ERROR WARNINGS
|
" ********************************************** END OF ERROR WARNINGS
|
||||||
|
|||||||
56
syntax/json5.vim
Normal file
56
syntax/json5.vim
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'json5') == -1
|
||||||
|
|
||||||
|
" Syntax setup {{{1
|
||||||
|
if exists('b:current_syntax') && b:current_syntax == 'json5'
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Syntax: Strings {{{1
|
||||||
|
syn region json5String start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=json5Escape
|
||||||
|
syn region json5String start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=json5Escape
|
||||||
|
|
||||||
|
" Syntax: Escape sequences
|
||||||
|
syn match json5Escape "\\["\\/bfnrt]" contained
|
||||||
|
syn match json5Escape "\\u\x\{4}" contained
|
||||||
|
|
||||||
|
" Syntax: Numbers {{{1
|
||||||
|
syn match json5Number "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
|
||||||
|
syn keyword json5Number Infinity -Infinity
|
||||||
|
|
||||||
|
" Syntax: An integer part of 0 followed by other digits is not allowed.
|
||||||
|
syn match json5NumError "-\=\<0\d\.\d*\>"
|
||||||
|
|
||||||
|
" Syntax: Boolean {{{1
|
||||||
|
syn keyword json5Boolean true false
|
||||||
|
|
||||||
|
" Syntax: Null {{{1
|
||||||
|
syn keyword json5Null null
|
||||||
|
|
||||||
|
" Syntax: Braces {{{1
|
||||||
|
syn match json5Braces "[{}\[\]]"
|
||||||
|
syn match json5ObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/
|
||||||
|
|
||||||
|
" Syntax: Comment {{{1
|
||||||
|
syn region json5LineComment start=+\/\/+ end=+$+ keepend
|
||||||
|
syn region json5LineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold
|
||||||
|
syn region json5Comment start="/\*" end="\*/" fold
|
||||||
|
|
||||||
|
" Define the default highlighting. {{{1
|
||||||
|
hi def link json5String String
|
||||||
|
hi def link json5ObjAssign Identifier
|
||||||
|
hi def link json5Escape Special
|
||||||
|
hi def link json5Number Number
|
||||||
|
hi def link json5Braces Operator
|
||||||
|
hi def link json5Null Function
|
||||||
|
hi def link json5Boolean Boolean
|
||||||
|
hi def link json5LineComment Comment
|
||||||
|
hi def link json5Comment Comment
|
||||||
|
hi def link json5NumError Error
|
||||||
|
|
||||||
|
if !exists('b:current_syntax')
|
||||||
|
let b:current_syntax = 'json5'
|
||||||
|
endif
|
||||||
|
|
||||||
|
" vim: fdm=marker
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -112,13 +112,13 @@ else
|
|||||||
endif
|
endif
|
||||||
syntax cluster juliaTypesItemsAll contains=juliaBaseTypeBasic,juliaBaseTypeNum,juliaBaseTypeC,juliaBaseTypeError,juliaBaseTypeIter,juliaBaseTypeString,juliaBaseTypeArray,juliaBaseTypeDict,juliaBaseTypeSet,juliaBaseTypeIO,juliaBaseTypeProcess,juliaBaseTypeRange,juliaBaseTypeRegex,juliaBaseTypeFact,juliaBaseTypeFact,juliaBaseTypeSort,juliaBaseTypeRound,juliaBaseTypeSpecial,juliaBaseTypeRandom,juliaBaseTypeDisplay,juliaBaseTypeTime,juliaBaseTypeOther
|
syntax cluster juliaTypesItemsAll contains=juliaBaseTypeBasic,juliaBaseTypeNum,juliaBaseTypeC,juliaBaseTypeError,juliaBaseTypeIter,juliaBaseTypeString,juliaBaseTypeArray,juliaBaseTypeDict,juliaBaseTypeSet,juliaBaseTypeIO,juliaBaseTypeProcess,juliaBaseTypeRange,juliaBaseTypeRegex,juliaBaseTypeFact,juliaBaseTypeFact,juliaBaseTypeSort,juliaBaseTypeRound,juliaBaseTypeSpecial,juliaBaseTypeRandom,juliaBaseTypeDisplay,juliaBaseTypeTime,juliaBaseTypeOther
|
||||||
syntax cluster juliaTypesItems05 contains=juliaBaseTypeIter05,juliaBaseTypeRange05
|
syntax cluster juliaTypesItems05 contains=juliaBaseTypeIter05,juliaBaseTypeRange05
|
||||||
syntax cluster juliaTypesItems0506 contains=juliaBaseTypeRange0506,juliaBaseTypeSet0506
|
syntax cluster juliaTypesItems0506 contains=juliaBaseTypeNum0506,juliaBaseTypeRange0506,juliaBaseTypeSet0506
|
||||||
syntax cluster juliaTypesItems0607 contains=juliaBaseTypeBasic0607,juliaBaseTypeArray0607,juliaBaseTypeSet0607,juliaBaseTypeProcess0607,juliaBaseTypeRange0607,juliaBaseTypeTime0607
|
syntax cluster juliaTypesItems0607 contains=juliaBaseTypeBasic0607,juliaBaseTypeArray0607,juliaBaseTypeSet0607,juliaBaseTypeProcess0607,juliaBaseTypeRange0607,juliaBaseTypeTime0607
|
||||||
syntax cluster juliaTypesItems07 contains=juliaBaseTypeRange07,juliaBaseTypeSet07
|
syntax cluster juliaTypesItems07 contains=juliaBaseTypeBasic07,juliaBaseTypeNum07,juliaBaseTypeError07,juliaBaseTypeIter07,juliaBaseTypeRange07,juliaBaseTypeArray07,juliaBaseTypeSet07,juliaBaseTypeC07,juliaBaseTypeDisplay07,juliaBaseTypeIO07
|
||||||
|
|
||||||
syntax cluster juliaConstItemsAll contains=juliaConstNum,juliaConstBool,juliaConstEnv,juliaConstIO,juliaConstMMap,juliaConstC,juliaConstGeneric
|
syntax cluster juliaConstItemsAll contains=juliaConstNum,juliaConstBool,juliaConstEnv,juliaConstIO,juliaConstMMap,juliaConstC,juliaConstGeneric
|
||||||
syntax cluster juliaConstItems0506 contains=juliaConstNum0506
|
syntax cluster juliaConstItems0506 contains=juliaConstNum0506
|
||||||
syntax cluster juliaConstItems07 contains=juliaPossibleEuler
|
syntax cluster juliaConstItems07 contains=juliaConstGeneric07,juliaPossibleEuler
|
||||||
if b:julia_syntax_version <= 6
|
if b:julia_syntax_version <= 6
|
||||||
syntax cluster juliaConstItems contains=@juliaConstItemsAll,@juliaConstItems0506
|
syntax cluster juliaConstItems contains=@juliaConstItemsAll,@juliaConstItems0506
|
||||||
else
|
else
|
||||||
@@ -208,20 +208,28 @@ exec 'syntax match juliaOuter contained "\<outer\ze\s\+' . s:idregex . '\>"
|
|||||||
|
|
||||||
syntax match juliaBaseTypeBasic display "\<\%(Tuple\|NTuple\|Symbol\|\%(Intrinsic\)\?Function\|Union\|Type\%(Name\|Constructor\|Var\)\?\|Any\|ANY\|Vararg\|Top\|None\|Nothing\|Ptr\|Void\|Exception\|Module\|Box\|Expr\|LambdaStaticData\|\%(Data\|Union\)Type\|\%(LineNumber\|Label\|Goto\|Quote\|Top\|Symbol\|Getfield\)Node\|\%(Weak\|Global\)\?Ref\|Associative\|Method\(Table\)\?\|GetfieldNode\|Nullable\|Pair\|Val\|TypeMap\%(Level\|Entry\)\)\>"
|
syntax match juliaBaseTypeBasic display "\<\%(Tuple\|NTuple\|Symbol\|\%(Intrinsic\)\?Function\|Union\|Type\%(Name\|Constructor\|Var\)\?\|Any\|ANY\|Vararg\|Top\|None\|Nothing\|Ptr\|Void\|Exception\|Module\|Box\|Expr\|LambdaStaticData\|\%(Data\|Union\)Type\|\%(LineNumber\|Label\|Goto\|Quote\|Top\|Symbol\|Getfield\)Node\|\%(Weak\|Global\)\?Ref\|Associative\|Method\(Table\)\?\|GetfieldNode\|Nullable\|Pair\|Val\|TypeMap\%(Level\|Entry\)\)\>"
|
||||||
syntax match juliaBaseTypeBasic0607 display "\<\%(UnionAll\|CodeInfo\)\>"
|
syntax match juliaBaseTypeBasic0607 display "\<\%(UnionAll\|CodeInfo\)\>"
|
||||||
syntax match juliaBaseTypeNum display "\<\%(U\?Int\%(8\|16\|32\|64\|128\)\?\|Float\%(16\|32\|64\)\|Complex\%(32\|64\|128\)\?\|Bool\|Char\|Number\|Signed\|Unsigned\|Integer\|AbstractFloat\|Real\|Rational\|Irrational\|Enum\|BigInt\|BigFloat\|MathConst\)\>"
|
syntax match juliaBaseTypeBasic07 display "\<\%(Some\|Missing\)\>"
|
||||||
|
syntax match juliaBaseTypeNum display "\<\%(U\?Int\%(8\|16\|32\|64\|128\)\?\|Float\%(16\|32\|64\)\|Complex\|Bool\|Char\|Number\|Signed\|Unsigned\|Integer\|AbstractFloat\|Real\|Rational\|Irrational\|Enum\|BigInt\|BigFloat\|MathConst\)\>"
|
||||||
|
syntax match juliaBaseTypeNum0506 display "\<Complex\%(32\|64\|128\)\>"
|
||||||
|
syntax match juliaBaseTypeNum07 display "\<\%(AbstractIrrational\|ComplexF\%(16\|32\|64\)\)\>"
|
||||||
syntax match juliaBaseTypeC display "\<\%(FileOffset\|C\%(u\?\%(char\|short\|int\|long\(long\)\?\|w\?string\)\|float\|double\|\%(ptrdiff\|s\?size\|wchar\|off\|u\?intmax\)_t\)\)\>"
|
syntax match juliaBaseTypeC display "\<\%(FileOffset\|C\%(u\?\%(char\|short\|int\|long\(long\)\?\|w\?string\)\|float\|double\|\%(ptrdiff\|s\?size\|wchar\|off\|u\?intmax\)_t\)\)\>"
|
||||||
|
syntax match juliaBaseTypeC07 display "\<Cvoid\>"
|
||||||
syntax match juliaBaseTypeError display "\<\%(\%(Bounds\|Divide\|Domain\|\%(Stack\)\?Overflow\|EOF\|Undef\%(Ref\|Var\)\|System\|Type\|Parse\|Argument\|Key\|Load\|Method\|Inexact\|OutOfMemory\|Init\|Assertion\|Unicode\|ReadOnlyMemory\)Error\|\%(Interrupt\|Error\|ProcessExited\|Captured\|Composite\|InvalidState\|Null\|Remote\)Exception\|DimensionMismatch\|SegmentationFault\)\>"
|
syntax match juliaBaseTypeError display "\<\%(\%(Bounds\|Divide\|Domain\|\%(Stack\)\?Overflow\|EOF\|Undef\%(Ref\|Var\)\|System\|Type\|Parse\|Argument\|Key\|Load\|Method\|Inexact\|OutOfMemory\|Init\|Assertion\|Unicode\|ReadOnlyMemory\)Error\|\%(Interrupt\|Error\|ProcessExited\|Captured\|Composite\|InvalidState\|Null\|Remote\)Exception\|DimensionMismatch\|SegmentationFault\)\>"
|
||||||
|
syntax match juliaBaseTypeError07 display "\<\%(StringIndexError\|MissingException\)\>"
|
||||||
syntax match juliaBaseTypeIter display "\<\%(EachLine\|Enumerate\|Cartesian\%(Index\|Range\)\|LinSpace\)\>"
|
syntax match juliaBaseTypeIter display "\<\%(EachLine\|Enumerate\|Cartesian\%(Index\|Range\)\|LinSpace\)\>"
|
||||||
syntax match juliaBaseTypeIter05 display "\<\%(Zip\|Filter\)\>"
|
syntax match juliaBaseTypeIter05 display "\<\%(Zip\|Filter\)\>"
|
||||||
|
syntax match juliaBaseTypeIter07 display "\<CartesianIndices\>"
|
||||||
syntax match juliaBaseTypeString display "\<\%(DirectIndex\|Sub\|Rep\|Rev\|Abstract\)\?String\>"
|
syntax match juliaBaseTypeString display "\<\%(DirectIndex\|Sub\|Rep\|Rev\|Abstract\)\?String\>"
|
||||||
syntax match juliaBaseTypeArray display "\<\%(\%(Sub\)\?Array\|\%(Abstract\|Dense\|Strided\)\?\%(Array\|Matrix\|Vec\%(tor\|OrMat\)\)\|SparseMatrixCSC\|\%(AbstractSparse\|Bit\|Shared\)\%(Array\|Vector\|Matrix\)\|\%\(D\|Bid\|\%(Sym\)\?Trid\)iagonal\|Hermitian\|Symmetric\|UniformScaling\|\%(Lower\|Upper\)Triangular\|SparseVector\|VecElement\)\>"
|
syntax match juliaBaseTypeArray display "\<\%(\%(Sub\)\?Array\|\%(Abstract\|Dense\|Strided\)\?\%(Array\|Matrix\|Vec\%(tor\|OrMat\)\)\|SparseMatrixCSC\|\%(AbstractSparse\|Bit\|Shared\)\%(Array\|Vector\|Matrix\)\|\%\(D\|Bid\|\%(Sym\)\?Trid\)iagonal\|Hermitian\|Symmetric\|UniformScaling\|\%(Lower\|Upper\)Triangular\|SparseVector\|VecElement\)\>"
|
||||||
syntax match juliaBaseTypeArray0607 display "\<\%(Conj\%(Array\|Matrix\|Vector\)\|Index\%(Cartesian\|Linear\|Style\)\|PermutedDimsArray\|RowVector\)\>"
|
syntax match juliaBaseTypeArray0607 display "\<\%(Conj\%(Array\|Matrix\|Vector\)\|Index\%(Cartesian\|Linear\|Style\)\|PermutedDimsArray\|RowVector\)\>"
|
||||||
|
syntax match juliaBaseTypeArray07 display "\<\%(BroadcastStyle\|Adjoint\|Transpose\|LinearIndices\)\>"
|
||||||
syntax match juliaBaseTypeDict display "\<\%(WeakKey\|ObjectId\)\?Dict\>"
|
syntax match juliaBaseTypeDict display "\<\%(WeakKey\|ObjectId\)\?Dict\>"
|
||||||
syntax match juliaBaseTypeSet display "\<Set\>"
|
syntax match juliaBaseTypeSet display "\<Set\>"
|
||||||
syntax match juliaBaseTypeSet0506 display "\<IntSet\>"
|
syntax match juliaBaseTypeSet0506 display "\<IntSet\>"
|
||||||
syntax match juliaBaseTypeSet0607 display "\<AbstractSet\>"
|
syntax match juliaBaseTypeSet0607 display "\<AbstractSet\>"
|
||||||
syntax match juliaBaseTypeSet07 display "\<BitSet\>"
|
syntax match juliaBaseTypeSet07 display "\<\%(\%(Bit\|Key\)Set\|AbstractDict\)\>"
|
||||||
syntax match juliaBaseTypeIO display "\<\%(IO\%(Stream\|Buffer\|Context\)\?\|RawFD\|StatStruct\|DevNull\|FileMonitor\|PollingFileWatcher\|Timer\|Base64\%(Decode\|Encode\)Pipe\|\%(UDP\|TCP\)Socket\|\%(Abstract\)\?Channel\|BufferStream\|ReentrantLock\)\>"
|
syntax match juliaBaseTypeIO display "\<\%(IO\%(Stream\|Buffer\|Context\)\?\|RawFD\|StatStruct\|FileMonitor\|PollingFileWatcher\|Timer\|Base64\%(Decode\|Encode\)Pipe\|\%(UDP\|TCP\)Socket\|\%(Abstract\)\?Channel\|BufferStream\|ReentrantLock\)\>"
|
||||||
|
syntax match juliaBaseTypeIO07 display "\<GenericIOBuffer\>"
|
||||||
syntax match juliaBaseTypeProcess display "\<\%(ProcessGroup\|Pipe\|Cmd\)\>"
|
syntax match juliaBaseTypeProcess display "\<\%(ProcessGroup\|Pipe\|Cmd\)\>"
|
||||||
syntax match juliaBaseTypeProcess0607 display "\<PipeBuffer\>"
|
syntax match juliaBaseTypeProcess0607 display "\<PipeBuffer\>"
|
||||||
syntax match juliaBaseTypeRange display "\<\%(Dims\|RangeIndex\|\%(Ordinal\|Step\|\%(Abstract\)\?Unit\)Range\|Colon\)\>"
|
syntax match juliaBaseTypeRange display "\<\%(Dims\|RangeIndex\|\%(Ordinal\|Step\|\%(Abstract\)\?Unit\)Range\|Colon\)\>"
|
||||||
@@ -236,6 +244,7 @@ syntax match juliaBaseTypeRound display "\<Round\%(ingMode\|FromZero\|Down\|Ne
|
|||||||
syntax match juliaBaseTypeSpecial display "\<\%(LocalProcess\|ClusterManager\)\>"
|
syntax match juliaBaseTypeSpecial display "\<\%(LocalProcess\|ClusterManager\)\>"
|
||||||
syntax match juliaBaseTypeRandom display "\<\%(AbstractRNG\|MersenneTwister\|RandomDevice\)\>"
|
syntax match juliaBaseTypeRandom display "\<\%(AbstractRNG\|MersenneTwister\|RandomDevice\)\>"
|
||||||
syntax match juliaBaseTypeDisplay display "\<\%(Text\(Display\)\?\|Display\|MIME\|HTML\)\>"
|
syntax match juliaBaseTypeDisplay display "\<\%(Text\(Display\)\?\|Display\|MIME\|HTML\)\>"
|
||||||
|
syntax match juliaBaseTypeDisplay07 display "\<AbstractDisplay\>"
|
||||||
syntax match juliaBaseTypeTime display "\<\%(Date\%(Time\)\?\)\>"
|
syntax match juliaBaseTypeTime display "\<\%(Date\%(Time\)\?\)\>"
|
||||||
syntax match juliaBaseTypeTime0607 display "\<DateFormat\>"
|
syntax match juliaBaseTypeTime0607 display "\<DateFormat\>"
|
||||||
syntax match juliaBaseTypeOther display "\<\%(RemoteRef\|Task\|Condition\|VersionNumber\|IPv[46]\|SerializationState\|WorkerConfig\|Future\|RemoteChannel\|IPAddr\|Stack\%(Trace\|Frame\)\|\(Caching\|Worker\)Pool\|AbstractSerializer\)\>"
|
syntax match juliaBaseTypeOther display "\<\%(RemoteRef\|Task\|Condition\|VersionNumber\|IPv[46]\|SerializationState\|WorkerConfig\|Future\|RemoteChannel\|IPAddr\|Stack\%(Trace\|Frame\)\|\(Caching\|Worker\)Pool\|AbstractSerializer\)\>"
|
||||||
@@ -251,9 +260,10 @@ syntax match juliaPossibleEuler "ℯ" contains=juliaEuler
|
|||||||
exec 'syntax match juliaEuler contained "\%(\%(^\|[' . s:nonidS_chars . ']\|' . s:operators . '\)\%([.0-9eEf_]*\d\)\?\)\@'.s:d(80).'<=ℯ\ze\%($\|[' . s:nonidS_chars . ']\|' . s:operators . '\)"'
|
exec 'syntax match juliaEuler contained "\%(\%(^\|[' . s:nonidS_chars . ']\|' . s:operators . '\)\%([.0-9eEf_]*\d\)\?\)\@'.s:d(80).'<=ℯ\ze\%($\|[' . s:nonidS_chars . ']\|' . s:operators . '\)"'
|
||||||
syntax match juliaConstBool display "\<\%(true\|false\)\>"
|
syntax match juliaConstBool display "\<\%(true\|false\)\>"
|
||||||
syntax match juliaConstEnv display "\<\%(ARGS\|ENV\|CPU_CORES\|OS_NAME\|ENDIAN_BOM\|LOAD_PATH\|VERSION\|JULIA_HOME\|PROGRAM_FILE\)\>"
|
syntax match juliaConstEnv display "\<\%(ARGS\|ENV\|CPU_CORES\|OS_NAME\|ENDIAN_BOM\|LOAD_PATH\|VERSION\|JULIA_HOME\|PROGRAM_FILE\)\>"
|
||||||
syntax match juliaConstIO display "\<\%(STD\%(OUT\|IN\|ERR\)\)\>"
|
syntax match juliaConstIO display "\<\%(STD\%(OUT\|IN\|ERR\)\|DevNull\)\>"
|
||||||
syntax match juliaConstC display "\<\%(WORD_SIZE\|C_NULL\)\>"
|
syntax match juliaConstC display "\<\%(WORD_SIZE\|C_NULL\)\>"
|
||||||
syntax match juliaConstGeneric display "\<\%(nothing\|Main\)\>"
|
syntax match juliaConstGeneric display "\<\%(nothing\|Main\)\>"
|
||||||
|
syntax match juliaConstGeneric07 display "\<missing\>"
|
||||||
|
|
||||||
syntax match juliaPossibleMacro transparent "@" contains=juliaMacroCall,juliaMacroCallP,juliaPrintfMacro
|
syntax match juliaPossibleMacro transparent "@" contains=juliaMacroCall,juliaMacroCallP,juliaPrintfMacro
|
||||||
|
|
||||||
@@ -442,11 +452,11 @@ for t in ["Iter", "Range"]
|
|||||||
let h = b:julia_syntax_version == 5 ? "Type" : b:julia_syntax_version == 6 ? "juliaDeprecated" : "NONE"
|
let h = b:julia_syntax_version == 5 ? "Type" : b:julia_syntax_version == 6 ? "juliaDeprecated" : "NONE"
|
||||||
exec "hi! def link juliaBaseType" . t . "05 " . h
|
exec "hi! def link juliaBaseType" . t . "05 " . h
|
||||||
endfor
|
endfor
|
||||||
for t in ["Range", "Set"]
|
for t in ["Num", "Range", "Set"]
|
||||||
let h = b:julia_syntax_version <= 6 ? "Type" : "juliaDeprecated"
|
let h = b:julia_syntax_version <= 6 ? "Type" : "juliaDeprecated"
|
||||||
exec "hi! def link juliaBaseType" . t . "0506 " . h
|
exec "hi! def link juliaBaseType" . t . "0506 " . h
|
||||||
endfor
|
endfor
|
||||||
for t in ["Range", "Set"]
|
for t in ["Range", "Set", "Basic", "C", "Array", "Iter", "Display", "IO", "Num", "Error"]
|
||||||
let h = b:julia_syntax_version >= 7 ? "Type" : "NONE"
|
let h = b:julia_syntax_version >= 7 ? "Type" : "NONE"
|
||||||
exec "hi! def link juliaBaseType" . t . "07 " . h
|
exec "hi! def link juliaBaseType" . t . "07 " . h
|
||||||
endfor
|
endfor
|
||||||
@@ -469,6 +479,9 @@ hi def link juliaConstGeneric Constant
|
|||||||
hi def link juliaRangeEnd Constant
|
hi def link juliaRangeEnd Constant
|
||||||
hi def link juliaConstBool Boolean
|
hi def link juliaConstBool Boolean
|
||||||
|
|
||||||
|
let h = b:julia_syntax_version >= 7 ? "Constant" : "NONE"
|
||||||
|
exec "hi! def link juliaConstGeneric07 " . h
|
||||||
|
|
||||||
hi def link juliaComprehensionFor Keyword
|
hi def link juliaComprehensionFor Keyword
|
||||||
hi def link juliaComprehensionIf Keyword
|
hi def link juliaComprehensionIf Keyword
|
||||||
|
|
||||||
|
|||||||
13
syntax/latextoc.vim
Normal file
13
syntax/latextoc.vim
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
|
||||||
|
|
||||||
|
syntax match helpText /^.*: .*/
|
||||||
|
syntax match secNum /^\S\+\(\.\S\+\)\?\s*/ contained conceal
|
||||||
|
syntax match secLine /^\S\+\t.\+/ contains=secNum
|
||||||
|
syntax match mainSecLine /^[^\.]\+\t.*/ contains=secNum
|
||||||
|
syntax match ssubSecLine /^[^\.]\+\.[^\.]\+\.[^\.]\+\t.*/ contains=secNum
|
||||||
|
highlight link helpText PreProc
|
||||||
|
highlight link secNum Number
|
||||||
|
highlight link mainSecLine Title
|
||||||
|
highlight link ssubSecLine Comment
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -110,11 +110,9 @@ syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ containe
|
|||||||
syn match mkdListItem /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained
|
syn match mkdListItem /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained
|
||||||
syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
|
syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
|
||||||
syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
|
syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
|
||||||
syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
|
syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*\(\*\|\s\)*$/
|
||||||
syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
|
syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-\(-\|\s\)*$/
|
||||||
syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
|
syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_\(_\|\s\)*$/
|
||||||
syn match mkdRule /^\s*-\{3,}$/
|
|
||||||
syn match mkdRule /^\s*\*\{3,5}$/
|
|
||||||
|
|
||||||
" YAML frontmatter
|
" YAML frontmatter
|
||||||
if get(g:, 'vim_markdown_frontmatter', 0)
|
if get(g:, 'vim_markdown_frontmatter', 0)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ syntax match plantumlHorizontalArrow /\%([-\.]\%(|>\|>\|\*\|o\>\|\\\\\|\\\|\/\/\
|
|||||||
syntax match plantumlDirectedOrVerticalArrowLR /[-\.]\%(le\?f\?t\?\|ri\?g\?h\?t\?\|up\?\|do\?w\?n\?\)\?[-\.]\%(|>\|>>\|>\|\*\|o\>\|\\\\\|\\\|\/\/\|\/\|\.\|-\)\%(\[[^\]]*\]\)\?/ contains=plantumlLabel
|
syntax match plantumlDirectedOrVerticalArrowLR /[-\.]\%(le\?f\?t\?\|ri\?g\?h\?t\?\|up\?\|do\?w\?n\?\)\?[-\.]\%(|>\|>>\|>\|\*\|o\>\|\\\\\|\\\|\/\/\|\/\|\.\|-\)\%(\[[^\]]*\]\)\?/ contains=plantumlLabel
|
||||||
syntax match plantumlDirectedOrVerticalArrowRL /\%(<|\|<<\|<\|\*\|\<o\|\\\\\|\\\|\/\/\|\/\)[-\.]\%(le\?f\?t\?\|ri\?g\?h\?t\?\|up\?\|do\?w\?n\?\)\?[-\.]\%(\[[^\]]*\]\)\?/ contains=plantumlLabel
|
syntax match plantumlDirectedOrVerticalArrowRL /\%(<|\|<<\|<\|\*\|\<o\|\\\\\|\\\|\/\/\|\/\)[-\.]\%(le\?f\?t\?\|ri\?g\?h\?t\?\|up\?\|do\?w\?n\?\)\?[-\.]\%(\[[^\]]*\]\)\?/ contains=plantumlLabel
|
||||||
syntax region plantumlLabel start=/\[/ms=s+1 end=/\]/me=s-1 contained contains=plantumlText
|
syntax region plantumlLabel start=/\[/ms=s+1 end=/\]/me=s-1 contained contains=plantumlText
|
||||||
syntax match plantumlText /\%([0-9A-Za-zÀ-ÿ]\|\s\|[\.,;_-]\)\+/ contained
|
syntax match plantumlText /\%([0-9A-Za-z\0xc0-\0xff]\|\s\|[\.,;_-]\)\+/ contained
|
||||||
|
|
||||||
" Note
|
" Note
|
||||||
syntax region plantumlNoteMultiLine start=/\%(^\s*[rh]\?note\)\@<=\s\%([^:"]\+$\)\@=/ end=/^\%(\s*end \?[rh]\?note$\)\@=/ contains=plantumlSpecialString,plantumlNoteMultiLineStart
|
syntax region plantumlNoteMultiLine start=/\%(^\s*[rh]\?note\)\@<=\s\%([^:"]\+$\)\@=/ end=/^\%(\s*end \?[rh]\?note$\)\@=/ contains=plantumlSpecialString,plantumlNoteMultiLineStart
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ syn keyword pbRepeat optional required repeated
|
|||||||
syn keyword pbDefault default
|
syn keyword pbDefault default
|
||||||
syn keyword pbExtend extend extensions to max reserved
|
syn keyword pbExtend extend extensions to max reserved
|
||||||
syn keyword pbRPC service rpc returns
|
syn keyword pbRPC service rpc returns
|
||||||
|
syn keyword pbStream stream
|
||||||
|
|
||||||
syn keyword pbType int32 int64 uint32 uint64 sint32 sint64
|
syn keyword pbType int32 int64 uint32 uint64 sint32 sint64
|
||||||
syn keyword pbType fixed32 fixed64 sfixed32 sfixed64
|
syn keyword pbType fixed32 fixed64 sfixed32 sfixed64
|
||||||
@@ -92,6 +93,7 @@ if version >= 508 || !exists("did_proto_syn_inits")
|
|||||||
HiLink pbDefault Keyword
|
HiLink pbDefault Keyword
|
||||||
HiLink pbExtend Keyword
|
HiLink pbExtend Keyword
|
||||||
HiLink pbRPC Keyword
|
HiLink pbRPC Keyword
|
||||||
|
HiLink pbStream Keyword
|
||||||
HiLink pbType Type
|
HiLink pbType Type
|
||||||
HiLink pbTypedef Typedef
|
HiLink pbTypedef Typedef
|
||||||
HiLink pbBool Boolean
|
HiLink pbBool Boolean
|
||||||
|
|||||||
@@ -1,326 +1,487 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
||||||
|
|
||||||
" Vim syntax file
|
|
||||||
"
|
|
||||||
" Based on python.vim (from Vim 6.1 distribution)
|
|
||||||
" by Neil Schemenauer <nas@python.ca>
|
|
||||||
"
|
|
||||||
" Notes Armin:
|
|
||||||
"
|
|
||||||
" This version of the syntax file works better for 2.x and 3.x without
|
|
||||||
" having to switch modes.
|
|
||||||
"
|
|
||||||
" Thanks:
|
|
||||||
"
|
|
||||||
" Jeroen Ruigrok van der Werven
|
|
||||||
" for the idea of highlighting for erroneous operators
|
|
||||||
" Pedro Algarvio
|
|
||||||
" for the patch to enable spell checking only for the right spots
|
|
||||||
" (strings and comments)
|
|
||||||
|
|
||||||
"
|
|
||||||
" Options:
|
|
||||||
"
|
|
||||||
" For set option do: let OPTION_NAME = 1
|
|
||||||
" For clear option do: let OPTION_NAME = 0
|
|
||||||
"
|
|
||||||
" Option names:
|
|
||||||
"
|
|
||||||
" For highlight builtin functions:
|
|
||||||
" python_highlight_builtins
|
|
||||||
"
|
|
||||||
" For highlight standard exceptions:
|
|
||||||
" python_highlight_exceptions
|
|
||||||
"
|
|
||||||
" For highlight string formatting:
|
|
||||||
" python_highlight_string_formatting
|
|
||||||
"
|
|
||||||
" For highlight indentation errors:
|
|
||||||
" python_highlight_indent_errors
|
|
||||||
"
|
|
||||||
" For highlight trailing spaces:
|
|
||||||
" python_highlight_space_errors
|
|
||||||
"
|
|
||||||
" For highlight doc-tests:
|
|
||||||
" python_highlight_doctests
|
|
||||||
"
|
|
||||||
" If you want all possible Python highlighting:
|
|
||||||
" (This option not override previously set options)
|
|
||||||
" python_highlight_all
|
|
||||||
"
|
|
||||||
" For fast machines:
|
|
||||||
" python_slow_sync
|
|
||||||
"
|
|
||||||
|
|
||||||
" For version 5.x: Clear all syntax items
|
" For version 5.x: Clear all syntax items
|
||||||
" For version 6.x: Quit when a syntax file was already loaded
|
" For versions greater than 6.x: Quit when a syntax file was already loaded
|
||||||
if version < 600
|
if v:version < 600
|
||||||
syntax clear
|
syntax clear
|
||||||
elseif exists("b:current_syntax")
|
elseif exists('b:current_syntax')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_highlight_all") && python_highlight_all != 0
|
"
|
||||||
" Not override previously set options
|
" Commands
|
||||||
if !exists("python_highlight_builtins")
|
"
|
||||||
let python_highlight_builtins = 1
|
command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax
|
||||||
|
command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax
|
||||||
|
|
||||||
|
" Enable option if it's not defined
|
||||||
|
function! s:EnableByDefault(name)
|
||||||
|
if !exists(a:name)
|
||||||
|
let {a:name} = 1
|
||||||
endif
|
endif
|
||||||
if !exists("python_highlight_exceptions")
|
endfunction
|
||||||
let python_highlight_exceptions = 1
|
|
||||||
|
" Check if option is enabled
|
||||||
|
function! s:Enabled(name)
|
||||||
|
return exists(a:name) && {a:name}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is it Python 2 syntax?
|
||||||
|
function! s:Python2Syntax()
|
||||||
|
if exists('b:python_version_2')
|
||||||
|
return b:python_version_2
|
||||||
endif
|
endif
|
||||||
if !exists("python_highlight_string_formatting")
|
return s:Enabled('g:python_version_2')
|
||||||
let python_highlight_string_formatting = 1
|
endfunction
|
||||||
endif
|
|
||||||
if !exists("python_highlight_indent_errors")
|
"
|
||||||
let python_highlight_indent_errors = 1
|
" Default options
|
||||||
endif
|
"
|
||||||
if !exists("python_highlight_space_errors")
|
|
||||||
let python_highlight_space_errors = 1
|
call s:EnableByDefault('g:python_slow_sync')
|
||||||
endif
|
call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg')
|
||||||
if !exists("python_highlight_doctests")
|
|
||||||
let python_highlight_doctests = 1
|
if s:Enabled('g:python_highlight_all')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtins')
|
||||||
|
if s:Enabled('g:python_highlight_builtins')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtin_objs')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtin_funcs')
|
||||||
endif
|
endif
|
||||||
|
call s:EnableByDefault('g:python_highlight_exceptions')
|
||||||
|
call s:EnableByDefault('g:python_highlight_string_formatting')
|
||||||
|
call s:EnableByDefault('g:python_highlight_string_format')
|
||||||
|
call s:EnableByDefault('g:python_highlight_string_templates')
|
||||||
|
call s:EnableByDefault('g:python_highlight_indent_errors')
|
||||||
|
call s:EnableByDefault('g:python_highlight_space_errors')
|
||||||
|
call s:EnableByDefault('g:python_highlight_doctests')
|
||||||
|
call s:EnableByDefault('g:python_print_as_function')
|
||||||
|
call s:EnableByDefault('g:python_highlight_class_vars')
|
||||||
|
call s:EnableByDefault('g:python_highlight_operators')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
" Keywords
|
" Keywords
|
||||||
syn keyword pythonStatement break continue del
|
"
|
||||||
syn keyword pythonStatement exec return
|
|
||||||
syn keyword pythonStatement pass raise
|
|
||||||
syn keyword pythonStatement global assert
|
|
||||||
syn keyword pythonStatement lambda yield
|
|
||||||
syn keyword pythonStatement async await
|
|
||||||
syn keyword pythonStatement with nonlocal True False None
|
|
||||||
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
|
||||||
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
|
|
||||||
syn keyword pythonRepeat for while
|
|
||||||
syn keyword pythonConditional if elif else
|
|
||||||
syn keyword pythonImport import from as
|
|
||||||
syn keyword pythonException try except finally
|
|
||||||
syn keyword pythonOperator and in is not or
|
|
||||||
|
|
||||||
" Print keyword but only if not used as function
|
syn keyword pythonStatement break continue del return pass yield global assert lambda with
|
||||||
syn match pythonStatement "\<print\>\((\|,\|*=\)\@!" display
|
syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite
|
||||||
|
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
||||||
|
if s:Enabled('g:python_highlight_class_vars')
|
||||||
|
syn keyword pythonClassVar self cls
|
||||||
|
endif
|
||||||
|
syn keyword pythonRepeat for while
|
||||||
|
syn keyword pythonConditional if elif else
|
||||||
|
syn keyword pythonException try except finally
|
||||||
|
" The standard pyrex.vim unconditionally removes the pythonInclude group, so
|
||||||
|
" we provide a dummy group here to avoid crashing pyrex.vim.
|
||||||
|
syn keyword pythonInclude import
|
||||||
|
syn keyword pythonImport import
|
||||||
|
syn match pythonRaiseFromStatement '\<from\>'
|
||||||
|
syn match pythonImport '^\s*\zsfrom\>'
|
||||||
|
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
if !s:Enabled('g:python_print_as_function')
|
||||||
|
syn keyword pythonStatement print
|
||||||
|
endif
|
||||||
|
syn keyword pythonStatement exec
|
||||||
|
syn keyword pythonImport as
|
||||||
|
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained
|
||||||
|
else
|
||||||
|
syn keyword pythonStatement as nonlocal
|
||||||
|
syn match pythonStatement '\v\.@<!<await>'
|
||||||
|
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
|
||||||
|
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
|
||||||
|
syn match pythonStatement '\<async\s\+with\>'
|
||||||
|
syn match pythonStatement '\<async\s\+for\>'
|
||||||
|
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
"
|
||||||
|
" Operators
|
||||||
|
"
|
||||||
|
syn keyword pythonOperator and in is not or
|
||||||
|
if s:Enabled('g:python_highlight_operators')
|
||||||
|
syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!='
|
||||||
|
endif
|
||||||
|
syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[<!>]\+=\{2,}\|!\{2,}=\+' display
|
||||||
|
|
||||||
|
"
|
||||||
" Decorators (new in Python 2.4)
|
" Decorators (new in Python 2.4)
|
||||||
syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
|
"
|
||||||
|
|
||||||
|
syn match pythonDecorator '^\s*\zs@' display nextgroup=pythonDottedName skipwhite
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained
|
||||||
|
else
|
||||||
|
syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained
|
||||||
|
endif
|
||||||
|
syn match pythonDot '\.' display containedin=pythonDottedName
|
||||||
|
|
||||||
|
"
|
||||||
" Comments
|
" Comments
|
||||||
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
"
|
||||||
syn match pythonRun "\%^#!.*$"
|
|
||||||
syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
|
||||||
syn keyword pythonTodo TODO FIXME XXX contained
|
|
||||||
|
|
||||||
|
syn match pythonComment '#.*$' display contains=pythonTodo,@Spell
|
||||||
|
if !s:Enabled('g:python_highlight_file_headers_as_comments')
|
||||||
|
syn match pythonRun '\%^#!.*$'
|
||||||
|
syn match pythonCoding '\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$'
|
||||||
|
endif
|
||||||
|
syn keyword pythonTodo TODO FIXME XXX contained
|
||||||
|
|
||||||
|
"
|
||||||
" Errors
|
" Errors
|
||||||
syn match pythonError "\<\d\+\D\+\>" display
|
"
|
||||||
syn match pythonError "[$?]" display
|
|
||||||
syn match pythonError "[-+&|]\{2,}" display
|
|
||||||
syn match pythonError "[=]\{3,}" display
|
|
||||||
|
|
||||||
" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
|
syn match pythonError '\<\d\+[^0-9[:space:]]\+\>' display
|
||||||
" statements. For now I don't know how to work around this.
|
|
||||||
if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
|
" Mixing spaces and tabs also may be used for pretty formatting multiline
|
||||||
syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
|
" statements
|
||||||
|
if s:Enabled('g:python_highlight_indent_errors')
|
||||||
|
syn match pythonIndentError '^\s*\%( \t\|\t \)\s*\S'me=e-1 display
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Trailing space errors
|
" Trailing space errors
|
||||||
if exists("python_highlight_space_errors") && python_highlight_space_errors != 0
|
if s:Enabled('g:python_highlight_space_errors')
|
||||||
syn match pythonSpaceError "\s\+$" display
|
syn match pythonSpaceError '\s\+$' display
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
" Strings
|
" Strings
|
||||||
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
"
|
||||||
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
||||||
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
|
if s:Python2Syntax()
|
||||||
syn match pythonEscape "\\\o\o\=\o\=" display contained
|
" Python 2 strings
|
||||||
syn match pythonEscapeError "\\\o\{,2}[89]" display contained
|
syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
syn match pythonEscape "\\x\x\{2}" display contained
|
syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
syn match pythonEscapeError "\\x\x\=\X" display contained
|
syn region pythonString start=+[bB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
syn match pythonEscape "\\$"
|
syn region pythonString start=+[bB]\='''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
else
|
||||||
|
" Python 3 byte strings
|
||||||
|
syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
|
||||||
|
syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
|
||||||
|
syn region pythonBytes start=+[bB]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
" Byte-Strings
|
syn match pythonBytesError '.\+' display contained
|
||||||
syn region pythonBString start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError
|
||||||
syn region pythonBString start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
|
||||||
syn region pythonBString start=+[bB]"""+ end=+"""+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonBString start=+[bB]'''+ end=+'''+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonBEscape +\\[abfnrtv'"\\]+ display contained
|
|
||||||
syn match pythonBEscape "\\\o\o\=\o\=" display contained
|
|
||||||
syn match pythonBEscapeError "\\\o\{,2}[89]" display contained
|
|
||||||
syn match pythonBEscape "\\x\x\{2}" display contained
|
|
||||||
syn match pythonBEscapeError "\\x\x\=\X" display contained
|
|
||||||
syn match pythonBEscape "\\$"
|
|
||||||
|
|
||||||
" Unicode strings
|
|
||||||
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
||||||
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
|
|
||||||
syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonUniEscape "\\u\x\{4}" display contained
|
|
||||||
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
|
|
||||||
syn match pythonUniEscape "\\U\x\{8}" display contained
|
|
||||||
syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
|
|
||||||
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
|
|
||||||
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
|
|
||||||
|
|
||||||
" Raw strings
|
|
||||||
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
|
||||||
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
|
||||||
syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonRawEscape +\\['"]+ display transparent contained
|
|
||||||
|
|
||||||
" Unicode raw strings
|
|
||||||
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
|
||||||
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
|
||||||
syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
|
|
||||||
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
|
|
||||||
|
|
||||||
if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
|
|
||||||
" String formatting
|
|
||||||
syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
|
||||||
syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_highlight_doctests") && python_highlight_doctests != 0
|
syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
|
||||||
|
syn match pythonBytesEscape '\\\o\o\=\o\=' display contained
|
||||||
|
syn match pythonBytesEscapeError '\\\o\{,2}[89]' display contained
|
||||||
|
syn match pythonBytesEscape '\\x\x\{2}' display contained
|
||||||
|
syn match pythonBytesEscapeError '\\x\x\=\X' display contained
|
||||||
|
syn match pythonBytesEscape '\\$'
|
||||||
|
|
||||||
|
syn match pythonUniEscape '\\u\x\{4}' display contained
|
||||||
|
syn match pythonUniEscapeError '\\u\x\{,3}\X' display contained
|
||||||
|
syn match pythonUniEscape '\\U\x\{8}' display contained
|
||||||
|
syn match pythonUniEscapeError '\\U\x\{,7}\X' display contained
|
||||||
|
syn match pythonUniEscape '\\N{[A-Z ]\+}' display contained
|
||||||
|
syn match pythonUniEscapeError '\\N{[^A-Z ]\+}' display contained
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
" Python 2 Unicode strings
|
||||||
|
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
else
|
||||||
|
" Python 3 strings
|
||||||
|
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
" Python 2 Unicode raw strings
|
||||||
|
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
||||||
|
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
||||||
|
syn region pythonUniRawString start=+[uU][rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn match pythonUniRawEscape '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{4}' display contained
|
||||||
|
syn match pythonUniRawEscapeError '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{,3}\X' display contained
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Python 2/3 raw strings
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawString start=+[bB]\=[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
else
|
||||||
|
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawString start=+[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
endif
|
||||||
|
|
||||||
|
syn match pythonRawEscape +\\['"]+ display contained
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_string_formatting')
|
||||||
|
" % operator string formatting
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent
|
||||||
|
syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent
|
||||||
|
else
|
||||||
|
syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent
|
||||||
|
syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_string_format')
|
||||||
|
" str.format syntax
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
else
|
||||||
|
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
|
||||||
|
syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
|
||||||
|
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_string_templates')
|
||||||
|
" string.Template format
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
else
|
||||||
|
syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonRawString
|
||||||
|
syn match pythonStrTemplate '\${[a-zA-Z_][a-zA-Z0-9_]*}' contained containedin=pythonString,pythonRawString
|
||||||
|
syn match pythonStrTemplate '\$[a-zA-Z_][a-zA-Z0-9_]*' contained containedin=pythonString,pythonRawString
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_doctests')
|
||||||
" DocTests
|
" DocTests
|
||||||
syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
|
syn region pythonDocTest start='^\s*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained
|
||||||
syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
|
syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
" Numbers (ints, longs, floats, complex)
|
" Numbers (ints, longs, floats, complex)
|
||||||
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
|
"
|
||||||
syn match pythonHexNumber "\<0[xX]\>" display
|
|
||||||
syn match pythonNumber "\<\d\+[lLjJ]\=\>" display
|
|
||||||
syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display
|
|
||||||
syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
|
|
||||||
syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
|
|
||||||
|
|
||||||
syn match pythonOctalError "\<0\o*[89]\d*[lL]\=\>" display
|
if s:Python2Syntax()
|
||||||
syn match pythonHexError "\<0[xX]\X\+[lL]\=\>" display
|
syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>' display
|
||||||
|
syn match pythonOctError '\<0[oO]\=\o*\D\+\d*[lL]\=\>' display
|
||||||
|
syn match pythonBinError '\<0[bB][01]*\D\+\d*[lL]\=\>' display
|
||||||
|
|
||||||
if exists("python_highlight_builtins") && python_highlight_builtins != 0
|
syn match pythonHexNumber '\<0[xX]\x\+[lL]\=\>' display
|
||||||
" Builtin functions, types and objects
|
syn match pythonOctNumber '\<0[oO]\o\+[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
syn match pythonBinNumber '\<0[bB][01]\+[lL]\=\>' display
|
||||||
|
|
||||||
syn keyword pythonBuiltinFunc __import__ abs all any apply
|
syn match pythonNumberError '\<\d\+\D[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc basestring bool buffer bytearray bytes callable
|
syn match pythonNumber '\<\d[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex
|
syn match pythonNumber '\<[0-9]\d\+[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
|
syn match pythonNumber '\<\d\+[lLjJ]\>' display
|
||||||
syn keyword pythonBuiltinFunc execfile file filter float frozenset getattr
|
|
||||||
syn keyword pythonBuiltinfunc globals hasattr hash help hex id
|
syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc input int intern isinstance
|
syn match pythonBinError '\<0[bB][01]*[2-9]\d*[lL]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
|
|
||||||
syn keyword pythonBuiltinFunc min object oct open ord pow property range
|
syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc raw_input reduce reload repr
|
syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display
|
||||||
syn keyword pythonBuiltinFunc reversed round set setattr
|
syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display
|
||||||
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
|
else
|
||||||
syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip
|
syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display
|
||||||
|
" pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError
|
||||||
|
syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display
|
||||||
|
syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display
|
||||||
|
|
||||||
|
syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display
|
||||||
|
syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display
|
||||||
|
syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display
|
||||||
|
|
||||||
|
syn match pythonNumberError '\<\d[_0-9]*\D\>' display
|
||||||
|
syn match pythonNumberError '\<0[_0-9]\+\>' display
|
||||||
|
syn match pythonNumberError '\<0_x\S*\>' display
|
||||||
|
syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display
|
||||||
|
syn match pythonNumberError '\<\d[_0-9]*_\>' display
|
||||||
|
syn match pythonNumber '\<\d\>' display
|
||||||
|
syn match pythonNumber '\<[1-9][_0-9]*\d\>' display
|
||||||
|
syn match pythonNumber '\<\d[jJ]\>' display
|
||||||
|
syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display
|
||||||
|
|
||||||
|
syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display
|
||||||
|
syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display
|
||||||
|
|
||||||
|
syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display
|
||||||
|
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display
|
||||||
|
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
|
"
|
||||||
" Builtin exceptions and warnings
|
" Builtin objects and types
|
||||||
syn keyword pythonExClass BaseException
|
"
|
||||||
syn keyword pythonExClass Exception StandardError ArithmeticError
|
|
||||||
syn keyword pythonExClass LookupError EnvironmentError
|
|
||||||
|
|
||||||
syn keyword pythonExClass AssertionError AttributeError EOFError
|
if s:Enabled('g:python_highlight_builtin_objs')
|
||||||
syn keyword pythonExClass FloatingPointError GeneratorExit IOError
|
syn keyword pythonNone None
|
||||||
syn keyword pythonExClass ImportError IndexError KeyError
|
syn keyword pythonBoolean True False
|
||||||
syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
|
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
||||||
syn keyword pythonExClass NotImplementedError OSError OverflowError
|
syn match pythonBuiltinObj '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
|
||||||
syn keyword pythonExClass ReferenceError RuntimeError StopIteration
|
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
|
||||||
syn keyword pythonExClass SyntaxError IndentationError TabError
|
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
|
||||||
syn keyword pythonExClass SystemError SystemExit TypeError
|
|
||||||
syn keyword pythonExClass UnboundLocalError UnicodeError
|
|
||||||
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
|
|
||||||
syn keyword pythonExClass UnicodeTranslateError ValueError
|
|
||||||
syn keyword pythonExClass WindowsError ZeroDivisionError
|
|
||||||
|
|
||||||
syn keyword pythonExClass Warning UserWarning DeprecationWarning
|
|
||||||
syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
|
|
||||||
syn keyword pythonExClass RuntimeWarning FutureWarning OverflowWarning
|
|
||||||
syn keyword pythonExClass ImportWarning UnicodeWarning
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_slow_sync") && python_slow_sync != 0
|
"
|
||||||
|
" Builtin functions
|
||||||
|
"
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_builtin_funcs')
|
||||||
|
let s:funcs_re = '__import__|abs|all|any|bin|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip'
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
let s:funcs_re .= '|apply|basestring|buffer|cmp|coerce|execfile|file|intern|long|raw_input|reduce|reload|unichr|unicode|xrange'
|
||||||
|
if s:Enabled('g:python_print_as_function')
|
||||||
|
let s:funcs_re .= '|print'
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let s:funcs_re .= '|ascii|exec|print'
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@<!\zs<%(' . s:funcs_re . ')>'
|
||||||
|
|
||||||
|
if !s:Enabled('g:python_highlight_builtin_funcs_kwarg')
|
||||||
|
let s:funcs_re .= '\=@!'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute s:funcs_re . ''''
|
||||||
|
unlet s:funcs_re
|
||||||
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
|
" Builtin exceptions and warnings
|
||||||
|
"
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_exceptions')
|
||||||
|
let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDepricationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning'
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
let s:exs_re .= '|StandardError'
|
||||||
|
else
|
||||||
|
let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute 'syn match pythonExClass ''\v\.@<!\zs<%(' . s:exs_re . ')>'''
|
||||||
|
unlet s:exs_re
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_slow_sync')
|
||||||
syn sync minlines=2000
|
syn sync minlines=2000
|
||||||
else
|
else
|
||||||
" This is fast but code inside triple quoted strings screws it up. It
|
" This is fast but code inside triple quoted strings screws it up. It
|
||||||
" is impossible to fix because the only way to know if you are inside a
|
" is impossible to fix because the only way to know if you are inside a
|
||||||
" triple quoted string is to start from the beginning of the file.
|
" triple quoted string is to start from the beginning of the file.
|
||||||
syn sync match pythonSync grouphere NONE "):$"
|
syn sync match pythonSync grouphere NONE '):$'
|
||||||
syn sync maxlines=200
|
syn sync maxlines=200
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if version >= 508 || !exists("did_python_syn_inits")
|
if v:version >= 508 || !exists('did_python_syn_inits')
|
||||||
if version <= 508
|
if v:version <= 508
|
||||||
let did_python_syn_inits = 1
|
let did_python_syn_inits = 1
|
||||||
command -nargs=+ HiLink hi link <args>
|
command -nargs=+ HiLink hi link <args>
|
||||||
else
|
else
|
||||||
command -nargs=+ HiLink hi def link <args>
|
command -nargs=+ HiLink hi def link <args>
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HiLink pythonStatement Statement
|
HiLink pythonStatement Statement
|
||||||
HiLink pythonImport Statement
|
HiLink pythonRaiseFromStatement Statement
|
||||||
HiLink pythonFunction Function
|
HiLink pythonImport Include
|
||||||
HiLink pythonConditional Conditional
|
HiLink pythonFunction Function
|
||||||
HiLink pythonRepeat Repeat
|
HiLink pythonConditional Conditional
|
||||||
HiLink pythonException Exception
|
HiLink pythonRepeat Repeat
|
||||||
HiLink pythonOperator Operator
|
HiLink pythonException Exception
|
||||||
|
HiLink pythonOperator Operator
|
||||||
|
|
||||||
HiLink pythonDecorator Define
|
HiLink pythonDecorator Define
|
||||||
|
HiLink pythonDottedName Function
|
||||||
|
HiLink pythonDot Normal
|
||||||
|
|
||||||
HiLink pythonComment Comment
|
HiLink pythonComment Comment
|
||||||
HiLink pythonCoding Special
|
if !s:Enabled('g:python_highlight_file_headers_as_comments')
|
||||||
HiLink pythonRun Special
|
HiLink pythonCoding Special
|
||||||
HiLink pythonTodo Todo
|
HiLink pythonRun Special
|
||||||
|
endif
|
||||||
|
HiLink pythonTodo Todo
|
||||||
|
|
||||||
HiLink pythonError Error
|
HiLink pythonError Error
|
||||||
HiLink pythonIndentError Error
|
HiLink pythonIndentError Error
|
||||||
HiLink pythonSpaceError Error
|
HiLink pythonSpaceError Error
|
||||||
|
|
||||||
HiLink pythonString String
|
HiLink pythonString String
|
||||||
HiLink pythonBString String
|
HiLink pythonRawString String
|
||||||
HiLink pythonUniString String
|
HiLink pythonRawEscape Special
|
||||||
HiLink pythonRawString String
|
|
||||||
HiLink pythonUniRawString String
|
|
||||||
|
|
||||||
HiLink pythonEscape Special
|
HiLink pythonUniEscape Special
|
||||||
HiLink pythonBEscape Special
|
HiLink pythonUniEscapeError Error
|
||||||
HiLink pythonEscapeError Error
|
|
||||||
HiLink pythonBEscapeError Error
|
|
||||||
HiLink pythonUniEscape Special
|
|
||||||
HiLink pythonUniEscapeError Error
|
|
||||||
HiLink pythonUniRawEscape Special
|
|
||||||
HiLink pythonUniRawEscapeError Error
|
|
||||||
|
|
||||||
HiLink pythonStrFormat Special
|
if s:Python2Syntax()
|
||||||
|
HiLink pythonUniString String
|
||||||
|
HiLink pythonUniRawString String
|
||||||
|
HiLink pythonUniRawEscape Special
|
||||||
|
HiLink pythonUniRawEscapeError Error
|
||||||
|
else
|
||||||
|
HiLink pythonBytes String
|
||||||
|
HiLink pythonRawBytes String
|
||||||
|
HiLink pythonBytesContent String
|
||||||
|
HiLink pythonBytesError Error
|
||||||
|
HiLink pythonBytesEscape Special
|
||||||
|
HiLink pythonBytesEscapeError Error
|
||||||
|
HiLink pythonFString String
|
||||||
|
HiLink pythonRawFString String
|
||||||
|
HiLink pythonStrInterpRegion Special
|
||||||
|
endif
|
||||||
|
|
||||||
HiLink pythonDocTest Special
|
HiLink pythonStrFormatting Special
|
||||||
HiLink pythonDocTest2 Special
|
HiLink pythonStrFormat Special
|
||||||
|
HiLink pythonStrTemplate Special
|
||||||
|
|
||||||
HiLink pythonNumber Number
|
HiLink pythonDocTest Special
|
||||||
HiLink pythonHexNumber Number
|
HiLink pythonDocTest2 Special
|
||||||
HiLink pythonFloat Float
|
|
||||||
HiLink pythonOctalError Error
|
|
||||||
HiLink pythonHexError Error
|
|
||||||
|
|
||||||
HiLink pythonBuiltinObj Structure
|
HiLink pythonNumber Number
|
||||||
HiLink pythonBuiltinFunc Function
|
HiLink pythonHexNumber Number
|
||||||
|
HiLink pythonOctNumber Number
|
||||||
|
HiLink pythonBinNumber Number
|
||||||
|
HiLink pythonFloat Float
|
||||||
|
HiLink pythonNumberError Error
|
||||||
|
HiLink pythonOctError Error
|
||||||
|
HiLink pythonHexError Error
|
||||||
|
HiLink pythonBinError Error
|
||||||
|
|
||||||
HiLink pythonExClass Structure
|
HiLink pythonBoolean Boolean
|
||||||
|
HiLink pythonNone Constant
|
||||||
|
|
||||||
|
HiLink pythonBuiltinObj Structure
|
||||||
|
HiLink pythonBuiltinFunc Function
|
||||||
|
|
||||||
|
HiLink pythonExClass Structure
|
||||||
|
HiLink pythonClassVar Identifier
|
||||||
|
|
||||||
delcommand HiLink
|
delcommand HiLink
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let b:current_syntax = "python"
|
let b:current_syntax = 'python'
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ syn keyword qmlLabel case default
|
|||||||
syn keyword qmlException try catch finally throw
|
syn keyword qmlException try catch finally throw
|
||||||
syn keyword qmlMessage alert confirm prompt status
|
syn keyword qmlMessage alert confirm prompt status
|
||||||
syn keyword qmlGlobal self
|
syn keyword qmlGlobal self
|
||||||
syn keyword qmlDeclaration property signal
|
syn keyword qmlDeclaration property signal readonly
|
||||||
syn keyword qmlReserved abstract boolean byte char class const debugger enum export extends final float goto implements import interface long native package pragma private protected public short static super synchronized throws transient volatile
|
syn keyword qmlReserved abstract boolean byte char class const debugger enum export extends final float goto implements import interface long native package pragma private protected public short static super synchronized throws transient volatile
|
||||||
|
|
||||||
if get(g:, 'qml_fold', 0)
|
if get(g:, 'qml_fold', 0)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'swift') == -1
|
|||||||
" File: swift.vim
|
" File: swift.vim
|
||||||
" Author: Keith Smiley
|
" Author: Keith Smiley
|
||||||
" Description: Runtime files for Swift
|
" Description: Runtime files for Swift
|
||||||
" Last Modified: June 15, 2014
|
|
||||||
|
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
finish
|
finish
|
||||||
@@ -242,6 +241,8 @@ syntax keyword swiftPreprocessor
|
|||||||
\ #else
|
\ #else
|
||||||
\ #endif
|
\ #endif
|
||||||
\ #selector
|
\ #selector
|
||||||
|
\ #warning
|
||||||
|
\ #error
|
||||||
|
|
||||||
|
|
||||||
" Comment patterns
|
" Comment patterns
|
||||||
|
|||||||
@@ -9,14 +9,25 @@ endif
|
|||||||
|
|
||||||
syn case match
|
syn case match
|
||||||
|
|
||||||
syn keyword terraSection connection output provider variable data terraform
|
syn keyword terraSection connection output provider variable data terraform locals
|
||||||
syn keyword terraValueBool true false on off yes no
|
syn keyword terraValueBool true false on off yes no
|
||||||
|
|
||||||
""" data
|
""" data
|
||||||
syn keyword terraDataTypeBI
|
syn keyword terraDataTypeBI
|
||||||
|
\ alicloud_dns_domain_groups
|
||||||
|
\ alicloud_dns_domain_records
|
||||||
|
\ alicloud_dns_domains
|
||||||
|
\ alicloud_dns_groups
|
||||||
|
\ alicloud_dns_records
|
||||||
\ alicloud_images
|
\ alicloud_images
|
||||||
\ alicloud_instance_types
|
\ alicloud_instance_types
|
||||||
\ alicloud_key_pairs
|
\ alicloud_key_pairs
|
||||||
|
\ alicloud_ram_account_alias
|
||||||
|
\ alicloud_ram_account_aliases
|
||||||
|
\ alicloud_ram_groups
|
||||||
|
\ alicloud_ram_policies
|
||||||
|
\ alicloud_ram_roles
|
||||||
|
\ alicloud_ram_users
|
||||||
\ alicloud_regions
|
\ alicloud_regions
|
||||||
\ alicloud_vpcs
|
\ alicloud_vpcs
|
||||||
\ alicloud_zones
|
\ alicloud_zones
|
||||||
@@ -52,6 +63,7 @@ syn keyword terraDataTypeBI
|
|||||||
\ aws_elastic_beanstalk_solution_stack
|
\ aws_elastic_beanstalk_solution_stack
|
||||||
\ aws_elasticache_cluster
|
\ aws_elasticache_cluster
|
||||||
\ aws_elasticache_replication_group
|
\ aws_elasticache_replication_group
|
||||||
|
\ aws_elb
|
||||||
\ aws_elb_hosted_zone_id
|
\ aws_elb_hosted_zone_id
|
||||||
\ aws_elb_service_account
|
\ aws_elb_service_account
|
||||||
\ aws_iam_account_alias
|
\ aws_iam_account_alias
|
||||||
@@ -73,6 +85,7 @@ syn keyword terraDataTypeBI
|
|||||||
\ aws_lb_listener
|
\ aws_lb_listener
|
||||||
\ aws_lb_target_group
|
\ aws_lb_target_group
|
||||||
\ aws_nat_gateway
|
\ aws_nat_gateway
|
||||||
|
\ aws_network_interface
|
||||||
\ aws_partition
|
\ aws_partition
|
||||||
\ aws_prefix_list
|
\ aws_prefix_list
|
||||||
\ aws_rds_cluster
|
\ aws_rds_cluster
|
||||||
@@ -97,6 +110,7 @@ syn keyword terraDataTypeBI
|
|||||||
\ azurerm_image
|
\ azurerm_image
|
||||||
\ azurerm_key_vault_access_policy
|
\ azurerm_key_vault_access_policy
|
||||||
\ azurerm_managed_disk
|
\ azurerm_managed_disk
|
||||||
|
\ azurerm_network_security_group
|
||||||
\ azurerm_platform_image
|
\ azurerm_platform_image
|
||||||
\ azurerm_public_ip
|
\ azurerm_public_ip
|
||||||
\ azurerm_resource_group
|
\ azurerm_resource_group
|
||||||
@@ -104,6 +118,7 @@ syn keyword terraDataTypeBI
|
|||||||
\ azurerm_snapshot
|
\ azurerm_snapshot
|
||||||
\ azurerm_subnet
|
\ azurerm_subnet
|
||||||
\ azurerm_subscription
|
\ azurerm_subscription
|
||||||
|
\ azurerm_virtual_network
|
||||||
\ circonus_account
|
\ circonus_account
|
||||||
\ circonus_collector
|
\ circonus_collector
|
||||||
\ cloudstack_template
|
\ cloudstack_template
|
||||||
@@ -124,21 +139,28 @@ syn keyword terraDataTypeBI
|
|||||||
\ github_team
|
\ github_team
|
||||||
\ github_user
|
\ github_user
|
||||||
\ google_active_folder
|
\ google_active_folder
|
||||||
|
\ google_billing_account
|
||||||
\ google_client_config
|
\ google_client_config
|
||||||
\ google_compute_address
|
\ google_compute_address
|
||||||
\ google_compute_global_address
|
\ google_compute_global_address
|
||||||
|
\ google_compute_image
|
||||||
\ google_compute_instance_group
|
\ google_compute_instance_group
|
||||||
\ google_compute_lb_ip_ranges
|
\ google_compute_lb_ip_ranges
|
||||||
\ google_compute_network
|
\ google_compute_network
|
||||||
|
\ google_compute_region_instance_group
|
||||||
\ google_compute_subnetwork
|
\ google_compute_subnetwork
|
||||||
\ google_compute_zones
|
\ google_compute_zones
|
||||||
|
\ google_container_cluster
|
||||||
\ google_container_engine_versions
|
\ google_container_engine_versions
|
||||||
\ google_dns_managed_zone
|
\ google_dns_managed_zone
|
||||||
\ google_iam_policy
|
\ google_iam_policy
|
||||||
|
\ google_kms_secret
|
||||||
|
\ google_organization
|
||||||
\ google_storage_object_signed_url
|
\ google_storage_object_signed_url
|
||||||
\ http
|
\ http
|
||||||
\ kubernetes_service
|
\ kubernetes_service
|
||||||
\ kubernetes_storage_class
|
\ kubernetes_storage_class
|
||||||
|
\ local_file
|
||||||
\ logicmonitor_collectors
|
\ logicmonitor_collectors
|
||||||
\ logicmonitor_device_group
|
\ logicmonitor_device_group
|
||||||
\ newrelic_application
|
\ newrelic_application
|
||||||
@@ -154,6 +176,10 @@ syn keyword terraDataTypeBI
|
|||||||
\ openstack_networking_network_v2
|
\ openstack_networking_network_v2
|
||||||
\ openstack_networking_secgroup_v2
|
\ openstack_networking_secgroup_v2
|
||||||
\ openstack_networking_subnet_v2
|
\ openstack_networking_subnet_v2
|
||||||
|
\ opentelekomcloud_images_image_v2
|
||||||
|
\ opentelekomcloud_networking_network_v2
|
||||||
|
\ opentelekomcloud_networking_secgroup_v2
|
||||||
|
\ opentelekomcloud_s3_bucket_object
|
||||||
\ opsgenie_user
|
\ opsgenie_user
|
||||||
\ ovh_publiccloud_region
|
\ ovh_publiccloud_region
|
||||||
\ ovh_publiccloud_regions
|
\ ovh_publiccloud_regions
|
||||||
@@ -175,22 +201,33 @@ syn keyword terraDataTypeBI
|
|||||||
\ template_cloudinit_config
|
\ template_cloudinit_config
|
||||||
\ template_file
|
\ template_file
|
||||||
\ terraform_remote_state
|
\ terraform_remote_state
|
||||||
|
\ triton_account
|
||||||
|
\ triton_datacenter
|
||||||
\ triton_image
|
\ triton_image
|
||||||
\ triton_network
|
\ triton_network
|
||||||
|
\ vsphere_custom_attribute
|
||||||
\ vsphere_datacenter
|
\ vsphere_datacenter
|
||||||
|
\ vsphere_datastore
|
||||||
\ vsphere_distributed_virtual_switch
|
\ vsphere_distributed_virtual_switch
|
||||||
\ vsphere_host
|
\ vsphere_host
|
||||||
\ vsphere_network
|
\ vsphere_network
|
||||||
|
\ vsphere_resource_pool
|
||||||
\ vsphere_tag
|
\ vsphere_tag
|
||||||
\ vsphere_tag_category
|
\ vsphere_tag_category
|
||||||
|
\ vsphere_virtual_machine
|
||||||
\ vsphere_vmfs_disks
|
\ vsphere_vmfs_disks
|
||||||
""" end data sources
|
""" end data sources
|
||||||
|
|
||||||
""" resource
|
""" resource
|
||||||
syn keyword terraResourceTypeBI
|
syn keyword terraResourceTypeBI
|
||||||
|
\ alicloud_cdn_domain
|
||||||
|
\ alicloud_container_cluster
|
||||||
\ alicloud_db_instance
|
\ alicloud_db_instance
|
||||||
\ alicloud_disk
|
\ alicloud_disk
|
||||||
\ alicloud_disk_attachment
|
\ alicloud_disk_attachment
|
||||||
|
\ alicloud_dns
|
||||||
|
\ alicloud_dns_group
|
||||||
|
\ alicloud_dns_record
|
||||||
\ alicloud_eip
|
\ alicloud_eip
|
||||||
\ alicloud_eip_association
|
\ alicloud_eip_association
|
||||||
\ alicloud_ess_scaling_configuration
|
\ alicloud_ess_scaling_configuration
|
||||||
@@ -204,12 +241,26 @@ syn keyword terraResourceTypeBI
|
|||||||
\ alicloud_nat_gateway
|
\ alicloud_nat_gateway
|
||||||
\ alicloud_oss_bucket
|
\ alicloud_oss_bucket
|
||||||
\ alicloud_oss_bucket_object
|
\ alicloud_oss_bucket_object
|
||||||
|
\ alicloud_ram_access_key
|
||||||
|
\ alicloud_ram_account_alias
|
||||||
|
\ alicloud_ram_alias
|
||||||
|
\ alicloud_ram_group
|
||||||
|
\ alicloud_ram_group_membership
|
||||||
|
\ alicloud_ram_group_policy_attachment
|
||||||
|
\ alicloud_ram_login_profile
|
||||||
|
\ alicloud_ram_policy
|
||||||
|
\ alicloud_ram_role
|
||||||
|
\ alicloud_ram_role_attachment
|
||||||
|
\ alicloud_ram_role_policy_attachment
|
||||||
|
\ alicloud_ram_user
|
||||||
|
\ alicloud_ram_user_policy_attachment
|
||||||
\ alicloud_route_entry
|
\ alicloud_route_entry
|
||||||
\ alicloud_router_interface
|
\ alicloud_router_interface
|
||||||
\ alicloud_security_group
|
\ alicloud_security_group
|
||||||
\ alicloud_security_group_rule
|
\ alicloud_security_group_rule
|
||||||
\ alicloud_slb
|
\ alicloud_slb
|
||||||
\ alicloud_slb_attachment
|
\ alicloud_slb_attachment
|
||||||
|
\ alicloud_slb_listener
|
||||||
\ alicloud_snat_entry
|
\ alicloud_snat_entry
|
||||||
\ alicloud_subnet
|
\ alicloud_subnet
|
||||||
\ alicloud_vpc
|
\ alicloud_vpc
|
||||||
@@ -247,6 +298,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ aws_api_gateway_usage_plan_key
|
\ aws_api_gateway_usage_plan_key
|
||||||
\ aws_app_cookie_stickiness_policy
|
\ aws_app_cookie_stickiness_policy
|
||||||
\ aws_appautoscaling_policy
|
\ aws_appautoscaling_policy
|
||||||
|
\ aws_appautoscaling_scheduled_action
|
||||||
\ aws_appautoscaling_target
|
\ aws_appautoscaling_target
|
||||||
\ aws_athena_database
|
\ aws_athena_database
|
||||||
\ aws_athena_named_query
|
\ aws_athena_named_query
|
||||||
@@ -270,6 +322,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ aws_cloudwatch_log_destination_policy
|
\ aws_cloudwatch_log_destination_policy
|
||||||
\ aws_cloudwatch_log_group
|
\ aws_cloudwatch_log_group
|
||||||
\ aws_cloudwatch_log_metric_filter
|
\ aws_cloudwatch_log_metric_filter
|
||||||
|
\ aws_cloudwatch_log_resource_policy
|
||||||
\ aws_cloudwatch_log_stream
|
\ aws_cloudwatch_log_stream
|
||||||
\ aws_cloudwatch_log_subscription_filter
|
\ aws_cloudwatch_log_subscription_filter
|
||||||
\ aws_cloudwatch_metric_alarm
|
\ aws_cloudwatch_metric_alarm
|
||||||
@@ -309,6 +362,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ aws_dms_replication_subnet_group
|
\ aws_dms_replication_subnet_group
|
||||||
\ aws_dms_replication_task
|
\ aws_dms_replication_task
|
||||||
\ aws_dx_connection
|
\ aws_dx_connection
|
||||||
|
\ aws_dx_connection_association
|
||||||
\ aws_dx_lag
|
\ aws_dx_lag
|
||||||
\ aws_dynamodb_table
|
\ aws_dynamodb_table
|
||||||
\ aws_ebs_snapshot
|
\ aws_ebs_snapshot
|
||||||
@@ -398,6 +452,9 @@ syn keyword terraResourceTypeBI
|
|||||||
\ aws_load_balancer_listener_policy
|
\ aws_load_balancer_listener_policy
|
||||||
\ aws_load_balancer_policy
|
\ aws_load_balancer_policy
|
||||||
\ aws_main_route_table_association
|
\ aws_main_route_table_association
|
||||||
|
\ aws_media_store_container
|
||||||
|
\ aws_mq_broker
|
||||||
|
\ aws_mq_configuration
|
||||||
\ aws_nat_gateway
|
\ aws_nat_gateway
|
||||||
\ aws_network_acl
|
\ aws_network_acl
|
||||||
\ aws_network_acl_rule
|
\ aws_network_acl_rule
|
||||||
@@ -443,6 +500,8 @@ syn keyword terraResourceTypeBI
|
|||||||
\ aws_s3_bucket_policy
|
\ aws_s3_bucket_policy
|
||||||
\ aws_security_group
|
\ aws_security_group
|
||||||
\ aws_security_group_rule
|
\ aws_security_group_rule
|
||||||
|
\ aws_service_discovery_private_dns_namespace
|
||||||
|
\ aws_service_discovery_public_dns_namespace
|
||||||
\ aws_servicecatalog_portfolio
|
\ aws_servicecatalog_portfolio
|
||||||
\ aws_ses_active_receipt_rule_set
|
\ aws_ses_active_receipt_rule_set
|
||||||
\ aws_ses_configuration_set
|
\ aws_ses_configuration_set
|
||||||
@@ -559,6 +618,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ azurerm_local_network_gateway
|
\ azurerm_local_network_gateway
|
||||||
\ azurerm_log_analytics_workspace
|
\ azurerm_log_analytics_workspace
|
||||||
\ azurerm_managed_disk
|
\ azurerm_managed_disk
|
||||||
|
\ azurerm_management_lock
|
||||||
\ azurerm_mysql_configuration
|
\ azurerm_mysql_configuration
|
||||||
\ azurerm_mysql_database
|
\ azurerm_mysql_database
|
||||||
\ azurerm_mysql_firewall_rule
|
\ azurerm_mysql_firewall_rule
|
||||||
@@ -566,6 +626,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ azurerm_network_interface
|
\ azurerm_network_interface
|
||||||
\ azurerm_network_security_group
|
\ azurerm_network_security_group
|
||||||
\ azurerm_network_security_rule
|
\ azurerm_network_security_rule
|
||||||
|
\ azurerm_network_watcher
|
||||||
\ azurerm_postgresql_configuration
|
\ azurerm_postgresql_configuration
|
||||||
\ azurerm_postgresql_database
|
\ azurerm_postgresql_database
|
||||||
\ azurerm_postgresql_firewall_rule
|
\ azurerm_postgresql_firewall_rule
|
||||||
@@ -758,10 +819,11 @@ syn keyword terraResourceTypeBI
|
|||||||
\ google_container_cluster
|
\ google_container_cluster
|
||||||
\ google_container_node_pool
|
\ google_container_node_pool
|
||||||
\ google_dataproc_cluster
|
\ google_dataproc_cluster
|
||||||
|
\ google_dataproc_job
|
||||||
\ google_dns_managed_zone
|
\ google_dns_managed_zone
|
||||||
\ google_dns_record_set
|
\ google_dns_record_set
|
||||||
\ google_folder
|
\ google_folder
|
||||||
\ google_folder_iam_policy
|
\ google_folder_organization_policy
|
||||||
\ google_kms_crypto_key
|
\ google_kms_crypto_key
|
||||||
\ google_kms_key_ring
|
\ google_kms_key_ring
|
||||||
\ google_logging_billing_account_sink
|
\ google_logging_billing_account_sink
|
||||||
@@ -770,9 +832,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ google_organization_iam_custom_role
|
\ google_organization_iam_custom_role
|
||||||
\ google_organization_policy
|
\ google_organization_policy
|
||||||
\ google_project
|
\ google_project
|
||||||
\ google_project_iam_binding
|
|
||||||
\ google_project_iam_custom_role
|
\ google_project_iam_custom_role
|
||||||
\ google_project_iam_member
|
|
||||||
\ google_project_iam_policy
|
\ google_project_iam_policy
|
||||||
\ google_project_service
|
\ google_project_service
|
||||||
\ google_project_services
|
\ google_project_services
|
||||||
@@ -874,6 +934,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ opc_compute_ip_network
|
\ opc_compute_ip_network
|
||||||
\ opc_compute_ip_network_exchange
|
\ opc_compute_ip_network_exchange
|
||||||
\ opc_compute_ip_reservation
|
\ opc_compute_ip_reservation
|
||||||
|
\ opc_compute_orchestrated_instance
|
||||||
\ opc_compute_route
|
\ opc_compute_route
|
||||||
\ opc_compute_sec_rule
|
\ opc_compute_sec_rule
|
||||||
\ opc_compute_security_application
|
\ opc_compute_security_application
|
||||||
@@ -887,7 +948,6 @@ syn keyword terraResourceTypeBI
|
|||||||
\ opc_compute_storage_volume
|
\ opc_compute_storage_volume
|
||||||
\ opc_compute_storage_volume_snapshot
|
\ opc_compute_storage_volume_snapshot
|
||||||
\ opc_compute_vnic_set
|
\ opc_compute_vnic_set
|
||||||
\ opc_database_service_instance
|
|
||||||
\ opc_storage_container
|
\ opc_storage_container
|
||||||
\ opc_storage_object
|
\ opc_storage_object
|
||||||
\ openstack_blockstorage_volume_attach_v2
|
\ openstack_blockstorage_volume_attach_v2
|
||||||
@@ -901,6 +961,8 @@ syn keyword terraResourceTypeBI
|
|||||||
\ openstack_compute_secgroup_v2
|
\ openstack_compute_secgroup_v2
|
||||||
\ openstack_compute_servergroup_v2
|
\ openstack_compute_servergroup_v2
|
||||||
\ openstack_compute_volume_attach_v2
|
\ openstack_compute_volume_attach_v2
|
||||||
|
\ openstack_db_database_v1
|
||||||
|
\ openstack_db_instance_v1
|
||||||
\ openstack_dns_recordset_v2
|
\ openstack_dns_recordset_v2
|
||||||
\ openstack_dns_zone_v2
|
\ openstack_dns_zone_v2
|
||||||
\ openstack_fw_firewall_v1
|
\ openstack_fw_firewall_v1
|
||||||
@@ -929,8 +991,47 @@ syn keyword terraResourceTypeBI
|
|||||||
\ openstack_networking_subnet_v2
|
\ openstack_networking_subnet_v2
|
||||||
\ openstack_objectstorage_container_v1
|
\ openstack_objectstorage_container_v1
|
||||||
\ openstack_objectstorage_object_v1
|
\ openstack_objectstorage_object_v1
|
||||||
|
\ opentelekomcloud_blockstorage_volume_v2
|
||||||
|
\ opentelekomcloud_ces_alarmrule
|
||||||
|
\ opentelekomcloud_compute_floatingip_associate_v2
|
||||||
|
\ opentelekomcloud_compute_floatingip_v2
|
||||||
|
\ opentelekomcloud_compute_instance_v2
|
||||||
|
\ opentelekomcloud_compute_keypair_v2
|
||||||
|
\ opentelekomcloud_compute_secgroup_v2
|
||||||
|
\ opentelekomcloud_compute_servergroup_v2
|
||||||
|
\ opentelekomcloud_compute_volume_attach_v2
|
||||||
|
\ opentelekomcloud_dns_recordset_v2
|
||||||
|
\ opentelekomcloud_dns_zone_v2
|
||||||
|
\ opentelekomcloud_elb_backend
|
||||||
|
\ opentelekomcloud_elb_health
|
||||||
|
\ opentelekomcloud_elb_listener
|
||||||
|
\ opentelekomcloud_elb_loadbalancer
|
||||||
|
\ opentelekomcloud_fw_firewall_group_v2
|
||||||
|
\ opentelekomcloud_fw_policy_v2
|
||||||
|
\ opentelekomcloud_fw_rule_v2
|
||||||
|
\ opentelekomcloud_images_image_v2
|
||||||
|
\ opentelekomcloud_lb_listener_v2
|
||||||
|
\ opentelekomcloud_lb_loadbalancer_v2
|
||||||
|
\ opentelekomcloud_lb_member_v2
|
||||||
|
\ opentelekomcloud_lb_monitor_v2
|
||||||
|
\ opentelekomcloud_lb_pool_v2
|
||||||
|
\ opentelekomcloud_networking_floatingip_v2
|
||||||
|
\ opentelekomcloud_networking_network_v2
|
||||||
|
\ opentelekomcloud_networking_port_v2
|
||||||
|
\ opentelekomcloud_networking_router_interface_v2
|
||||||
|
\ opentelekomcloud_networking_router_route_v2
|
||||||
|
\ opentelekomcloud_networking_router_v2
|
||||||
|
\ opentelekomcloud_networking_secgroup_rule_v2
|
||||||
|
\ opentelekomcloud_networking_secgroup_v2
|
||||||
|
\ opentelekomcloud_networking_subnet_v2
|
||||||
|
\ opentelekomcloud_s3_bucket
|
||||||
|
\ opentelekomcloud_s3_bucket_object
|
||||||
|
\ opentelekomcloud_s3_bucket_policy
|
||||||
|
\ opentelekomcloud_smn_subscription_v2
|
||||||
|
\ opentelekomcloud_smn_topic_v2
|
||||||
\ opsgenie_team
|
\ opsgenie_team
|
||||||
\ opsgenie_user
|
\ opsgenie_user
|
||||||
|
\ ovh_domain_zone_record
|
||||||
\ ovh_publiccloud_private_network
|
\ ovh_publiccloud_private_network
|
||||||
\ ovh_publiccloud_private_network_subnet
|
\ ovh_publiccloud_private_network_subnet
|
||||||
\ ovh_publiccloud_user
|
\ ovh_publiccloud_user
|
||||||
@@ -984,6 +1085,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ rancher_registry_credential
|
\ rancher_registry_credential
|
||||||
\ rancher_secret
|
\ rancher_secret
|
||||||
\ rancher_stack
|
\ rancher_stack
|
||||||
|
\ rancher_volume
|
||||||
\ random_id
|
\ random_id
|
||||||
\ random_integer
|
\ random_integer
|
||||||
\ random_pet
|
\ random_pet
|
||||||
@@ -1029,6 +1131,7 @@ syn keyword terraResourceTypeBI
|
|||||||
\ vcd_snat
|
\ vcd_snat
|
||||||
\ vcd_vapp
|
\ vcd_vapp
|
||||||
\ vcd_vapp_vm
|
\ vcd_vapp_vm
|
||||||
|
\ vsphere_custom_attribute
|
||||||
\ vsphere_datacenter
|
\ vsphere_datacenter
|
||||||
\ vsphere_distributed_port_group
|
\ vsphere_distributed_port_group
|
||||||
\ vsphere_distributed_virtual_switch
|
\ vsphere_distributed_virtual_switch
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'tmux') == -1
|
|||||||
" - Switch on syntax highlighting by adding "syntax enable" to .vimrc.
|
" - Switch on syntax highlighting by adding "syntax enable" to .vimrc.
|
||||||
"
|
"
|
||||||
|
|
||||||
if version < 600
|
if v:version < 600
|
||||||
syntax clear
|
syntax clear
|
||||||
elseif exists("b:current_syntax")
|
elseif exists('b:current_syntax')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ syn keyword tmuxCmds
|
|||||||
\ confirm
|
\ confirm
|
||||||
\ confirm-before
|
\ confirm-before
|
||||||
\ copy-mode
|
\ copy-mode
|
||||||
|
\ copy-mode-vi
|
||||||
\ delete-buffer
|
\ delete-buffer
|
||||||
\ deleteb
|
\ deleteb
|
||||||
\ detach
|
\ detach
|
||||||
@@ -327,6 +328,6 @@ hi def link tmuxTodo Todo
|
|||||||
hi def link tmuxVariable Constant
|
hi def link tmuxVariable Constant
|
||||||
hi def link tmuxVariableExpansion Constant
|
hi def link tmuxVariableExpansion Constant
|
||||||
|
|
||||||
let b:current_syntax = "tmux"
|
let b:current_syntax = 'tmux'
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ syn match tomlBoolean /\<\%(true\|false\)\>/ display
|
|||||||
hi def link tomlBoolean Boolean
|
hi def link tomlBoolean Boolean
|
||||||
|
|
||||||
" https://tools.ietf.org/html/rfc3339
|
" https://tools.ietf.org/html/rfc3339
|
||||||
syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}T\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)/ display
|
syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}/ display
|
||||||
|
syn match tomlDate /\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?/ display
|
||||||
|
syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}[T ]\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)\?/ display
|
||||||
hi def link tomlDate Constant
|
hi def link tomlDate Constant
|
||||||
|
|
||||||
syn region tomlKeyDq oneline start=/"/ end=/"/ contains=tomlEscape contained
|
syn region tomlKeyDq oneline start=/"/ end=/"/ contains=tomlEscape contained
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ if !exists("typescript_ignore_typescriptdoc")
|
|||||||
"unlet b:current_syntax
|
"unlet b:current_syntax
|
||||||
|
|
||||||
syntax region typescriptDocComment start="/\*\*\s*$" end="\*/" contains=typescriptDocTags,typescriptCommentTodo,typescriptCvsTag,@typescriptHtml,@Spell fold extend
|
syntax region typescriptDocComment start="/\*\*\s*$" end="\*/" contains=typescriptDocTags,typescriptCommentTodo,typescriptCvsTag,@typescriptHtml,@Spell fold extend
|
||||||
syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite
|
syntax match typescriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\|returns\=\)\>" nextgroup=typescriptDocParam,typescriptDocSeeTag skipwhite
|
||||||
syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
|
syntax match typescriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>"
|
||||||
syntax match typescriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
|
syntax match typescriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+"
|
||||||
syntax region typescriptDocSeeTag contained matchgroup=typescriptDocSeeTag start="{" end="}" contains=typescriptDocTags
|
syntax region typescriptDocSeeTag contained matchgroup=typescriptDocSeeTag start="{" end="}" contains=typescriptDocTags
|
||||||
|
|
||||||
@@ -67,14 +67,16 @@ syn region typescriptInterpolation matchgroup=typescriptInterpolationDelimiter
|
|||||||
\ start=/${/ end=/}/ contained
|
\ start=/${/ end=/}/ contained
|
||||||
\ contains=@typescriptExpression
|
\ contains=@typescriptExpression
|
||||||
|
|
||||||
syn match typescriptNumber "-\=\<\d\+L\=\>\|0[xX][0-9a-fA-F]\+\>"
|
syn match typescriptNumber "-\=\<0[xX][0-9a-fA-F][0-9a-fA-F_]*\>" display
|
||||||
|
syn match typescriptNumber "-\=\<0[bB][01][01_]*\>" display
|
||||||
|
syn match typescriptNumber "-\=\<0[oO]\o[0-7_]*\>" display
|
||||||
syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
|
syn region typescriptRegexpString start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gi]\{0,2\}\s*$+ end=+/[gi]\{0,2\}\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc oneline
|
||||||
" syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
|
" syntax match typescriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\."
|
||||||
" syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc
|
" syntax region typescriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=typescriptSpecial,@htmlPreproc
|
||||||
" syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc
|
" syntax region typescriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=typescriptSpecial,@htmlPreproc
|
||||||
" syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline
|
" syntax region typescriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=typescriptSpecial,@htmlPreproc oneline
|
||||||
" syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
|
" syntax match typescriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
|
||||||
syntax match typescriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
|
syntax match typescriptFloat /\<-\=\%(\d[0-9_]*\.\d[0-9_]*\|\d[0-9_]*\.\|\.\d[0-9]*\)\%([eE][+-]\=\d[0-9_]*\)\=\>/
|
||||||
" syntax match typescriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
|
" syntax match typescriptLabel /\(?\s*\)\@<!\<\w\+\(\s*:\)\@=/
|
||||||
|
|
||||||
syn match typescriptDecorators /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/
|
syn match typescriptDecorators /@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>/
|
||||||
|
|||||||
Reference in New Issue
Block a user