1
0
mirror of https://github.com/amix/vimrc synced 2025-06-30 11:54:59 +08:00

Updated plugins

This commit is contained in:
Amir
2024-01-07 16:14:20 +01:00
parent 86762cf230
commit f676f799e7
172 changed files with 3227 additions and 1204 deletions

View File

@ -14,41 +14,34 @@ Originally authored by [Michael Sanders][msanders], SnipMate was forked in 2011
after a stagnation in development. This fork is currently maintained by [Rok
Garbas][garbas], [Marc Weber][marcweber], and [Adnan Zafar][ajzafar].
## Installing SnipMate ##
We recommend one of the following methods for installing SnipMate and its
dependencies. SnipMate depends on [vim-addon-mw-utils][mw-utils] and
[tlib][tlib].
SnipMate can be installed using a package manager or using Vim's built-in
package handling. It does depend on [vim-addon-mw-utils][mw-utils] and
optionally [tlib][tlib]. For example, to use Vim's built-in support,
% mkdir -p ~/.vim/pack/SnipMate/start
% cd ~/.vim/pack/SnipMate/start
% git clone https://github.com/garbas/vim-snipmate.git
% git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
# Optional:
% git clone https://github.com/tomtom/tlib_vim.git
% git clone https://github.com/honza/vim-snippets.git
> **NOTE:** SnipMate does not ship with any snippets out of the box. We suggest
looking at the [vim-snippets][vim-snippets] repository.
* Using [VAM][vam], add `vim-snippets` to the list of packages to be installed.
If tlib is enabled, it is used for multisnip (`:h SnipMate-multisnip`). It's
also required for the `:SnipMateOpenSnippetFiles` command.
* Using [Pathogen][pathogen], run the following commands:
% cd ~/.vim/bundle
% git clone https://github.com/tomtom/tlib_vim.git
% git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
% git clone https://github.com/garbas/vim-snipmate.git
# Optional:
% git clone https://github.com/honza/vim-snippets.git
* Using [Vundle][vundle], add the following to your `vimrc` then run
`:PluginInstall`
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
" Optional:
Plugin 'honza/vim-snippets'
Remember to run `:helptags ALL` once your Vim has loaded SnipMate!
## Using SnipMate ##
Press <tab> and try :SnipMateOpenSnippetFiles for starting.
Also see doc/SnipMate.txt to learn all SnipMate
Install and create some snippets (see `:h SnipMate-snippets`). Then type in the
trigger for one in the correct filetype and hit the expansion key (by default
bound to `<Tab>`).
## FAQ ##
@ -116,6 +109,22 @@ be found in the docs at `:h SnipMate-parser-versions`.
## Release Notes ##
Some changes listed here were contributed by non-maintainers. A full list can be
found at [Contributors.md](Contributors.md).
### Current ###
- Make tlib an optional dependency.
- Add SnipLookupPre and SnipLookupPost autocommand events
- Make version 1 of the snippet parser the default with no message
### 0.90 - 2023-12-29 ###
- Remove empty lines at the end of a `${VISUAL}` expansion
- Fix code for opening folds when expanding a snippet
- Deprecate legacy snippet parser
- Fix jumps when `&sel == 'exclusive'`
### 0.89 - 2016-05-29 ###
* Various regex updates to legacy parser

View File

@ -3,12 +3,6 @@ if !exists('g:snipMate')
let g:snipMate = {}
endif
try
call tlib#input#List('mi', '', [])
catch /.*/
echoe "tlib is missing. See install instructions at ".expand('<sfile>:h:h').'/README.md'
endtry
fun! Filename(...) abort
let filename = expand('%:t:r')
if filename == '' | return a:0 == 2 ? a:2 : '' | endif
@ -26,6 +20,8 @@ function! snipMate#expandSnip(snip, version, col) abort
if a:version == 1
let [snippet, b:snip_state.stops] = snipmate#parse#snippet(a:snip)
" only if zero stop doesn't exist
call s:add_zero_stop(snippet, b:snip_state.stops)
" Build stop/mirror info
let b:snip_state.stop_count = s:build_stops(snippet, b:snip_state.stops, lnum, col, indent)
else
@ -57,6 +53,14 @@ function! snipMate#expandSnip(snip, version, col) abort
return b:snip_state.set_stop(0)
endfunction
function! s:add_zero_stop(snippet, stops) abort
if !exists("a:stops['0']")
let zero_stop = {'mirrors': [], 'placeholder': []}
call extend(a:snippet[-1], [[0, '', zero_stop]])
call extend(a:stops, {'0': zero_stop}, 'keep')
endif
endfunction
function! s:insert_snippet_text(snippet, lnum, col, indent)
let line = getline(a:lnum)
let col = a:col
@ -147,10 +151,6 @@ function! s:build_stops(snippet, stops, lnum, col, indent) abort
endif
endfor
" add zero tabstop if it doesn't exist and then link it to the highest stop
" number
let stops[0] = get(stops, 0,
\ { 'placeholder' : [], 'line' : lnum, 'col' : col })
let stop_count = max(keys(stops)) + 2
let stops[stop_count - 1] = stops[0]
@ -175,6 +175,7 @@ function! s:build_loc_info(snippet, stops, lnum, col, seen_items) abort
let stub.col = col
call s:add_update_objects(stub, seen_items)
" if we've found a stop?
if len(item) > 2 && type(item[1]) != type({})
let col = s:build_loc_info(item[1:-2], stops, lnum, col, seen_items)
else
@ -211,7 +212,7 @@ fun! snipMate#ReadSnippetsFile(file) abort
if !filereadable(a:file) | return [result, new_scopes] | endif
let inSnip = 0
let line_no = 0
let snipversion = get(g:snipMate, 'snippet_version', 0)
let snipversion = get(g:snipMate, 'snippet_version', 1)
for line in readfile(a:file) + ["\n"]
let line_no += 1
@ -308,7 +309,7 @@ function! s:source_snippet() abort
let new_snips = []
if fnamemodify(file, ':e') == 'snippet'
call add(new_snips, [trigger, desc, join(readfile(file), "\n"), 0,
\ get(g:snipMate, 'snippet_version', 0)])
\ get(g:snipMate, 'snippet_version', 1)])
else
let [snippets, extends] = s:CachedSnips(file)
let new_snips = deepcopy(snippets)
@ -421,6 +422,12 @@ function! s:snippet_dirs() abort
endfunction
function! snipMate#OpenSnippetFiles() abort
if !exists('g:loaded_tlib') || g:loaded_tlib < 41
echom 'tlib is required for this command. '
\ . 'Remember to run :packadd if necessary.'
return
endif
let files = []
let scopes_done = []
let exists = []
@ -448,15 +455,50 @@ fun! snipMate#ScopesByFile() abort
return filter(funcref#Call(g:snipMate.get_scopes), "v:val != ''")
endf
" used by both: completion and insert snippet
fun! snipMate#GetSnippetsForWordBelowCursor(word, exact) abort
function! snipMate#flatten_filter_empty(list) abort
let result = []
for item in a:list
if type(item) == type([])
call extend(result, snipMate#flatten_filter_empty(item))
elseif !empty(item)
call extend(result, [item])
endif
unlet item " Avoid E706
endfor
return result
endf
function! s:determine_lookups(word) abort
let b:snip_word = a:word
" gather any lookups from the Pre au
if exists('#User#SnipLookupPre')
doautocmd User <nomodeline> SnipLookupPre
endif
" If none are found, add the standard lookups
if !exists('b:snip_lookups') || empty(b:snip_lookups)
let b:snip_lookups = s:standard_lookups(b:snip_word)
endif
" Run the Post au
if exists('#User#SnipLookupPost')
doautocmd <nomodeline> User SnipLookupPost
endif
" return the appropriate data, deleting buffer variables.
let ret = b:snip_lookups
unlet! b:snip_lookups b:snip_word
return ret
endfunction
function! s:standard_lookups(word) abort
" Split non-word characters into their own piece
" so 'foo.bar..baz' becomes ['foo', '.', 'bar', '.', '.', 'baz']
" First split just after a \W and then split each resultant string just
" before a \W
let parts = filter(tlib#list#Flatten(
\ map(split(a:word, '\W\zs'), 'split(v:val, "\\ze\\W")')),
\ '!empty(v:val)')
let parts = snipMate#flatten_filter_empty(
\ map(split(a:word, '\W\zs'), 'split(v:val, "\\ze\\W")'))
" Only look at the last few possibilities. Too many can be slow.
if len(parts) > 5
let parts = parts[-5:]
@ -469,7 +511,12 @@ fun! snipMate#GetSnippetsForWordBelowCursor(word, exact) abort
call add(lookups, lookup)
endif
endfor
return lookups
endfunction
" used by both: completion and insert snippet
fun! snipMate#GetSnippetsForWordBelowCursor(word, exact) abort
let lookups = s:determine_lookups(a:word)
" Remove empty lookup entries, but only if there are other nonempty lookups
if len(lookups) > 1
call filter(lookups, 'v:val != ""')
@ -504,18 +551,17 @@ fun! s:ChooseSnippet(snippets) abort
let snippet += [i.'. '.snip]
let i += 1
endfor
if len(snippet) == 1 || get(g:snipMate, 'always_choose_first', 0) == 1
" there's only a single snippet, choose it
let idx = 0
else
let idx = tlib#input#List('si','select snippet by name',snippet) -1
if idx == -1
return ''
let i = 0
if len(snippet) > 1 && get(g:snipMate, 'always_choose_first', 0) != 1
if exists('g:loaded_tlib') && g:loaded_tlib >= 41
let i = tlib#input#List('si','select snippet by name',snippet) - 1
else
let i = inputlist(snippet + ['Select a snippet by number']) - 1
endif
endif
" if a:snippets[..] is a String Call returns it
" If it's a function or a function string the result is returned
return funcref#Call(a:snippets[keys(a:snippets)[idx]])
return (i == -1) ? '' : funcref#Call(a:snippets[keys(a:snippets)[i]])
endf
fun! snipMate#WordBelowCursor() abort

View File

@ -17,7 +17,7 @@ For Vim version 7.0 or later.
This plugin only works if 'compatible' is not set.
{Vi does not have any of these features.}
SnipMate depends on vim-addon-mw-utils and tlib.
SnipMate depends on vim-addon-mw-utils and optionally on tlib.
==============================================================================
DESCRIPTION *SnipMate-description*
@ -75,6 +75,9 @@ Commands~
files will be shown, with the existing files
shown first.
The optional dependency tlib is required for
this command to work.
:SnipMateLoadScope[!] scope [scope ...]
Load snippets from additional scopes. Without
[!] the additional scopes are loaded only in
@ -221,6 +224,44 @@ The list of possible <Plug> mappings is as follows:
Additionally, <CR> is mapped in visual mode in .snippets files for retabbing
snippets.
*SnipMate-autocmds*
Autocommands~
Autocommands allow code written by the user to be executed automatically at
certain points within SnipMate's normal execution. Here is a list of events
available to the User. All of these are subject to change.
SnipTriggerPre *SnipMate-SnipTriggerPre*
SnipTriggerPost *SnipMate-SnipTriggerPost*
These two events are run when determining what text to use as
the trigger. The Pre version can be used to forgo SnipMate's
normal lookups entirely, and the Post version can be used to
add to whatever lookups already exist.
Both events have access to b:snip_word, a variable
containining the WORD before the cursor when snippet
triggering began, and b:snip_lookups, a |List| containing all
possible lookups that SnipMate should try as possible
triggers. They are tried in order from the beginning.
If SnipTriggerPre runs and puts anything in b:snip_lookups,
SnipMate's normal lookups will not be tried. SnipTriggerPost
runs regardless.
The following example only allows a '.' as a possible trigger
if the WORD before the cursor is not "self.": >
au User SnipLookupPost call My_func()
function My_func() abort
if match(b:snip_word, 'self\.$') != -1
call filter(b:snip_lookups, "v:val !~# '^\\.$'")
endif
endfunction
==============================================================================
SNIPPETS *SnipMate-snippets*
@ -583,6 +624,14 @@ Perhaps some of these features will be added in a later release.
==============================================================================
CHANGELOG *SnipMate-changelog*
0.90 - 2023-12-29
-----------------
- Remove empty lines at the end of a `${VISUAL}` expansion
- Fix code for opening folds when expanding a snippet
- Deprecate legacy snippet parser
- Fix jumps when `&sel == 'exclusive'`
0.89 - 2016-05-29
-----------------

View File

@ -57,10 +57,6 @@ endif
let g:snipMate['no_match_completion_feedkeys_chars'] =
\ get(g:snipMate, 'no_match_completion_feedkeys_chars', "\t")
if !exists('g:snipMate.snippet_version')
echom 'The legacy SnipMate parser is deprecated. Please see :h SnipMate-deprecate.'
endif
" Add default scope aliases, without overriding user settings
let g:snipMate.scope_aliases = get(g:snipMate, 'scope_aliases', {})
if exists('g:snipMate_no_default_aliases')