Changeset 321 for lang/vim

Show
Ignore:
Timestamp:
10/01/07 04:56:56 (6 years ago)
Author:
kana
Message:

lang/vim/surround:
* Support dynamic template for user-defined objects.

Location:
lang/vim/surround/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/surround/trunk/doc/surround.txt

    r320 r321  
    230230CHANGELOG                                       *surround-changelog* 
    231231 
     2322007-10-01T03:43:51+09:00       kana    <http://nicht.s8.xrea.com/> 
     233 
     234        - Support dynamic template for |surround-customizing|. 
     235          Now templates of user-defined surrounding objects may be functions 
     236          or funcrefs which must return a template. 
     237 
     238          For example, the following setting provides two-stroke keys "xb" and 
     239          "xB" for some templates. 
     240> 
     241          function g:surround_{char2nr('x')}() 
     242            let c = nr2char(getchar()) 
     243            if c ==# 'b' 
     244              return "(((\r)))" 
     245            elseif c ==# 'B' 
     246              return "{{{\r}}}" 
     247            else 
     248              return '' 
     249            endif 
     250          endfunction 
     251< 
    2322522007-10-01T00:25:20+09:00       kana    <http://nicht.s8.xrea.com/> 
    233253 
  • lang/vim/surround/trunk/plugin/surround.vim

    r320 r321  
    617617function! s:get_user_defined_object(char) 
    618618    if exists("b:surround_".char2nr(a:char)) 
    619         return b:surround_{char2nr(a:char)} 
     619        let Value = b:surround_{char2nr(a:char)} 
     620    elseif exists("*b:surround_".char2nr(a:char)) 
     621        let Value = function('b:surround_'.char2nr(a:char)) 
    620622    elseif exists("g:surround_".char2nr(a:char)) 
    621         return g:surround_{char2nr(a:char)} 
    622     else 
    623         return '' 
     623        let Value = g:surround_{char2nr(a:char)} 
     624    elseif exists("*g:surround_".char2nr(a:char)) 
     625        let Value = function('g:surround_'.char2nr(a:char)) 
     626    else 
     627        let Value = '' 
     628    endif 
     629 
     630    if type(Value) == type('string') 
     631        return Value 
     632    else  " function? 
     633        return Value() 
    624634    endif 
    625635endfunction