Improve variables methods
This commit is contained in:
parent
4f35262ae1
commit
3e60de00a3
@ -77,7 +77,7 @@ endfunction"}}}
|
|||||||
function! neosnippet#jump(cur_text, col) "{{{
|
function! neosnippet#jump(cur_text, col) "{{{
|
||||||
call s:skip_next_auto_completion()
|
call s:skip_next_auto_completion()
|
||||||
|
|
||||||
let expand_stack = neosnippet#variables#get_expand_stack()
|
let expand_stack = neosnippet#variables#expand_stack()
|
||||||
|
|
||||||
" Get patterns and count.
|
" Get patterns and count.
|
||||||
if empty(expand_stack)
|
if empty(expand_stack)
|
||||||
@ -103,7 +103,7 @@ function! neosnippet#jump(cur_text, col) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Not found.
|
" Not found.
|
||||||
let expand_stack = neosnippet#variables#get_expand_stack()
|
let expand_stack = neosnippet#variables#expand_stack()
|
||||||
let expand_stack = expand_stack[: -2]
|
let expand_stack = expand_stack[: -2]
|
||||||
|
|
||||||
return s:search_outof_range(a:col)
|
return s:search_outof_range(a:col)
|
||||||
@ -171,7 +171,7 @@ function! neosnippet#expand(cur_text, col, trigger_name) "{{{
|
|||||||
let &l:foldmethod = 'manual'
|
let &l:foldmethod = 'manual'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let expand_stack = neosnippet#variables#get_expand_stack()
|
let expand_stack = neosnippet#variables#expand_stack()
|
||||||
|
|
||||||
try
|
try
|
||||||
call setline('.', snippet_lines[0])
|
call setline('.', snippet_lines[0])
|
||||||
@ -214,7 +214,7 @@ endfunction"}}}
|
|||||||
function! neosnippet#expand_target() "{{{
|
function! neosnippet#expand_target() "{{{
|
||||||
let trigger = input('Please input snippet trigger: ',
|
let trigger = input('Please input snippet trigger: ',
|
||||||
\ '', 'customlist,neosnippet#complete_target_snippets')
|
\ '', 'customlist,neosnippet#complete_target_snippets')
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
if !has_key(neosnippet#get_snippets(), trigger) ||
|
if !has_key(neosnippet#get_snippets(), trigger) ||
|
||||||
\ neosnippet#get_snippets()[trigger].snip !~#
|
\ neosnippet#get_snippets()[trigger].snip !~#
|
||||||
\ neosnippet#get_placeholder_target_marker_pattern()
|
\ neosnippet#get_placeholder_target_marker_pattern()
|
||||||
@ -229,7 +229,7 @@ function! neosnippet#expand_target() "{{{
|
|||||||
call neosnippet#expand_target_trigger(trigger)
|
call neosnippet#expand_target_trigger(trigger)
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#expand_target_trigger(trigger) "{{{
|
function! neosnippet#expand_target_trigger(trigger) "{{{
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let neosnippet.target = substitute(
|
let neosnippet.target = substitute(
|
||||||
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ function! s:indent_snippet(begin, end) "{{{
|
|||||||
|
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
|
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
|
|
||||||
let equalprg = &l:equalprg
|
let equalprg = &l:equalprg
|
||||||
try
|
try
|
||||||
@ -366,7 +366,7 @@ function! s:expand_placeholder(start, end, holder_cnt, line, ...) "{{{
|
|||||||
\ '\\d\\+', a:holder_cnt, '')
|
\ '\\d\\+', a:holder_cnt, '')
|
||||||
let current_line = getline(a:line)
|
let current_line = getline(a:line)
|
||||||
let match = match(current_line, pattern)
|
let match = match(current_line, pattern)
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
|
|
||||||
let default_pattern = substitute(
|
let default_pattern = substitute(
|
||||||
\ neosnippet#get_placeholder_marker_default_pattern(),
|
\ neosnippet#get_placeholder_marker_default_pattern(),
|
||||||
@ -438,7 +438,7 @@ function! s:expand_placeholder(start, end, holder_cnt, line, ...) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! s:expand_target_placeholder(line, col) "{{{
|
function! s:expand_target_placeholder(line, col) "{{{
|
||||||
" Expand target
|
" Expand target
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let next_line = getline(a:line)[a:col-1 :]
|
let next_line = getline(a:line)[a:col-1 :]
|
||||||
let target_lines = split(neosnippet.target, '\n', 1)
|
let target_lines = split(neosnippet.target, '\n', 1)
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ function! s:eval_snippet(snippet_text) "{{{
|
|||||||
|
|
||||||
return snip_word
|
return snip_word
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_current_neosnippet() "{{{
|
function! neosnippet#variables#current_neosnippet() "{{{
|
||||||
if !exists('b:neosnippet')
|
if !exists('b:neosnippet')
|
||||||
let b:neosnippet = {
|
let b:neosnippet = {
|
||||||
\ 'snippets' : {},
|
\ 'snippets' : {},
|
||||||
@ -572,12 +572,12 @@ endfunction"}}}
|
|||||||
function! neosnippet#get_snippets() "{{{
|
function! neosnippet#get_snippets() "{{{
|
||||||
call neosnippet#init#check()
|
call neosnippet#init#check()
|
||||||
|
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let snippets = copy(neosnippet.snippets)
|
let snippets = copy(neosnippet.snippets)
|
||||||
for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
|
for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
|
||||||
call neosnippet#commands#_make_cache(filetype)
|
call neosnippet#commands#_make_cache(filetype)
|
||||||
call extend(snippets,
|
call extend(snippets,
|
||||||
\ neosnippet#variables#get_snippets()[filetype], 'keep')
|
\ neosnippet#variables#snippets()[filetype], 'keep')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let cur_text = neosnippet#util#get_cur_text()
|
let cur_text = neosnippet#util#get_cur_text()
|
||||||
@ -594,20 +594,20 @@ function! neosnippet#get_snippets() "{{{
|
|||||||
return snippets
|
return snippets
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_snippets_directory() "{{{
|
function! neosnippet#get_snippets_directory() "{{{
|
||||||
let snippets_dir = copy(neosnippet#variables#get_snippets_dir())
|
let snippets_dir = copy(neosnippet#variables#snippets_dir())
|
||||||
if !get(g:neosnippet#disable_runtime_snippets,
|
if !get(g:neosnippet#disable_runtime_snippets,
|
||||||
\ neosnippet#get_filetype(),
|
\ neosnippet#get_filetype(),
|
||||||
\ get(g:neosnippet#disable_runtime_snippets, '_', 0))
|
\ get(g:neosnippet#disable_runtime_snippets, '_', 0))
|
||||||
let snippets_dir += neosnippet#variables#get_runtime_dir()
|
let snippets_dir += neosnippet#variables#runtime_dir()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return snippets_dir
|
return snippets_dir
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_user_snippets_directory() "{{{
|
function! neosnippet#get_user_snippets_directory() "{{{
|
||||||
return copy(neosnippet#variables#get_snippets_dir())
|
return copy(neosnippet#variables#snippets_dir())
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_runtime_snippets_directory() "{{{
|
function! neosnippet#get_runtime_snippets_directory() "{{{
|
||||||
return copy(neosnippet#variables#get_runtime_dir())
|
return copy(neosnippet#variables#runtime_dir())
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_filetype() "{{{
|
function! neosnippet#get_filetype() "{{{
|
||||||
if !exists('s:exists_context_filetype')
|
if !exists('s:exists_context_filetype')
|
||||||
@ -661,6 +661,7 @@ function! neosnippet#complete_target_snippets(arglead, cmdline, cursorpos) "{{{
|
|||||||
\ && v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"), 'v:val.word')
|
\ && v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"), 'v:val.word')
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
" Get marker patterns.
|
||||||
function! neosnippet#get_placeholder_target_marker_pattern() "{{{
|
function! neosnippet#get_placeholder_target_marker_pattern() "{{{
|
||||||
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
|
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
@ -767,7 +768,7 @@ function! s:skip_next_auto_completion() "{{{
|
|||||||
call neocomplete#skip_next_complete()
|
call neocomplete#skip_next_complete()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let neosnippet.trigger = 0
|
let neosnippet.trigger = 0
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ function! neosnippet#commands#_make_cache(filetype) "{{{
|
|||||||
let filetype = 'nothing'
|
let filetype = 'nothing'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippets = neosnippet#variables#get_snippets()
|
let snippets = neosnippet#variables#snippets()
|
||||||
if has_key(snippets, filetype)
|
if has_key(snippets, filetype)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@ -112,14 +112,14 @@ function! neosnippet#commands#_make_cache(filetype) "{{{
|
|||||||
call neosnippet#parser#_parse(snippet, snippets_file)
|
call neosnippet#parser#_parse(snippet, snippets_file)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let snippets = neosnippet#variables#get_snippets()
|
let snippets = neosnippet#variables#snippets()
|
||||||
let snippets[filetype] = snippet
|
let snippets[filetype] = snippet
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! neosnippet#commands#_source(filename) "{{{
|
function! neosnippet#commands#_source(filename) "{{{
|
||||||
call neosnippet#init#check()
|
call neosnippet#init#check()
|
||||||
|
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:initialize_script_variables() "{{{
|
function! s:initialize_script_variables() "{{{
|
||||||
" Set runtime dir.
|
" Set runtime dir.
|
||||||
let runtime_dir = neosnippet#variables#get_runtime_dir()
|
let runtime_dir = neosnippet#variables#runtime_dir()
|
||||||
let runtime_dir += split(globpath(&runtimepath,
|
let runtime_dir += split(globpath(&runtimepath,
|
||||||
\ 'autoload/neosnippet/snippets'), '\n')
|
\ 'autoload/neosnippet/snippets'), '\n')
|
||||||
if g:neosnippet#enable_snipmate_compatibility
|
if g:neosnippet#enable_snipmate_compatibility
|
||||||
@ -57,7 +57,7 @@ function! s:initialize_script_variables() "{{{
|
|||||||
call map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
|
call map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
|
||||||
|
|
||||||
" Set snippets_dir.
|
" Set snippets_dir.
|
||||||
let snippets_dir = neosnippet#variables#get_snippets_dir()
|
let snippets_dir = neosnippet#variables#snippets_dir()
|
||||||
for dir in neosnippet#util#option2list(g:neosnippet#snippets_directory)
|
for dir in neosnippet#util#option2list(g:neosnippet#snippets_directory)
|
||||||
let dir = neosnippet#util#expand(dir)
|
let dir = neosnippet#util#expand(dir)
|
||||||
if !isdirectory(dir) && !neosnippet#util#is_sudo()
|
if !isdirectory(dir) && !neosnippet#util#is_sudo()
|
||||||
@ -130,11 +130,11 @@ function! s:initialize_others() "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:on_insert_leave() "{{{
|
function! s:on_insert_leave() "{{{
|
||||||
let expand_stack = neosnippet#variables#get_expand_stack()
|
let expand_stack = neosnippet#variables#expand_stack()
|
||||||
|
|
||||||
" Get patterns and count.
|
" Get patterns and count.
|
||||||
if empty(expand_stack)
|
if empty(expand_stack)
|
||||||
\ || neosnippet#get_current_neosnippet().trigger
|
\ || neosnippet#variables#current_neosnippet().trigger
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ function! neosnippet#mappings#_register_oneshot_snippet() "{{{
|
|||||||
let selected_text = substitute(selected_text,
|
let selected_text = substitute(selected_text,
|
||||||
\'^' . base_indent, '', 'g')
|
\'^' . base_indent, '', 'g')
|
||||||
|
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let options = neosnippet#parser#_initialize_snippet_options()
|
let options = neosnippet#parser#_initialize_snippet_options()
|
||||||
let options.word = 1
|
let options.word = 1
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ function! s:trigger(function) "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Get selected text.
|
" Get selected text.
|
||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let neosnippet.trigger = 1
|
let neosnippet.trigger = 1
|
||||||
if mode() ==# 's' && neosnippet.selected_text =~ '^#:'
|
if mode() ==# 's' && neosnippet.selected_text =~ '^#:'
|
||||||
let expr .= "\<C-o>\"_d"
|
let expr .= "\<C-o>\"_d"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: variables.vim
|
" FILE: variables.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 19 Nov 2013.
|
" Last Modified: 21 Nov 2013.
|
||||||
" License: MIT license {{{
|
" License: MIT license {{{
|
||||||
" Permission is hereby granted, free of charge, to any person obtaining
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
" a copy of this software and associated documentation files (the
|
" a copy of this software and associated documentation files (the
|
||||||
@ -27,14 +27,26 @@
|
|||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
function! neosnippet#variables#get_expand_stack() "{{{
|
function! neosnippet#variables#current_neosnippet() "{{{
|
||||||
|
if !exists('b:neosnippet')
|
||||||
|
let b:neosnippet = {
|
||||||
|
\ 'snippets' : {},
|
||||||
|
\ 'selected_text' : '',
|
||||||
|
\ 'target' : '',
|
||||||
|
\ 'trigger' : 0,
|
||||||
|
\}
|
||||||
|
endif
|
||||||
|
|
||||||
|
return b:neosnippet
|
||||||
|
endfunction"}}}
|
||||||
|
function! neosnippet#variables#expand_stack() "{{{
|
||||||
if !exists('s:expand_stack')
|
if !exists('s:expand_stack')
|
||||||
let s:expand_stack = []
|
let s:expand_stack = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return s:expand_stack
|
return s:expand_stack
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#variables#get_snippets() "{{{
|
function! neosnippet#variables#snippets() "{{{
|
||||||
if !exists('s:snippets')
|
if !exists('s:snippets')
|
||||||
let s:snippets= {}
|
let s:snippets= {}
|
||||||
endif
|
endif
|
||||||
@ -48,14 +60,14 @@ function! neosnippet#variables#set_snippets(list) "{{{
|
|||||||
|
|
||||||
let s:snippets = a:list
|
let s:snippets = a:list
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#variables#get_snippets_dir() "{{{
|
function! neosnippet#variables#snippets_dir() "{{{
|
||||||
if !exists('s:snippets_dir')
|
if !exists('s:snippets_dir')
|
||||||
let s:snippets_dir = []
|
let s:snippets_dir = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return s:snippets_dir
|
return s:snippets_dir
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#variables#get_runtime_dir() "{{{
|
function! neosnippet#variables#runtime_dir() "{{{
|
||||||
if !exists('s:runtime_dir')
|
if !exists('s:runtime_dir')
|
||||||
let s:runtime_dir = []
|
let s:runtime_dir = []
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user