vice.vim


Ⅰ. 插件描述

MOP for vim script

Ⅱ. 基本信息

创建日期:  2010-11-19
使用用户:  2
Github星:  3
插件作者:  Fujiwara Takuya

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'tyru/vice-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'tyru/vice-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'tyru/vice-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/tyru/vice.vim

Ⅳ. 文档说明

# Features

Inheritance

" vice.vim needs to know the SID of where the methods are defined.
function! s:SID()
    return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
endfunction

" 'generate_stub' is defaultly 0 for some reasons.
" you can omit the vice#class()'s 3rd argument
" if you like default one.
let s:VICE_OPTIONS = {'generate_stub': 1}
" Trait

let s:Printable = vice#trait('Printable', s:SID(), s:VICE_OPTIONS)

function! {s:Printable.method('print')}(self)
    echon a:self.message()
endfunction

function! {s:Printable.method('say')}(self)
    echo a:self.message()
endfunction

function! s:Printable.requires()
    return ['message']
endfunction
let s:Foo = vice#class('Foo', s:SID(), s:VICE_OPTIONS)
call s:Foo.with(s:Printable)

function! {s:Foo.method('message')}(self)
    return 'foo'
endfunction
let s:Bar = vice#class('Bar', s:SID(), s:VICE_OPTIONS)
call s:Bar.with(s:Printable)

function! {s:Bar.method('message')}(self)
    return 'bar'
endfunction
echon "--- Foo ---\n"

let foo = s:Foo.new()
" "foo"
call foo.print()
" "foo" with newline
call foo.say()

echon "\n"
echon "--- Bar ---\n"

let bar = s:Bar.new()
" "bar"
call bar.print()
" "bar" with newline
call bar.say()

Trait (Perl's role-like feature)

  • Trait can provide some methods
  • Trait can require some methods to implement

TODO

Type constraints

let s:class = vice#new('Klass')
let meta = s:class._meta

" Create Pair type (local to s:buffer_string object).
function! meta.subtype('Pair', 'List').where(Value)
    return len(a:Value) == 2
endfunction

" Create Pair type (local to s:buffer_string object).
function! meta.subtype('Pair', 'List').define()
    function self.where(Value)
        return len(a:Value) == 2
    endfunction
endfunction
  • .where()
  • when it should be called?

    • How do other languages' system do that?
    • it should be called when assigning a value.

etc.

  • Moose(Perl)'s before(), after()

    • override (or more like Aspect-Oriented?)

添加新评论