From d3f4db7367ff7966bbcb47f303297f4a447205fc Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 4 Jun 2012 16:37:24 +0900 Subject: [PATCH] calculate 'indentation' from shiftwidth. close #78 --- autoload/zencoding.vim | 25 ++++++++++++++++++------- autoload/zencoding/lang/css.vim | 7 +------ autoload/zencoding/lang/html.vim | 7 +------ unittest.vim | 6 +++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/autoload/zencoding.vim b/autoload/zencoding.vim index b823314..a4c6179 100644 --- a/autoload/zencoding.vim +++ b/autoload/zencoding.vim @@ -1,7 +1,7 @@ "============================================================================= " zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Jun-2012. +" Last Change: 04-Jun-2012. let s:save_cpo = &cpo set cpo&vim @@ -23,6 +23,22 @@ function! zencoding#useFilter(filters, filter) return 0 endfunction +function! zencoding#getIndentation(...) + if a:0 > 0 + let type = a:1 + else + let type = zencoding#getFileType() + endif + if has_key(s:zen_settings, type) && has_key(s:zen_settings[type], 'indentation') + let indent = s:zen_settings[type].indentation + elseif has_key(s:zen_settings, 'indentation') + let indent = s:zen_settings.indentation + else + let indent = (&l:expandtab || &l:tabstop != &l:shiftwidth) ? repeat(' ', &l:shiftwidth) : "\t" + endif + return indent +endfunction + function! zencoding#isExtends(type, extend) if a:type == a:extend return 1 @@ -106,11 +122,7 @@ function! zencoding#toString(...) let filters = ['html'] endif - if has_key(s:zen_settings, type) && has_key(s:zen_settings[type], 'indentation') - let indent = s:zen_settings[type].indentation - else - let indent = s:zen_settings.indentation - endif + let indent = zencoding#getIndentation(type) let itemno = 0 let str = '' let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1) @@ -599,7 +611,6 @@ endfunction unlet! s:zen_settings let s:zen_settings = { -\ 'indentation': "\t", \ 'lang': "en", \ 'charset': "UTF-8", \ 'css': { diff --git a/autoload/zencoding/lang/css.vim b/autoload/zencoding/lang/css.vim index c492305..5495f9f 100644 --- a/autoload/zencoding/lang/css.vim +++ b/autoload/zencoding/lang/css.vim @@ -7,12 +7,7 @@ function! zencoding#lang#css#parseIntoTree(abbr, type) let type = a:type let settings = zencoding#getSettings() - - if has_key(settings[type], 'indentation') - let indent = settings[type].indentation - else - let indent = settings.indentation - endif + let indent = zencoding#getIndentation(type) let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } diff --git a/autoload/zencoding/lang/html.vim b/autoload/zencoding/lang/html.vim index a2848ad..5f13e68 100644 --- a/autoload/zencoding/lang/html.vim +++ b/autoload/zencoding/lang/html.vim @@ -41,12 +41,7 @@ function! zencoding#lang#html#parseIntoTree(abbr, type) if len(type) == 0 | let type = 'html' | endif let settings = zencoding#getSettings() - - if has_key(settings[type], 'indentation') - let indent = settings[type].indentation - else - let indent = settings.indentation - endif + let indent = zencoding#getIndentation(type) " try 'foo' to (foo-x) let rabbr = zencoding#getExpandos(type, abbr) diff --git a/unittest.vim b/unittest.vim index abffcb9..9a7a51f 100644 --- a/unittest.vim +++ b/unittest.vim @@ -1,6 +1,6 @@ if exists('g:user_zen_settings') let s:old_user_zen_settings = g:user_zen_settings - unlet! g:user_zen_settings + let g:user_zen_settings = { 'indentation': "\t" } endif function! s:reload(d) @@ -97,13 +97,13 @@ function! s:testExpandAbbr() unlet! res | let res = zencoding#ExpandWord(query, type, 0) endif if stridx(result, '$$$$') != -1 - if res == result + if res ==# result call s:show_ok() else call s:show_ng(n+1, result, res) endif else - if res == result + if res ==# result call s:show_ok() else call s:show_ng(n+1, result, res)