blob: b42570a75a06618ec4e9ceb91a0657c2b32b9026 [file] [log] [blame]
Bram Moolenaar3b1db362013-08-10 15:00:24 +02001*if_mzsch.txt* For Vim version 7.4. Last change: 2012 Dec 17
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002
3
4 VIM REFERENCE MANUAL by Sergey Khorev
5
6
7The MzScheme Interface to Vim *mzscheme* *MzScheme*
8
91. Commands |mzscheme-commands|
102. Examples |mzscheme-examples|
113. Threads |mzscheme-threads|
Bram Moolenaar7e506b62010-01-19 15:55:06 +0100124. Vim access from MzScheme |mzscheme-vim|
135. mzeval() Vim function |mzscheme-mzeval|
Bram Moolenaar75676462013-01-30 14:55:42 +0100146. Using Function references |mzscheme-funcref|
157. Dynamic loading |mzscheme-dynamic|
Bram Moolenaar325b7a22004-07-05 15:58:32 +000016
17{Vi does not have any of these commands}
18
19The MzScheme interface is available only if Vim was compiled with the
20|+mzscheme| feature.
21
22Based on the work of Brent Fulgham.
Bram Moolenaar281bdce2005-01-25 21:53:18 +000023Dynamic loading added by Sergey Khorev
Bram Moolenaar325b7a22004-07-05 15:58:32 +000024
Bram Moolenaar75676462013-01-30 14:55:42 +010025MzScheme and PLT Scheme names have been rebranded as Racket. For more
26information please check http://racket-lang.org
Bram Moolenaar325b7a22004-07-05 15:58:32 +000027
Bram Moolenaar75676462013-01-30 14:55:42 +010028Futures and places of Racket version 5.x up to and including 5.3.1 do not
29work correctly with processes created by Vim.
30The simplest solution is to build Racket on your own with these features
31disabled: >
32 ./configure --disable-futures --disable-places --prefix=your-install-prefix
33
34To speed up the process, you might also want to use --disable-gracket and
35--disable-docs
Bram Moolenaar9964e462007-05-05 17:54:07 +000036
Bram Moolenaar325b7a22004-07-05 15:58:32 +000037==============================================================================
381. Commands *mzscheme-commands*
39
40 *:mzscheme* *:mz*
41:[range]mz[scheme] {stmt}
42 Execute MzScheme statement {stmt}. {not in Vi}
43
44:[range]mz[scheme] << {endmarker}
45{script}
46{endmarker}
47 Execute inlined MzScheme script {script}.
48 Note: This command doesn't work if the MzScheme
49 feature wasn't compiled in. To avoid errors, see
50 |script-here|.
51
52 *:mzfile* *:mzf*
53:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
Bram Moolenaar325b7a22004-07-05 15:58:32 +000054
55All of these commands do essentially the same thing - they execute a piece of
56MzScheme code, with the "current range" set to the given line
57range.
58
59In the case of :mzscheme, the code to execute is in the command-line.
60In the case of :mzfile, the code to execute is the contents of the given file.
61
Bram Moolenaar325b7a22004-07-05 15:58:32 +000062MzScheme interface defines exception exn:vim, derived from exn.
63It is raised for various Vim errors.
64
65During compilation, the MzScheme interface will remember the current MzScheme
66collection path. If you want to specify additional paths use the
67'current-library-collection-paths' parameter. E.g., to cons the user-local
68MzScheme collection path: >
69 :mz << EOF
70 (current-library-collection-paths
71 (cons
72 (build-path (find-system-path 'addon-dir) (version) "collects")
73 (current-library-collection-paths)))
74 EOF
75<
76
77All functionality is provided through module vimext.
78
79The exn:vim is available without explicit import.
80
81To avoid clashes with MzScheme, consider using prefix when requiring module,
82e.g.: >
83 :mzscheme (require (prefix vim- vimext))
84<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000085All the examples below assume this naming scheme.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000086
Bram Moolenaar051b7822005-05-19 21:00:46 +000087 *mzscheme-sandbox*
88When executed in the |sandbox|, access to some filesystem and Vim interface
89procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000090
91==============================================================================
922. Examples *mzscheme-examples*
93>
94 :mzscheme (display "Hello")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000095 :mz (display (string-append "Using MzScheme version " (version)))
96 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
97 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
Bram Moolenaar325b7a22004-07-05 15:58:32 +000098 :mzscheme (vim-set-buff-line 10 "This is line #10")
99<
100Inline script usage: >
101 function! <SID>SetFirstLine()
102 :mz << EOF
103 (display "!!!")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000104 (require (prefix vim- vimext))
105 ; for newer versions (require (prefix-in vim- 'vimext))
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000106 (vim-set-buff-line 1 "This is line #1")
107 (vim-beep)
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000108 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000109 endfunction
110
111 nmap <F9> :call <SID>SetFirstLine() <CR>
112<
113File execution: >
114 :mzfile supascript.scm
115<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000116Vim exception handling: >
117 :mz << EOF
118 (require (prefix vim- vimext))
119 ; for newer versions (require (prefix-in vim- 'vimext))
120 (with-handlers
121 ([exn:vim? (lambda (e) (display (exn-message e)))])
122 (vim-eval "nonsense-string"))
123 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000124<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000125Auto-instantiation of vimext module (can be placed in your |vimrc|): >
126 function! MzRequire()
127 :redir => l:mzversion
128 :mz (version)
129 :redir END
130 if strpart(l:mzversion, 1, 1) < "4"
131 " MzScheme versions < 4.x:
132 :mz (require (prefix vim- vimext))
133 else
134 " newer versions:
135 :mz (require (prefix-in vim- 'vimext))
136 endif
137 endfunction
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000138
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000139 if has("mzscheme")
140 silent call MzRequire()
141 endif
142<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000143==============================================================================
1443. Threads *mzscheme-threads*
145
146The MzScheme interface supports threads. They are independent from OS threads,
147thus scheduling is required. The option 'mzquantum' determines how often
148Vim should poll for available MzScheme threads.
149NOTE
150Thread scheduling in the console version of Vim is less reliable than in the
151GUI version.
152
153==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01001544. Vim access from MzScheme *mzscheme-vim*
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000155
156 *mzscheme-vimext*
157The 'vimext' module provides access to procedures defined in the MzScheme
158interface.
159
160Common
161------
162 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000163 (eval {expr-string}) Evaluate the vim expression into
164 respective MzScheme object: |Lists| are
165 represented as Scheme lists,
Bram Moolenaar75676462013-01-30 14:55:42 +0100166 |Dictionaries| as hash tables,
167 |Funcref|s as functions (see also
168 |mzscheme-funcref|)
169 NOTE the name clashes with MzScheme eval,
170 use module qualifiers to overcome this.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000171 (range-start) Start/End of the range passed with
172 (range-end) the Scheme command.
173 (beep) beep
174 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
175 local or global, see set-option).
176 (set-option {string} [buffer-or-window])
177 Set a Vim option. String must have option
178 setting form (like optname=optval, or
179 optname+=optval, etc.) When called with
180 {buffer} or {window} the local option will
181 be set. The symbol 'global can be passed
182 as {buffer-or-window}. Then |:setglobal|
183 will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000184
185Buffers *mzscheme-buffer*
186-------
187 (buff? {object}) Is object a buffer?
188 (buff-valid? {object}) Is object a valid buffer? (i.e.
189 corresponds to the real Vim buffer)
190 (get-buff-line {linenr} [buffer])
191 Get line from a buffer.
192 (set-buff-line {linenr} {string} [buffer])
193 Set a line in a buffer. If {string} is #f,
194 the line gets deleted. The [buffer]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000195 argument is optional. If omitted, the
196 current buffer will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000197 (get-buff-line-list {start} {end} [buffer])
198 Get a list of lines in a buffer. {Start}
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100199 and {end} are 1-based and inclusive.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000200 (set-buff-line-list {start} {end} {string-list} [buffer])
201 Set a list of lines in a buffer. If
202 string-list is #f or null, the lines get
203 deleted. If a list is shorter than
204 {end}-{start} the remaining lines will
205 be deleted.
206 (get-buff-name [buffer]) Get a buffer's text name.
207 (get-buff-num [buffer]) Get a buffer's number.
208 (get-buff-size [buffer]) Get buffer line count.
209 (insert-buff-line-list {linenr} {string/string-list} [buffer])
210 Insert a list of lines into a buffer after
211 {linenr}. If {linenr} is 0, lines will be
212 inserted at start.
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100213 (curr-buff) Get the current buffer. Use other MzScheme
214 interface procedures to change it.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000215 (buff-count) Get count of total buffers in the editor.
216 (get-next-buff [buffer]) Get next buffer.
217 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
218 are no more buffers.
219 (open-buff {filename}) Open a new buffer (for file "name")
220 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
221 if there is no such buffer.
222 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
223 there is no buffer with this number).
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000224
225Windows *mzscheme-window*
226------
227 (win? {object}) Is object a window?
228 (win-valid? {object}) Is object a valid window (i.e. corresponds
229 to the real Vim window)?
230 (curr-win) Get the current window.
231 (win-count) Get count of windows.
232 (get-win-num [window]) Get window number.
233 (get-win-by-num {windownum}) Get window by its number.
234 (get-win-buffer [window]) Get the buffer for a given window.
235 (get-win-height [window])
236 (set-win-height {height} [window]) Get/Set height of window.
237 (get-win-width [window])
238 (set-win-width {width} [window])Get/Set width of window.
239 (get-win-list [buffer]) Get list of windows for a buffer.
240 (get-cursor [window]) Get cursor position in a window as
241 a pair (linenr . column).
242 (set-cursor (line . col) [window]) Set cursor position.
243
Bram Moolenaar4770d092006-01-12 23:22:24 +0000244==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01002455. mzeval() Vim function *mzscheme-mzeval*
246
Bram Moolenaar945e2db2010-06-05 17:43:32 +0200247To facilitate bi-directional interface, you can use |mzeval()| function to
Bram Moolenaar7e506b62010-01-19 15:55:06 +0100248evaluate MzScheme expressions and pass their values to VimL.
249
250==============================================================================
Bram Moolenaar75676462013-01-30 14:55:42 +01002516. Using Function references *mzscheme-funcref*
252
253MzScheme interface allows use of |Funcref|s so you can call Vim functions
254directly from Scheme. For instance: >
255 function! MyAdd2(arg)
256 return a:arg + 2
257 endfunction
258 mz (define f2 (vim-eval "function(\"MyAdd2\")"))
259 mz (f2 7)
260< or : >
261 :mz (define indent (vim-eval "function('indent')"))
262 " return Vim indent for line 12
263 :mz (indent 12)
264<
265
266==============================================================================
2677. Dynamic loading *mzscheme-dynamic* *E815*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000268
269On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
270output then includes |+mzscheme/dyn|.
271
272This means that Vim will search for the MzScheme DLL files only when needed.
273When you don't use the MzScheme interface you don't need them, thus you can
274use Vim without these DLL files.
275
276To use the MzScheme interface the MzScheme DLLs must be in your search path.
277In a console window type "path" to see what directories are used.
278
279The names of the DLLs must match the MzScheme version Vim was compiled with.
280For MzScheme version 209 they will be "libmzsch209_000.dll" and
Bram Moolenaar9964e462007-05-05 17:54:07 +0000281"libmzgc209_000.dll". To know for sure look at the output of the ":version"
282command, look for -DDYNAMIC_MZSCH_DLL="something" and
283-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000284
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000285======================================================================
286 vim:tw=78:ts=8:sts=4:ft=help:norl: