874
|
1 *if_mzsch.txt* For Vim version 7.0. Last change: 2006 Apr 30
|
14
|
2
|
|
3
|
|
4 VIM REFERENCE MANUAL by Sergey Khorev
|
|
5
|
|
6
|
|
7 The MzScheme Interface to Vim *mzscheme* *MzScheme*
|
|
8
|
|
9 1. Commands |mzscheme-commands|
|
|
10 2. Examples |mzscheme-examples|
|
|
11 3. Threads |mzscheme-threads|
|
|
12 4. The Vim access procedures |mzscheme-vim|
|
625
|
13 5. Dynamic loading |mzscheme-dynamic|
|
14
|
14
|
|
15 {Vi does not have any of these commands}
|
|
16
|
|
17 The MzScheme interface is available only if Vim was compiled with the
|
|
18 |+mzscheme| feature.
|
|
19
|
|
20 Based on the work of Brent Fulgham.
|
128
|
21 Dynamic loading added by Sergey Khorev
|
14
|
22
|
|
23 For downloading MzScheme and other info:
|
|
24 http://www.plt-scheme.org/software/mzscheme/
|
|
25
|
|
26 ==============================================================================
|
|
27 1. Commands *mzscheme-commands*
|
|
28
|
|
29 *:mzscheme* *:mz*
|
|
30 :[range]mz[scheme] {stmt}
|
|
31 Execute MzScheme statement {stmt}. {not in Vi}
|
|
32
|
|
33 :[range]mz[scheme] << {endmarker}
|
|
34 {script}
|
|
35 {endmarker}
|
|
36 Execute inlined MzScheme script {script}.
|
|
37 Note: This command doesn't work if the MzScheme
|
|
38 feature wasn't compiled in. To avoid errors, see
|
|
39 |script-here|.
|
|
40
|
|
41 *:mzfile* *:mzf*
|
|
42 :[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
|
|
43 All statements are executed in the namespace of the
|
856
|
44 buffer that was current during :mzfile start.
|
14
|
45 If you want to access other namespaces, use
|
|
46 'parameterize'.
|
|
47
|
|
48 All of these commands do essentially the same thing - they execute a piece of
|
|
49 MzScheme code, with the "current range" set to the given line
|
|
50 range.
|
|
51
|
|
52 In the case of :mzscheme, the code to execute is in the command-line.
|
|
53 In the case of :mzfile, the code to execute is the contents of the given file.
|
|
54
|
|
55 Each buffer has its own MzScheme namespace. Global namespace is bound to
|
|
56 the `global-namespace' value from the 'vimext' module.
|
|
57 MzScheme interface defines exception exn:vim, derived from exn.
|
|
58 It is raised for various Vim errors.
|
|
59
|
|
60 During compilation, the MzScheme interface will remember the current MzScheme
|
|
61 collection path. If you want to specify additional paths use the
|
|
62 'current-library-collection-paths' parameter. E.g., to cons the user-local
|
|
63 MzScheme collection path: >
|
|
64 :mz << EOF
|
|
65 (current-library-collection-paths
|
|
66 (cons
|
|
67 (build-path (find-system-path 'addon-dir) (version) "collects")
|
|
68 (current-library-collection-paths)))
|
|
69 EOF
|
|
70 <
|
|
71
|
|
72 All functionality is provided through module vimext.
|
|
73
|
|
74 The exn:vim is available without explicit import.
|
|
75
|
|
76 To avoid clashes with MzScheme, consider using prefix when requiring module,
|
|
77 e.g.: >
|
|
78 :mzscheme (require (prefix vim- vimext))
|
|
79 <
|
|
80 All the examples below assume this naming scheme. Note that you need to do
|
|
81 this again for every buffer.
|
|
82
|
|
83 The auto-instantiation can be achieved with autocommands, e.g. you can put
|
26
|
84 something like this in your .vimrc (EOFs should not have indentation): >
|
|
85 function s:MzRequire()
|
|
86 if has("mzscheme")
|
|
87 :mz << EOF
|
|
88 (require (prefix vim- vimext))
|
|
89 (let ((buf (vim-get-buff-by-name (vim-eval "expand(\"<afile>\")"))))
|
|
90 (when (and buf (not (eq? buf (vim-curr-buff))))
|
|
91 (parameterize ((current-namespace (vim-get-buff-namespace buf)))
|
|
92 (namespace-attach-module vim-global-namespace 'vimext)
|
|
93 (namespace-require '(prefix vim vimext)))))
|
|
94 EOF
|
|
95 endif
|
|
96 endfunction
|
|
97
|
|
98 function s:MzStartup()
|
|
99 if has("mzscheme")
|
|
100 au BufNew,BufNewFile,BufAdd,BufReadPre * :call s:MzRequire()
|
|
101 :mz << EOF
|
|
102 (current-library-collection-paths
|
|
103 (cons
|
|
104 (build-path (find-system-path 'addon-dir) (version) "collects")
|
|
105 (current-library-collection-paths)))
|
|
106 EOF
|
|
107 endif
|
|
108 endfunction
|
|
109
|
|
110 call s:MzStartup()
|
14
|
111 <
|
|
112
|
|
113 The global namespace just instantiated this module with the prefix "vimext:".
|
273
|
114 *mzscheme-sandbox*
|
|
115 When executed in the |sandbox|, access to some filesystem and Vim interface
|
|
116 procedures is restricted.
|
14
|
117
|
|
118 ==============================================================================
|
|
119 2. Examples *mzscheme-examples*
|
|
120 >
|
|
121 :mzscheme (display "Hello")
|
|
122 :mzscheme (vim-set-buff-line 10 "This is line #10")
|
|
123 <
|
|
124 Inline script usage: >
|
|
125 function! <SID>SetFirstLine()
|
|
126 :mz << EOF
|
|
127 (display "!!!")
|
|
128 (vim-set-buff-line 1 "This is line #1")
|
|
129 (vim-beep)
|
|
130 EOF
|
|
131 endfunction
|
|
132
|
|
133 nmap <F9> :call <SID>SetFirstLine() <CR>
|
|
134 <
|
|
135 File execution: >
|
|
136 :mzfile supascript.scm
|
|
137 <
|
|
138 Accessing the current buffer namespace from an MzScheme program running in
|
|
139 another buffer within |:mzfile|-executed script : >
|
|
140 ; Move to the window below
|
|
141 (vim-command "wincmd j")
|
|
142 ; execute in the context of buffer, to which window belongs
|
|
143 ; assume that buffer has 'textstring' defined
|
|
144 (parameterize ((current-namespace
|
|
145 (vim-get-buff-namespace (vim-curr-buff))))
|
|
146 (eval '(vim-set-buff-line 1 textstring)))
|
|
147 <
|
|
148
|
|
149 ==============================================================================
|
|
150 3. Threads *mzscheme-threads*
|
|
151
|
|
152 The MzScheme interface supports threads. They are independent from OS threads,
|
|
153 thus scheduling is required. The option 'mzquantum' determines how often
|
|
154 Vim should poll for available MzScheme threads.
|
|
155 NOTE
|
|
156 Thread scheduling in the console version of Vim is less reliable than in the
|
|
157 GUI version.
|
|
158
|
|
159 ==============================================================================
|
|
160 5. VIM Functions *mzscheme-vim*
|
|
161
|
|
162 *mzscheme-vimext*
|
|
163 The 'vimext' module provides access to procedures defined in the MzScheme
|
|
164 interface.
|
|
165
|
|
166 Common
|
|
167 ------
|
|
168 (command {command-string}) Perform the vim ":Ex" style command.
|
714
|
169 (eval {expr-string}) Evaluate the vim expression to a string.
|
|
170 A |List| is turned into a string by
|
|
171 joining the items and inserting line
|
|
172 breaks.
|
14
|
173 NOTE clashes with MzScheme eval
|
|
174 (range-start) Start/End of the range passed with
|
|
175 (range-end) the Scheme command.
|
|
176 (beep) beep
|
|
177 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
|
|
178 local or global, see set-option).
|
|
179 (set-option {string} [buffer-or-window])
|
|
180 Set a Vim option. String must have option
|
|
181 setting form (like optname=optval, or
|
|
182 optname+=optval, etc.) When called with
|
|
183 {buffer} or {window} the local option will
|
|
184 be set. The symbol 'global can be passed
|
|
185 as {buffer-or-window}. Then |:setglobal|
|
|
186 will be used.
|
|
187 global-namespace The MzScheme main namespace.
|
|
188
|
|
189 Buffers *mzscheme-buffer*
|
|
190 -------
|
|
191 (buff? {object}) Is object a buffer?
|
|
192 (buff-valid? {object}) Is object a valid buffer? (i.e.
|
|
193 corresponds to the real Vim buffer)
|
|
194 (get-buff-line {linenr} [buffer])
|
|
195 Get line from a buffer.
|
|
196 (set-buff-line {linenr} {string} [buffer])
|
|
197 Set a line in a buffer. If {string} is #f,
|
|
198 the line gets deleted. The [buffer]
|
856
|
199 argument is optional. If omitted, the
|
|
200 current buffer will be used.
|
14
|
201 (get-buff-line-list {start} {end} [buffer])
|
|
202 Get a list of lines in a buffer. {Start}
|
|
203 and {end} are 1-based. {Start} is
|
|
204 inclusive, {end} - exclusive.
|
|
205 (set-buff-line-list {start} {end} {string-list} [buffer])
|
|
206 Set a list of lines in a buffer. If
|
|
207 string-list is #f or null, the lines get
|
|
208 deleted. If a list is shorter than
|
|
209 {end}-{start} the remaining lines will
|
|
210 be deleted.
|
|
211 (get-buff-name [buffer]) Get a buffer's text name.
|
|
212 (get-buff-num [buffer]) Get a buffer's number.
|
|
213 (get-buff-size [buffer]) Get buffer line count.
|
|
214 (insert-buff-line-list {linenr} {string/string-list} [buffer])
|
|
215 Insert a list of lines into a buffer after
|
|
216 {linenr}. If {linenr} is 0, lines will be
|
|
217 inserted at start.
|
|
218 (curr-buff) Get the current buffer. Use procedures
|
|
219 from `vimcmd' module to change it.
|
|
220 (buff-count) Get count of total buffers in the editor.
|
|
221 (get-next-buff [buffer]) Get next buffer.
|
|
222 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
|
|
223 are no more buffers.
|
|
224 (open-buff {filename}) Open a new buffer (for file "name")
|
|
225 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
|
|
226 if there is no such buffer.
|
|
227 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
|
|
228 there is no buffer with this number).
|
|
229 (get-buff-namespace [buffer]) Get buffer namespace.
|
|
230
|
|
231 Windows *mzscheme-window*
|
|
232 ------
|
|
233 (win? {object}) Is object a window?
|
|
234 (win-valid? {object}) Is object a valid window (i.e. corresponds
|
|
235 to the real Vim window)?
|
|
236 (curr-win) Get the current window.
|
|
237 (win-count) Get count of windows.
|
|
238 (get-win-num [window]) Get window number.
|
|
239 (get-win-by-num {windownum}) Get window by its number.
|
|
240 (get-win-buffer [window]) Get the buffer for a given window.
|
|
241 (get-win-height [window])
|
|
242 (set-win-height {height} [window]) Get/Set height of window.
|
|
243 (get-win-width [window])
|
|
244 (set-win-width {width} [window])Get/Set width of window.
|
|
245 (get-win-list [buffer]) Get list of windows for a buffer.
|
|
246 (get-cursor [window]) Get cursor position in a window as
|
|
247 a pair (linenr . column).
|
|
248 (set-cursor (line . col) [window]) Set cursor position.
|
|
249
|
625
|
250 ==============================================================================
|
|
251 5. Dynamic loading *mzscheme-dynamic*
|
|
252
|
|
253 On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
|
|
254 output then includes |+mzscheme/dyn|.
|
|
255
|
|
256 This means that Vim will search for the MzScheme DLL files only when needed.
|
|
257 When you don't use the MzScheme interface you don't need them, thus you can
|
|
258 use Vim without these DLL files.
|
|
259
|
|
260 To use the MzScheme interface the MzScheme DLLs must be in your search path.
|
|
261 In a console window type "path" to see what directories are used.
|
|
262
|
|
263 The names of the DLLs must match the MzScheme version Vim was compiled with.
|
|
264 For MzScheme version 209 they will be "libmzsch209_000.dll" and
|
856
|
265 "libmzgc209_000.dll". To know for sure edit "gvim.exe" and search for
|
625
|
266 "libmzsch\d\d\d_\d\d\d\.dll\c".
|
|
267
|
14
|
268 ======================================================================
|
|
269 vim:tw=78:ts=8:sts=4:ft=help:norl:
|