Skip to content

Commit 352025d

Browse files
authored
Merge pull request #759 from vim-jp/fix/document-example-20201003
2 parents 5c2b161 + 45df393 commit 352025d

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Module | Description
117117
### Install modules for your own plugin
118118

119119
Use `:Vitalize` to install modules.
120+
Assuming your Vim plugin name is `your_plugin_name` and plugin directory is `your_plugin_dir`.
120121
Please see [the help](doc/vitalizer.txt) for more details.
121122

122123
```vim
@@ -133,45 +134,61 @@ repository
133134

134135
### Use vital functions
135136

136-
Assuming your Vim plugin name is `ujihisa`. You can define your utility
137-
function set `ujihisa#util` just by
137+
Assuming your Vim plugin name is `your_plugin_name`. You can define your utility
138+
function set `your_plugin_name#util` just by
138139

139140
```vim
140-
let s:V = vital#ujihisa#new()
141-
function! ujihisa#util#system(...)
142-
return call(s:V.system, a:000, s:V)
141+
let s:Process = vital#your_plugin_name#import('System.Process')
142+
143+
function! your_plugin_name#util#system(...)
144+
return s:Process.execute(a:000)
143145
endfunction
146+
" run
147+
" echo your_plugin_name#util#system('echo','abc')
148+
" -> $ echo abc
144149
```
145150

146-
and then you can call functions by `ujihisa#util#system()`, without taking care
151+
and then you can call functions by `your_plugin_name#util#system()`, without taking care
147152
of `vital.vim` itself. It's all hidden.
148153

149154
Vital has module system. The below is an example to import/load a module
150-
`Data.OrderedSet` and to call a function `f()` of the module.
155+
`Math` and to call a function `lcm()` of the module.
151156

152157
```vim
153158
" Recommended way
154-
let s:V = vital#ujihisa#new()
155-
let s:O = s:V.import('Data.OrderedSet')
156-
call s:O.f()
159+
let s:M = vital#your_plugin_name#import('Math')
160+
call s:M.lcm([2, 3, 4])
161+
" -> 12
162+
```
163+
164+
or
165+
166+
```vim
167+
" Alternative way
168+
let s:V = vital#your_plugin_name#new()
169+
let s:M = s:V.import('Math')
170+
call s:M.lcm([2, 3, 4])
171+
" -> 12
157172
```
158173

159174
or
160175

161176
```vim
162-
" Recommended way only if you rarely use the module
163-
let s:V = vital#ujihisa#new()
164-
call s:V.load('Data.OrderedSet')
165-
call s:V.Data.OrderedSet.f()
177+
" Alternative way only if you rarely use the module
178+
let s:V = vital#your_plugin_name#new()
179+
call s:V.load('Math')
180+
call s:V.Math.lcm([2, 3, 4])
181+
" -> 12
166182
```
167183

168184
or
169185

170186
```vim
171187
" Available, but we don't recommend this very much
172-
let s:V = vital#ujihisa#new()
173-
call s:V.import('Data.OrderedSet', s:)
174-
call s:f()
188+
let s:V = vital#your_plugin_name#new()
189+
call s:V.import('Math', s:)
190+
call s:lcm([2, 3, 4])
191+
" -> 12
175192
```
176193

177194
We recommend you to use a capital letter for a Vital module dictionary to assign.

doc/vital.txt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,41 @@ Please read the docs of each module before using them.
3636
==============================================================================
3737
USAGE *Vital-usage*
3838

39-
Assuming your Vim plugin name is "ujihisa", you can define your utility
40-
function set 'ujihisa#util' just by
39+
Assuming your Vim plugin name is "your_plugin_name". You can define your utility
40+
function set "your_plugin_name#util" just by
4141
>
42-
let s:P = vital#ujihisa#new().import('Process')
43-
function! ujihisa#util#system(...)
44-
return call(s:P.system, a:000, s:P)
42+
let s:Process = vital#your_plugin_name#import('System.Process')
43+
44+
function! your_plugin_name#util#system(...)
45+
return s:Process.execute(a:000)
4546
endfunction
4647
<
47-
and then you can call functions by 'ujihisa#util#system()', without taking
48+
and then you can call functions by 'your_plugin_name#util#system()', without taking
4849
care of |vital.vim| itself. It's all hidden.
4950

5051
|Vital| has module system. The below is an example to import/load a module
51-
"data/ordered_set" and to call a function "f()" of the module.
52+
"Math" and to call a function "lcm()" of the module.
5253
>
53-
let s:V = vital#ujihisa#new()
54-
let s:O = s:V.import('Data.OrderedSet')
55-
call s:O.f()
54+
let s:M = vital#your_plugin_name#import('Math')
55+
call s:M.lcm([2, 3, 4])
5656
<
5757
or
5858
>
59-
let s:V = vital#ujihisa#new()
60-
call s:V.load('Data.OrderedSet')
61-
call s:V.Data.OrderedSet.f()
59+
let s:V = vital#your_plugin_name#new()
60+
let s:M = s:V.import('Math')
61+
call s:M.lcm([2, 3, 4])
6262
<
6363
or
6464
>
65-
let s:V = vital#ujihisa#new()
66-
call s:V.import('Data.OrderedSet', s:)
67-
call s:f()
65+
let s:V = vital#your_plugin_name#new()
66+
call s:V.load('Math')
67+
call s:V.Math.lcm([2, 3, 4])
68+
<
69+
or
70+
>
71+
let s:V = vital#your_plugin_name#new()
72+
call s:V.import('Math', s:)
73+
call s:lcm([2, 3, 4])
6874
<
6975
We recommend you to use a capital letter for a Vital module dictionary to
7076
assign as Vital convention. That makes your code more readable among Vital

0 commit comments

Comments
 (0)