blob: 484d09aa8a17acd8301f9374fd4a1f9906659c91 [file] [log] [blame]
Bram Moolenaar7e506b62010-01-19 15:55:06 +01001*if_mzsch.txt* For Vim version 7.2. Last change: 2010 Jan 19
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|
146. Dynamic loading |mzscheme-dynamic|
Bram Moolenaar325b7a22004-07-05 15:58:32 +000015
16{Vi does not have any of these commands}
17
18The MzScheme interface is available only if Vim was compiled with the
19|+mzscheme| feature.
20
21Based on the work of Brent Fulgham.
Bram Moolenaar281bdce2005-01-25 21:53:18 +000022Dynamic loading added by Sergey Khorev
Bram Moolenaar325b7a22004-07-05 15:58:32 +000023
24For downloading MzScheme and other info:
25 http://www.plt-scheme.org/software/mzscheme/
26
Bram Moolenaar9964e462007-05-05 17:54:07 +000027Note: On FreeBSD you should use the "drscheme" port.
28
Bram Moolenaar325b7a22004-07-05 15:58:32 +000029==============================================================================
301. Commands *mzscheme-commands*
31
32 *:mzscheme* *:mz*
33:[range]mz[scheme] {stmt}
34 Execute MzScheme statement {stmt}. {not in Vi}
35
36:[range]mz[scheme] << {endmarker}
37{script}
38{endmarker}
39 Execute inlined MzScheme script {script}.
40 Note: This command doesn't work if the MzScheme
41 feature wasn't compiled in. To avoid errors, see
42 |script-here|.
43
44 *:mzfile* *:mzf*
45:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
Bram Moolenaar325b7a22004-07-05 15:58:32 +000046
47All of these commands do essentially the same thing - they execute a piece of
48MzScheme code, with the "current range" set to the given line
49range.
50
51In the case of :mzscheme, the code to execute is in the command-line.
52In the case of :mzfile, the code to execute is the contents of the given file.
53
Bram Moolenaar325b7a22004-07-05 15:58:32 +000054MzScheme interface defines exception exn:vim, derived from exn.
55It is raised for various Vim errors.
56
57During compilation, the MzScheme interface will remember the current MzScheme
58collection path. If you want to specify additional paths use the
59'current-library-collection-paths' parameter. E.g., to cons the user-local
60MzScheme collection path: >
61 :mz << EOF
62 (current-library-collection-paths
63 (cons
64 (build-path (find-system-path 'addon-dir) (version) "collects")
65 (current-library-collection-paths)))
66 EOF
67<
68
69All functionality is provided through module vimext.
70
71The exn:vim is available without explicit import.
72
73To avoid clashes with MzScheme, consider using prefix when requiring module,
74e.g.: >
75 :mzscheme (require (prefix vim- vimext))
76<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000077All the examples below assume this naming scheme.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000078
Bram Moolenaar051b7822005-05-19 21:00:46 +000079 *mzscheme-sandbox*
80When executed in the |sandbox|, access to some filesystem and Vim interface
81procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000082
83==============================================================================
842. Examples *mzscheme-examples*
85>
86 :mzscheme (display "Hello")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000087 :mz (display (string-append "Using MzScheme version " (version)))
88 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
89 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
Bram Moolenaar325b7a22004-07-05 15:58:32 +000090 :mzscheme (vim-set-buff-line 10 "This is line #10")
91<
92Inline script usage: >
93 function! <SID>SetFirstLine()
94 :mz << EOF
95 (display "!!!")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000096 (require (prefix vim- vimext))
97 ; for newer versions (require (prefix-in vim- 'vimext))
Bram Moolenaar325b7a22004-07-05 15:58:32 +000098 (vim-set-buff-line 1 "This is line #1")
99 (vim-beep)
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000100 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000101 endfunction
102
103 nmap <F9> :call <SID>SetFirstLine() <CR>
104<
105File execution: >
106 :mzfile supascript.scm
107<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000108Vim exception handling: >
109 :mz << EOF
110 (require (prefix vim- vimext))
111 ; for newer versions (require (prefix-in vim- 'vimext))
112 (with-handlers
113 ([exn:vim? (lambda (e) (display (exn-message e)))])
114 (vim-eval "nonsense-string"))
115 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000116<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000117Auto-instantiation of vimext module (can be placed in your |vimrc|): >
118 function! MzRequire()
119 :redir => l:mzversion
120 :mz (version)
121 :redir END
122 if strpart(l:mzversion, 1, 1) < "4"
123 " MzScheme versions < 4.x:
124 :mz (require (prefix vim- vimext))
125 else
126 " newer versions:
127 :mz (require (prefix-in vim- 'vimext))
128 endif
129 endfunction
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000130
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000131 if has("mzscheme")
132 silent call MzRequire()
133 endif
134<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000135==============================================================================
1363. Threads *mzscheme-threads*
137
138The MzScheme interface supports threads. They are independent from OS threads,
139thus scheduling is required. The option 'mzquantum' determines how often
140Vim should poll for available MzScheme threads.
141NOTE
142Thread scheduling in the console version of Vim is less reliable than in the
143GUI version.
144
145==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01001464. Vim access from MzScheme *mzscheme-vim*
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000147
148 *mzscheme-vimext*
149The 'vimext' module provides access to procedures defined in the MzScheme
150interface.
151
152Common
153------
154 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000155 (eval {expr-string}) Evaluate the vim expression into
156 respective MzScheme object: |Lists| are
157 represented as Scheme lists,
158 |Dictionaries| as hash tables.
159 NOTE the name clashes with MzScheme eval
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000160 (range-start) Start/End of the range passed with
161 (range-end) the Scheme command.
162 (beep) beep
163 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
164 local or global, see set-option).
165 (set-option {string} [buffer-or-window])
166 Set a Vim option. String must have option
167 setting form (like optname=optval, or
168 optname+=optval, etc.) When called with
169 {buffer} or {window} the local option will
170 be set. The symbol 'global can be passed
171 as {buffer-or-window}. Then |:setglobal|
172 will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000173
174Buffers *mzscheme-buffer*
175-------
176 (buff? {object}) Is object a buffer?
177 (buff-valid? {object}) Is object a valid buffer? (i.e.
178 corresponds to the real Vim buffer)
179 (get-buff-line {linenr} [buffer])
180 Get line from a buffer.
181 (set-buff-line {linenr} {string} [buffer])
182 Set a line in a buffer. If {string} is #f,
183 the line gets deleted. The [buffer]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000184 argument is optional. If omitted, the
185 current buffer will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000186 (get-buff-line-list {start} {end} [buffer])
187 Get a list of lines in a buffer. {Start}
188 and {end} are 1-based. {Start} is
189 inclusive, {end} - exclusive.
190 (set-buff-line-list {start} {end} {string-list} [buffer])
191 Set a list of lines in a buffer. If
192 string-list is #f or null, the lines get
193 deleted. If a list is shorter than
194 {end}-{start} the remaining lines will
195 be deleted.
196 (get-buff-name [buffer]) Get a buffer's text name.
197 (get-buff-num [buffer]) Get a buffer's number.
198 (get-buff-size [buffer]) Get buffer line count.
199 (insert-buff-line-list {linenr} {string/string-list} [buffer])
200 Insert a list of lines into a buffer after
201 {linenr}. If {linenr} is 0, lines will be
202 inserted at start.
203 (curr-buff) Get the current buffer. Use procedures
Bram Moolenaarc236c162008-07-13 17:41:49 +0000204 from "vimcmd" module to change it.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000205 (buff-count) Get count of total buffers in the editor.
206 (get-next-buff [buffer]) Get next buffer.
207 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
208 are no more buffers.
209 (open-buff {filename}) Open a new buffer (for file "name")
210 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
211 if there is no such buffer.
212 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
213 there is no buffer with this number).
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000214
215Windows *mzscheme-window*
216------
217 (win? {object}) Is object a window?
218 (win-valid? {object}) Is object a valid window (i.e. corresponds
219 to the real Vim window)?
220 (curr-win) Get the current window.
221 (win-count) Get count of windows.
222 (get-win-num [window]) Get window number.
223 (get-win-by-num {windownum}) Get window by its number.
224 (get-win-buffer [window]) Get the buffer for a given window.
225 (get-win-height [window])
226 (set-win-height {height} [window]) Get/Set height of window.
227 (get-win-width [window])
228 (set-win-width {width} [window])Get/Set width of window.
229 (get-win-list [buffer]) Get list of windows for a buffer.
230 (get-cursor [window]) Get cursor position in a window as
231 a pair (linenr . column).
232 (set-cursor (line . col) [window]) Set cursor position.
233
Bram Moolenaar4770d092006-01-12 23:22:24 +0000234==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01002355. mzeval() Vim function *mzscheme-mzeval*
236
237To facilitate bi-directional interface, you can use |mzeval| function to
238evaluate MzScheme expressions and pass their values to VimL.
239
240==============================================================================
2416. Dynamic loading *mzscheme-dynamic* *E815*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000242
243On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
244output then includes |+mzscheme/dyn|.
245
246This means that Vim will search for the MzScheme DLL files only when needed.
247When you don't use the MzScheme interface you don't need them, thus you can
248use Vim without these DLL files.
249
250To use the MzScheme interface the MzScheme DLLs must be in your search path.
251In a console window type "path" to see what directories are used.
252
253The names of the DLLs must match the MzScheme version Vim was compiled with.
254For MzScheme version 209 they will be "libmzsch209_000.dll" and
Bram Moolenaar9964e462007-05-05 17:54:07 +0000255"libmzgc209_000.dll". To know for sure look at the output of the ":version"
256command, look for -DDYNAMIC_MZSCH_DLL="something" and
257-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000258
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000259======================================================================
260 vim:tw=78:ts=8:sts=4:ft=help:norl: