blob: c6888a8b61559a174d57ba46daf9851eb680f611 [file] [log] [blame]
Bram Moolenaar54775062019-07-31 21:07:14 +02001*if_mzsch.txt* For Vim version 8.1. Last change: 2019 Jul 21
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 Moolenaar4e640bd2016-01-16 16:20:38 +0100168. MzScheme setup |mzscheme-setup|
Bram Moolenaar325b7a22004-07-05 15:58:32 +000017
Bram Moolenaar25c9c682019-05-05 18:13:34 +020018{only available when Vim was compiled with the |+mzscheme| feature}
Bram Moolenaar325b7a22004-07-05 15:58:32 +000019
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
Bram Moolenaar75676462013-01-30 14:55:42 +010023MzScheme and PLT Scheme names have been rebranded as Racket. For more
24information please check http://racket-lang.org
Bram Moolenaar325b7a22004-07-05 15:58:32 +000025
Bram Moolenaar75676462013-01-30 14:55:42 +010026Futures and places of Racket version 5.x up to and including 5.3.1 do not
27work correctly with processes created by Vim.
28The simplest solution is to build Racket on your own with these features
29disabled: >
30 ./configure --disable-futures --disable-places --prefix=your-install-prefix
31
32To speed up the process, you might also want to use --disable-gracket and
33--disable-docs
Bram Moolenaar9964e462007-05-05 17:54:07 +000034
Bram Moolenaar325b7a22004-07-05 15:58:32 +000035==============================================================================
361. Commands *mzscheme-commands*
37
38 *:mzscheme* *:mz*
39:[range]mz[scheme] {stmt}
Bram Moolenaar25c9c682019-05-05 18:13:34 +020040 Execute MzScheme statement {stmt}.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000041
Bram Moolenaar54775062019-07-31 21:07:14 +020042:[range]mz[scheme] << [endmarker]
Bram Moolenaar325b7a22004-07-05 15:58:32 +000043{script}
44{endmarker}
45 Execute inlined MzScheme script {script}.
46 Note: This command doesn't work if the MzScheme
47 feature wasn't compiled in. To avoid errors, see
48 |script-here|.
49
Bram Moolenaar54775062019-07-31 21:07:14 +020050 The {endmarker} below the {script} must NOT be
51 preceded by any white space.
52
53 If [endmarker] is omitted from after the "<<", a dot
54 '.' must be used after {script}, like for the
55 |:append| and |:insert| commands.
56
Bram Moolenaar325b7a22004-07-05 15:58:32 +000057 *:mzfile* *:mzf*
Bram Moolenaar25c9c682019-05-05 18:13:34 +020058:[range]mzf[ile] {file} Execute the MzScheme script in {file}.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000059
60All of these commands do essentially the same thing - they execute a piece of
61MzScheme code, with the "current range" set to the given line
62range.
63
64In the case of :mzscheme, the code to execute is in the command-line.
65In the case of :mzfile, the code to execute is the contents of the given file.
66
Bram Moolenaar325b7a22004-07-05 15:58:32 +000067MzScheme interface defines exception exn:vim, derived from exn.
68It is raised for various Vim errors.
69
70During compilation, the MzScheme interface will remember the current MzScheme
71collection path. If you want to specify additional paths use the
72'current-library-collection-paths' parameter. E.g., to cons the user-local
73MzScheme collection path: >
74 :mz << EOF
75 (current-library-collection-paths
76 (cons
77 (build-path (find-system-path 'addon-dir) (version) "collects")
78 (current-library-collection-paths)))
79 EOF
80<
81
82All functionality is provided through module vimext.
83
84The exn:vim is available without explicit import.
85
86To avoid clashes with MzScheme, consider using prefix when requiring module,
87e.g.: >
88 :mzscheme (require (prefix vim- vimext))
89<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000090All the examples below assume this naming scheme.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000091
Bram Moolenaar051b7822005-05-19 21:00:46 +000092 *mzscheme-sandbox*
93When executed in the |sandbox|, access to some filesystem and Vim interface
94procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000095
96==============================================================================
972. Examples *mzscheme-examples*
98>
99 :mzscheme (display "Hello")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000100 :mz (display (string-append "Using MzScheme version " (version)))
101 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
102 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000103 :mzscheme (vim-set-buff-line 10 "This is line #10")
Bram Moolenaarabd468e2016-09-08 22:22:43 +0200104
105To see what version of MzScheme you have: >
106 :mzscheme (display (version))
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000107<
108Inline script usage: >
109 function! <SID>SetFirstLine()
110 :mz << EOF
111 (display "!!!")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000112 (require (prefix vim- vimext))
113 ; for newer versions (require (prefix-in vim- 'vimext))
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000114 (vim-set-buff-line 1 "This is line #1")
115 (vim-beep)
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000116 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000117 endfunction
118
119 nmap <F9> :call <SID>SetFirstLine() <CR>
120<
121File execution: >
122 :mzfile supascript.scm
123<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000124Vim exception handling: >
125 :mz << EOF
126 (require (prefix vim- vimext))
127 ; for newer versions (require (prefix-in vim- 'vimext))
128 (with-handlers
129 ([exn:vim? (lambda (e) (display (exn-message e)))])
130 (vim-eval "nonsense-string"))
131 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000132<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000133Auto-instantiation of vimext module (can be placed in your |vimrc|): >
134 function! MzRequire()
135 :redir => l:mzversion
136 :mz (version)
137 :redir END
138 if strpart(l:mzversion, 1, 1) < "4"
139 " MzScheme versions < 4.x:
140 :mz (require (prefix vim- vimext))
141 else
142 " newer versions:
143 :mz (require (prefix-in vim- 'vimext))
144 endif
145 endfunction
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000146
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000147 if has("mzscheme")
148 silent call MzRequire()
149 endif
150<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000151==============================================================================
1523. Threads *mzscheme-threads*
153
154The MzScheme interface supports threads. They are independent from OS threads,
155thus scheduling is required. The option 'mzquantum' determines how often
156Vim should poll for available MzScheme threads.
157NOTE
158Thread scheduling in the console version of Vim is less reliable than in the
159GUI version.
160
161==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01001624. Vim access from MzScheme *mzscheme-vim*
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000163
164 *mzscheme-vimext*
165The 'vimext' module provides access to procedures defined in the MzScheme
166interface.
167
168Common
169------
170 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000171 (eval {expr-string}) Evaluate the vim expression into
172 respective MzScheme object: |Lists| are
173 represented as Scheme lists,
Bram Moolenaar75676462013-01-30 14:55:42 +0100174 |Dictionaries| as hash tables,
175 |Funcref|s as functions (see also
176 |mzscheme-funcref|)
177 NOTE the name clashes with MzScheme eval,
178 use module qualifiers to overcome this.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000179 (range-start) Start/End of the range passed with
180 (range-end) the Scheme command.
181 (beep) beep
182 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
183 local or global, see set-option).
184 (set-option {string} [buffer-or-window])
185 Set a Vim option. String must have option
186 setting form (like optname=optval, or
187 optname+=optval, etc.) When called with
188 {buffer} or {window} the local option will
189 be set. The symbol 'global can be passed
190 as {buffer-or-window}. Then |:setglobal|
191 will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000192
193Buffers *mzscheme-buffer*
194-------
195 (buff? {object}) Is object a buffer?
196 (buff-valid? {object}) Is object a valid buffer? (i.e.
197 corresponds to the real Vim buffer)
198 (get-buff-line {linenr} [buffer])
199 Get line from a buffer.
200 (set-buff-line {linenr} {string} [buffer])
201 Set a line in a buffer. If {string} is #f,
202 the line gets deleted. The [buffer]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000203 argument is optional. If omitted, the
204 current buffer will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000205 (get-buff-line-list {start} {end} [buffer])
206 Get a list of lines in a buffer. {Start}
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100207 and {end} are 1-based and inclusive.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000208 (set-buff-line-list {start} {end} {string-list} [buffer])
209 Set a list of lines in a buffer. If
210 string-list is #f or null, the lines get
211 deleted. If a list is shorter than
212 {end}-{start} the remaining lines will
213 be deleted.
214 (get-buff-name [buffer]) Get a buffer's text name.
215 (get-buff-num [buffer]) Get a buffer's number.
216 (get-buff-size [buffer]) Get buffer line count.
217 (insert-buff-line-list {linenr} {string/string-list} [buffer])
218 Insert a list of lines into a buffer after
219 {linenr}. If {linenr} is 0, lines will be
220 inserted at start.
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100221 (curr-buff) Get the current buffer. Use other MzScheme
222 interface procedures to change it.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000223 (buff-count) Get count of total buffers in the editor.
224 (get-next-buff [buffer]) Get next buffer.
225 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
226 are no more buffers.
227 (open-buff {filename}) Open a new buffer (for file "name")
228 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
229 if there is no such buffer.
230 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
231 there is no buffer with this number).
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000232
233Windows *mzscheme-window*
234------
235 (win? {object}) Is object a window?
236 (win-valid? {object}) Is object a valid window (i.e. corresponds
237 to the real Vim window)?
238 (curr-win) Get the current window.
239 (win-count) Get count of windows.
240 (get-win-num [window]) Get window number.
241 (get-win-by-num {windownum}) Get window by its number.
242 (get-win-buffer [window]) Get the buffer for a given window.
243 (get-win-height [window])
244 (set-win-height {height} [window]) Get/Set height of window.
245 (get-win-width [window])
246 (set-win-width {width} [window])Get/Set width of window.
247 (get-win-list [buffer]) Get list of windows for a buffer.
248 (get-cursor [window]) Get cursor position in a window as
249 a pair (linenr . column).
250 (set-cursor (line . col) [window]) Set cursor position.
251
Bram Moolenaar4770d092006-01-12 23:22:24 +0000252==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01002535. mzeval() Vim function *mzscheme-mzeval*
254
Bram Moolenaar945e2db2010-06-05 17:43:32 +0200255To facilitate bi-directional interface, you can use |mzeval()| function to
Bram Moolenaarb544f3c2017-02-23 19:03:28 +0100256evaluate MzScheme expressions and pass their values to Vim script.
Bram Moolenaar7e506b62010-01-19 15:55:06 +0100257
258==============================================================================
Bram Moolenaar75676462013-01-30 14:55:42 +01002596. Using Function references *mzscheme-funcref*
260
261MzScheme interface allows use of |Funcref|s so you can call Vim functions
262directly from Scheme. For instance: >
263 function! MyAdd2(arg)
264 return a:arg + 2
265 endfunction
266 mz (define f2 (vim-eval "function(\"MyAdd2\")"))
267 mz (f2 7)
268< or : >
269 :mz (define indent (vim-eval "function('indent')"))
270 " return Vim indent for line 12
271 :mz (indent 12)
272<
273
274==============================================================================
Bram Moolenaar705ada12016-01-24 17:56:50 +01002757. Dynamic loading *mzscheme-dynamic* *E815*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000276
277On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
278output then includes |+mzscheme/dyn|.
279
280This means that Vim will search for the MzScheme DLL files only when needed.
281When you don't use the MzScheme interface you don't need them, thus you can
282use Vim without these DLL files.
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100283NOTE: Newer version of MzScheme (Racket) require earlier (trampolined)
284initialisation via scheme_main_setup. So Vim always loads the MzScheme DLL at
Bram Moolenaar0ab35b22017-10-08 17:41:37 +0200285startup if possible. This may make Vim startup slower.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000286
287To use the MzScheme interface the MzScheme DLLs must be in your search path.
288In a console window type "path" to see what directories are used.
289
Bram Moolenaar0ab35b22017-10-08 17:41:37 +0200290On MS-Windows the options 'mzschemedll' and 'mzschemegcdll' are used for the
291name of the library to load. The initial value is specified at build time.
292
293The version of the DLL must match the MzScheme version Vim was compiled with.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000294For MzScheme version 209 they will be "libmzsch209_000.dll" and
Bram Moolenaar9964e462007-05-05 17:54:07 +0000295"libmzgc209_000.dll". To know for sure look at the output of the ":version"
296command, look for -DDYNAMIC_MZSCH_DLL="something" and
297-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000298
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100299For example, if MzScheme (Racket) is installed at C:\Racket63, you may need
300to set the environment variable as the following: >
301
302 PATH=%PATH%;C:\Racket63\lib
303 PLTCOLLECTS=C:\Racket63\collects
304 PLTCONFIGDIR=C:\Racket63\etc
305<
306==============================================================================
Bram Moolenaar705ada12016-01-24 17:56:50 +01003078. MzScheme setup *mzscheme-setup* *E895*
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100308
309Vim requires "racket/base" module for if_mzsch core (fallback to "scheme/base"
310if it doesn't exist), "r5rs" module for test and "raco ctool" command for
311building Vim. If MzScheme did not have them, you can install them with
312MzScheme's raco command:
313>
314 raco pkg install scheme-lib # scheme/base module
315 raco pkg install r5rs-lib # r5rs module
316 raco pkg install cext-lib # raco ctool command
317<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000318======================================================================
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200319 vim:tw=78:ts=8:noet:sts=4:ft=help:norl: