blob: f8fc6461d6e4b0c820b2aeb6113f16dc9ac67692 [file] [log] [blame]
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001*if_mzsch.txt* For Vim version 7.0f. Last change: 2006 Mar 06
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|
124. The Vim access procedures |mzscheme-vim|
Bram Moolenaar4770d092006-01-12 23:22:24 +0000135. Dynamic loading |mzscheme-dynamic|
Bram Moolenaar325b7a22004-07-05 15:58:32 +000014
15{Vi does not have any of these commands}
16
17The MzScheme interface is available only if Vim was compiled with the
18|+mzscheme| feature.
19
20Based on the work of Brent Fulgham.
Bram Moolenaar281bdce2005-01-25 21:53:18 +000021Dynamic loading added by Sergey Khorev
Bram Moolenaar325b7a22004-07-05 15:58:32 +000022
23For downloading MzScheme and other info:
24 http://www.plt-scheme.org/software/mzscheme/
25
26==============================================================================
271. 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
44 buffer that was current during :mzfile start.
45 If you want to access other namespaces, use
46 'parameterize'.
47
48All of these commands do essentially the same thing - they execute a piece of
49MzScheme code, with the "current range" set to the given line
50range.
51
52In the case of :mzscheme, the code to execute is in the command-line.
53In the case of :mzfile, the code to execute is the contents of the given file.
54
55Each buffer has its own MzScheme namespace. Global namespace is bound to
56the `global-namespace' value from the 'vimext' module.
57MzScheme interface defines exception exn:vim, derived from exn.
58It is raised for various Vim errors.
59
60During compilation, the MzScheme interface will remember the current MzScheme
61collection path. If you want to specify additional paths use the
62'current-library-collection-paths' parameter. E.g., to cons the user-local
63MzScheme 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
72All functionality is provided through module vimext.
73
74The exn:vim is available without explicit import.
75
76To avoid clashes with MzScheme, consider using prefix when requiring module,
77e.g.: >
78 :mzscheme (require (prefix vim- vimext))
79<
80All the examples below assume this naming scheme. Note that you need to do
81this again for every buffer.
82
83The auto-instantiation can be achieved with autocommands, e.g. you can put
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +000084something 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()
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000111<
112
113The global namespace just instantiated this module with the prefix "vimext:".
Bram Moolenaar051b7822005-05-19 21:00:46 +0000114 *mzscheme-sandbox*
115When executed in the |sandbox|, access to some filesystem and Vim interface
116procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000117
118==============================================================================
1192. Examples *mzscheme-examples*
120>
121 :mzscheme (display "Hello")
122 :mzscheme (vim-set-buff-line 10 "This is line #10")
123<
124Inline 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<
135File execution: >
136 :mzfile supascript.scm
137<
138Accessing the current buffer namespace from an MzScheme program running in
139another 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==============================================================================
1503. Threads *mzscheme-threads*
151
152The MzScheme interface supports threads. They are independent from OS threads,
153thus scheduling is required. The option 'mzquantum' determines how often
154Vim should poll for available MzScheme threads.
155NOTE
156Thread scheduling in the console version of Vim is less reliable than in the
157GUI version.
158
159==============================================================================
1605. VIM Functions *mzscheme-vim*
161
162 *mzscheme-vimext*
163The 'vimext' module provides access to procedures defined in the MzScheme
164interface.
165
166Common
167------
168 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000169 (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.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000173 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
189Buffers *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]
199 argument is optional. If omitted, the
200 current buffer will be used.
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
231Windows *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
Bram Moolenaar4770d092006-01-12 23:22:24 +0000250==============================================================================
2515. Dynamic loading *mzscheme-dynamic*
252
253On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
254output then includes |+mzscheme/dyn|.
255
256This means that Vim will search for the MzScheme DLL files only when needed.
257When you don't use the MzScheme interface you don't need them, thus you can
258use Vim without these DLL files.
259
260To use the MzScheme interface the MzScheme DLLs must be in your search path.
261In a console window type "path" to see what directories are used.
262
263The names of the DLLs must match the MzScheme version Vim was compiled with.
264For MzScheme version 209 they will be "libmzsch209_000.dll" and
265"libmzgc209_000.dll". To know for sure edit "gvim.exe" and search for
266"libmzsch\d\d\d_\d\d\d\.dll\c".
267
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000268======================================================================
269 vim:tw=78:ts=8:sts=4:ft=help:norl: