From 6cebc087a23cd7a6a13a2780bbb6c3e92ce03ef5 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 30 Sep 2012 17:17:31 +0900 Subject: [PATCH] - Refactored variables. --- autoload/neosnippet.vim | 45 +++++++++++++++++++++--------------- autoload/neosnippet/util.vim | 8 +++++++ doc/neosnippet.txt | 1 + plugin/neosnippet.vim | 7 +----- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 74f3c88..1112a90 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -27,6 +27,15 @@ let s:save_cpo = &cpo set cpo&vim +" Global options definition."{{{ +call neosnippet#util#set_default('g:neosnippet#disable_runtime_snippets', + \ 0, 'g:neocomplcache_snippets_disable_runtime_snippets') +call neosnippet#util#set_default('g:neosnippet#snippets_directory', + \ '', 'g:neocomplcache_snippets_dir') +call neosnippet#util#set_default('g:neosnippet#disable_select_mode_mappings', + \ 0, 'g:neocomplcache_disable_select_mode_mappings') +"}}} + function! s:initialize()"{{{ " Initialize. let s:snippets_expand_stack = [] @@ -35,7 +44,7 @@ function! s:initialize()"{{{ let s:runtime_dir = split(globpath(&runtimepath, \ 'autoload/neosnippet/snippets'), '\n') - if !g:neocomplcache_snippets_disable_runtime_snippets + if !g:neosnippet#disable_runtime_snippets " Set snippets dir. let s:snippets_dir += (exists('g:snippets_dir') ? \ split(g:snippets_dir, '\s*,\s*') @@ -43,25 +52,23 @@ function! s:initialize()"{{{ \ + s:runtime_dir endif - if exists('g:neocomplcache_snippets_dir') - for dir in split(g:neocomplcache_snippets_dir, '\s*,\s*') - let dir = neosnippet#util#expand(dir) - if !isdirectory(dir) - call mkdir(dir, 'p') - endif - call add(s:snippets_dir, dir) - endfor - endif + for dir in split(g:neocomplcache_snippets_dir, '\s*,\s*') + let dir = neosnippet#util#expand(dir) + if !isdirectory(dir) + call mkdir(dir, 'p') + endif + call add(s:snippets_dir, dir) + endfor call map(s:snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")') if has('conceal') " Supported conceal features. augroup neosnippet autocmd BufNewFile,BufRead,ColorScheme * - \ syn match neocomplcacheExpandSnippets + \ syn match neosnippetExpandSnippets \ '<`\d\+:\|`>\|<{\d\+:\|}>' conceal autocmd BufNewFile,BufRead,ColorScheme * - \ execute 'syn match neocomplcacheExpandSnippets' + \ execute 'syn match neosnippetExpandSnippets' \ '''<`\d\+\\\@\|<{\d\+\\\@\|' \ .s:get_mirror_placeholder_marker_pattern()."'" \ 'conceal cchar=$' @@ -69,14 +76,14 @@ function! s:initialize()"{{{ else augroup neosnippet autocmd BufNewFile,BufRead,ColorScheme * - \ execute 'syn match neocomplcacheExpandSnippets' + \ execute 'syn match neosnippetExpandSnippets' \ "'".s:get_placeholder_marker_pattern(). '\|' \ .s:get_sync_placeholder_marker_pattern().'\|' \ .s:get_mirror_placeholder_marker_pattern()."'" augroup END endif - hi def link NeoComplCacheExpandSnippets Special + hi def link neosnippetExpandSnippets Special command! -nargs=? -complete=customlist,neocomplcache#filetype_complete \ NeoComplCacheEditSnippets @@ -88,8 +95,8 @@ function! s:initialize()"{{{ \ NeoComplCacheCachingSnippets \ call neosnippet#caching_snippets() - " Select mode mappings. - if !exists('g:neocomplcache_disable_select_mode_mappings') + " Select mode mappings."{{{ + if g:neosnippet#disable_select_mode_mappings snoremap a snoremap a snoremap a @@ -101,7 +108,7 @@ function! s:initialize()"{{{ snoremap ^ a^ snoremap \ a\ snoremap a - endif + endif"}}} " Caching _ snippets. call neosnippet#caching_snippets('_') @@ -109,14 +116,14 @@ function! s:initialize()"{{{ " Initialize check. call neosnippet#caching() - if neocomplcache#exists_echodoc() + if get(g:, 'loaded_echodoc', 0) call echodoc#register('snippets_complete', s:doc_dict) endif endfunction"}}} " For echodoc."{{{ let s:doc_dict = { - \ 'name' : 'snippets_complete', + \ 'name' : 'neosnippet', \ 'rank' : 100, \ 'filetypes' : {}, \ } diff --git a/autoload/neosnippet/util.vim b/autoload/neosnippet/util.vim index 3faef9a..8253fcb 100644 --- a/autoload/neosnippet/util.vim +++ b/autoload/neosnippet/util.vim @@ -61,6 +61,14 @@ function! neosnippet#util#expand(path)"{{{ \ '^\$\h\w*', '\=eval(submatch(0))', '') : \ a:path) endfunction"}}} +function! neosnippet#util#set_default(var, val, ...) "{{{ + if !exists(a:var) || type({a:var}) != type(a:val) + let alternate_var = get(a:000, 0, '') + + let {a:var} = exists(alternate_var) ? + \ {alternate_var} : a:val + endif +endfunction"}}} function! neosnippet#util#set_dictionary_helper(...)"{{{ return call(s:V.set_dictionary_helper, a:000) endfunction"}}} diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index bbd4173..b89d8f6 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -321,6 +321,7 @@ CHANGELOG *neosnippet-changelog* - Changed runtime directory. - Vitalized. - Deleted neocomplcache#util functions. +- Refactored variables. 2012-09-27 - Ver.3 development is started. diff --git a/plugin/neosnippet.vim b/plugin/neosnippet.vim index d662445..cdf4c09 100644 --- a/plugin/neosnippet.vim +++ b/plugin/neosnippet.vim @@ -1,7 +1,7 @@ "============================================================================= " FILE: neosnippet.vim " AUTHOR: Shougo Matsushita -" Last Modified: 28 Sep 2012. +" Last Modified: 30 Sep 2012. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -36,11 +36,6 @@ set cpo&vim " Obsolute options check."{{{ "}}} -" Global options definition."{{{ -if !exists('g:neocomplcache_snippets_disable_runtime_snippets') - let g:neocomplcache_snippets_disable_runtime_snippets = 0 -endif -"}}} " Plugin key-mappings."{{{ inoremap (neosnippet_expand_or_jump)