ããç°¡åã«è¡ããªãã®ã Vim ã®æãããã¨ããã
ã¨ãã§ããªãè½ã¨ãç©´ãããã¾ãã
æ¸ãæããé¢æ°ã§ã¹ã¯ãªãããã¼ã«ã«ãªå¤æ°ã«ã¢ã¯ã»ã¹ãããã¨ããã¨ãé¢æ°ã® ID ã«é¢ä¿ãªãé¢æ°ãå®ç¾©ãããã¡ã¤ã«ã®ã¹ã¯ãªãããã¼ã«ã«ãªå¤æ°ãè¦ã¦ãã¾ãã¾ãã
a.vim
let s:value1 = 'a.vim:value1' let s:value2 = 'a.vim:value2' function! s:get_value() return s:value1 endfunction " A wrapper to call from other scope. function! GetValue() return s:get_value() endfunction
b.vim
source hookfunc.vim source a.vim let s:value1 = 'b.vim:value1' let s:value2 = 'b.vim:value2' function! s:get_value() return s:value2 endfunction echo GetValue() " => a.vim:value1 call HookFunc(GetFunc(fnamemodify("a.vim", ":p"), "get_value"), GetFunc(expand("%:p"), "get_value")) echo GetValue() " => b.vim:value2 (not "a.vim:value2")
ããã§ã¯ã¹ã¯ãªãããã¼ã«ã«ãªå¤æ°ãåç
§ããé¢æ°ã¯å¤ããæ¸ãæããããªããé常ã«æ®å¿µã
ãã£ã¨ç°¡åã«æ¸ãæãããã¨ä»¥ä¸ã®ãããªç©ã¾ã§æ¸ãã¦ãã®ã«(æ¸ãã¦ãéä¸ã§ãã®äºå®ã«æ°ä»ãã)ã
" hookfunc.vim command! -nargs=+ Hookfunc execute s:hookfunc(<q-args>) function! s:get_script_id(fname) let snlist = '' redir => snlist silent! scriptnames redir END for line in split(tolower(substitute(snlist, '\\', '/', 'g')), "\n") if line =~? '\V' . a:fname . '\$' return matchstr(line, '^\s*\zs\d\+') endif endfor endfunction function! s:hookfunc(args) let [file, func] = split(a:args, ':') return 'function! <SNR>' . s:get_script_id(file) . '_' . func endfunction " ------------------------------------------------------------------ function! s:hoge(text) echo "Hello, " . a:text endfunction call s:hoge('world.') " => Hello, world. Hookfunc hookfunc.vim:hoge(text) echo "Goodbye, " . a:text endfunction call s:hoge('world.') " => Goodbye, world.
Vim ã®æ·±æ·µã¯æ·±ããã¦è¦ãè¾¼ããã¨ããã¨æãã¬æªæãããã®ã§æ°ãä»ãã¾ãããã