Last active
September 20, 2015 19:21
-
-
Save amashigeseiji/b4d2bc5a17e653e5d93b to your computer and use it in GitHub Desktop.
vimscript で動的に function 定義をする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" vimscript | |
" functionじゃないrcファイルとかをまるごとfunctionとして再定義する | |
" 動的なfunction生成できる | |
" 下の例だと、外部ファイルの内容をまるまる function にする | |
function! s:define_function(funcname, file) dict | |
let l:file = readfile(a:file) | |
let l:def = "function! s:" . a:funcname . "() dict\n" | |
for i in l:file | |
let l:def .= i . "\n" | |
endfor | |
let l:def .= 'endfunction' | |
exec l:def | |
let self.new_difined = function('s:new_difined') | |
endfunction | |
let hoge = { | |
\ 'define_function': function('s:define_function') | |
\} | |
call hoge.define_function('new_defined', 'hoge.vim') | |
call hoge.new_difined() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
定義は読み込んでおきたいけど遅延実行させたいときとかに使えそう