blob: 9d27683f7f0ad335793a394c05d7c13856790b3c [file] [log] [blame]
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001*if_mzsch.txt* For Vim version 8.1. Last change: 2017 Oct 08
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
18{Vi does not have any of these commands}
19
20The MzScheme interface is available only if Vim was compiled with the
21|+mzscheme| feature.
22
23Based on the work of Brent Fulgham.
Bram Moolenaar281bdce2005-01-25 21:53:18 +000024Dynamic loading added by Sergey Khorev
Bram Moolenaar325b7a22004-07-05 15:58:32 +000025
Bram Moolenaar75676462013-01-30 14:55:42 +010026MzScheme and PLT Scheme names have been rebranded as Racket. For more
27information please check http://racket-lang.org
Bram Moolenaar325b7a22004-07-05 15:58:32 +000028
Bram Moolenaar75676462013-01-30 14:55:42 +010029Futures and places of Racket version 5.x up to and including 5.3.1 do not
30work correctly with processes created by Vim.
31The simplest solution is to build Racket on your own with these features
32disabled: >
33 ./configure --disable-futures --disable-places --prefix=your-install-prefix
34
35To speed up the process, you might also want to use --disable-gracket and
36--disable-docs
Bram Moolenaar9964e462007-05-05 17:54:07 +000037
Bram Moolenaar325b7a22004-07-05 15:58:32 +000038==============================================================================
391. Commands *mzscheme-commands*
40
41 *:mzscheme* *:mz*
42:[range]mz[scheme] {stmt}
43 Execute MzScheme statement {stmt}. {not in Vi}
44
45:[range]mz[scheme] << {endmarker}
46{script}
47{endmarker}
48 Execute inlined MzScheme script {script}.
49 Note: This command doesn't work if the MzScheme
50 feature wasn't compiled in. To avoid errors, see
51 |script-here|.
52
53 *:mzfile* *:mzf*
54:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
Bram Moolenaar325b7a22004-07-05 15:58:32 +000055
56All of these commands do essentially the same thing - they execute a piece of
57MzScheme code, with the "current range" set to the given line
58range.
59
60In the case of :mzscheme, the code to execute is in the command-line.
61In the case of :mzfile, the code to execute is the contents of the given file.
62
Bram Moolenaar325b7a22004-07-05 15:58:32 +000063MzScheme interface defines exception exn:vim, derived from exn.
64It is raised for various Vim errors.
65
66During compilation, the MzScheme interface will remember the current MzScheme
67collection path. If you want to specify additional paths use the
68'current-library-collection-paths' parameter. E.g., to cons the user-local
69MzScheme collection path: >
70 :mz << EOF
71 (current-library-collection-paths
72 (cons
73 (build-path (find-system-path 'addon-dir) (version) "collects")
74 (current-library-collection-paths)))
75 EOF
76<
77
78All functionality is provided through module vimext.
79
80The exn:vim is available without explicit import.
81
82To avoid clashes with MzScheme, consider using prefix when requiring module,
83e.g.: >
84 :mzscheme (require (prefix vim- vimext))
85<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000086All the examples below assume this naming scheme.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000087
Bram Moolenaar051b7822005-05-19 21:00:46 +000088 *mzscheme-sandbox*
89When executed in the |sandbox|, access to some filesystem and Vim interface
90procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000091
92==============================================================================
932. Examples *mzscheme-examples*
94>
95 :mzscheme (display "Hello")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000096 :mz (display (string-append "Using MzScheme version " (version)))
97 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
98 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
Bram Moolenaar325b7a22004-07-05 15:58:32 +000099 :mzscheme (vim-set-buff-line 10 "This is line #10")
Bram Moolenaarabd468e2016-09-08 22:22:43 +0200100
101To see what version of MzScheme you have: >
102 :mzscheme (display (version))
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000103<
104Inline script usage: >
105 function! <SID>SetFirstLine()
106 :mz << EOF
107 (display "!!!")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000108 (require (prefix vim- vimext))
109 ; for newer versions (require (prefix-in vim- 'vimext))
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000110 (vim-set-buff-line 1 "This is line #1")
111 (vim-beep)
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000112 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000113 endfunction
114
115 nmap <F9> :call <SID>SetFirstLine() <CR>
116<
117File execution: >
118 :mzfile supascript.scm
119<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000120Vim exception handling: >
121 :mz << EOF
122 (require (prefix vim- vimext))
123 ; for newer versions (require (prefix-in vim- 'vimext))
124 (with-handlers
125 ([exn:vim? (lambda (e) (display (exn-message e)))])
126 (vim-eval "nonsense-string"))
127 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000128<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000129Auto-instantiation of vimext module (can be placed in your |vimrc|): >
130 function! MzRequire()
131 :redir => l:mzversion
132 :mz (version)
133 :redir END
134 if strpart(l:mzversion, 1, 1) < "4"
135 " MzScheme versions < 4.x:
136 :mz (require (prefix vim- vimext))
137 else
138 " newer versions:
139 :mz (require (prefix-in vim- 'vimext))
140 endif
141 endfunction
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000142
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000143 if has("mzscheme")
144 silent call MzRequire()
145 endif
146<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000147==============================================================================
1483. Threads *mzscheme-threads*
149
150The MzScheme interface supports threads. They are independent from OS threads,
151thus scheduling is required. The option 'mzquantum' determines how often
152Vim should poll for available MzScheme threads.
153NOTE
154Thread scheduling in the console version of Vim is less reliable than in the
155GUI version.
156
157==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01001584. Vim access from MzScheme *mzscheme-vim*
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000159
160 *mzscheme-vimext*
161The 'vimext' module provides access to procedures defined in the MzScheme
162interface.
163
164Common
165------
166 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000167 (eval {expr-string}) Evaluate the vim expression into
168 respective MzScheme object: |Lists| are
169 represented as Scheme lists,
Bram Moolenaar75676462013-01-30 14:55:42 +0100170 |Dictionaries| as hash tables,
171 |Funcref|s as functions (see also
172 |mzscheme-funcref|)
173 NOTE the name clashes with MzScheme eval,
174 use module qualifiers to overcome this.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000175 (range-start) Start/End of the range passed with
176 (range-end) the Scheme command.
177 (beep) beep
178 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
179 local or global, see set-option).
180 (set-option {string} [buffer-or-window])
181 Set a Vim option. String must have option
182 setting form (like optname=optval, or
183 optname+=optval, etc.) When called with
184 {buffer} or {window} the local option will
185 be set. The symbol 'global can be passed
186 as {buffer-or-window}. Then |:setglobal|
187 will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000188
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]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000199 argument is optional. If omitted, the
200 current buffer will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000201 (get-buff-line-list {start} {end} [buffer])
202 Get a list of lines in a buffer. {Start}
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100203 and {end} are 1-based and inclusive.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000204 (set-buff-line-list {start} {end} {string-list} [buffer])
205 Set a list of lines in a buffer. If
206 string-list is #f or null, the lines get
207 deleted. If a list is shorter than
208 {end}-{start} the remaining lines will
209 be deleted.
210 (get-buff-name [buffer]) Get a buffer's text name.
211 (get-buff-num [buffer]) Get a buffer's number.
212 (get-buff-size [buffer]) Get buffer line count.
213 (insert-buff-line-list {linenr} {string/string-list} [buffer])
214 Insert a list of lines into a buffer after
215 {linenr}. If {linenr} is 0, lines will be
216 inserted at start.
Bram Moolenaar5e3dae82010-03-02 16:19:40 +0100217 (curr-buff) Get the current buffer. Use other MzScheme
218 interface procedures to change it.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000219 (buff-count) Get count of total buffers in the editor.
220 (get-next-buff [buffer]) Get next buffer.
221 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
222 are no more buffers.
223 (open-buff {filename}) Open a new buffer (for file "name")
224 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
225 if there is no such buffer.
226 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
227 there is no buffer with this number).
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000228
229Windows *mzscheme-window*
230------
231 (win? {object}) Is object a window?
232 (win-valid? {object}) Is object a valid window (i.e. corresponds
233 to the real Vim window)?
234 (curr-win) Get the current window.
235 (win-count) Get count of windows.
236 (get-win-num [window]) Get window number.
237 (get-win-by-num {windownum}) Get window by its number.
238 (get-win-buffer [window]) Get the buffer for a given window.
239 (get-win-height [window])
240 (set-win-height {height} [window]) Get/Set height of window.
241 (get-win-width [window])
242 (set-win-width {width} [window])Get/Set width of window.
243 (get-win-list [buffer]) Get list of windows for a buffer.
244 (get-cursor [window]) Get cursor position in a window as
245 a pair (linenr . column).
246 (set-cursor (line . col) [window]) Set cursor position.
247
Bram Moolenaar4770d092006-01-12 23:22:24 +0000248==============================================================================
Bram Moolenaar7e506b62010-01-19 15:55:06 +01002495. mzeval() Vim function *mzscheme-mzeval*
250
Bram Moolenaar945e2db2010-06-05 17:43:32 +0200251To facilitate bi-directional interface, you can use |mzeval()| function to
Bram Moolenaarb544f3c2017-02-23 19:03:28 +0100252evaluate MzScheme expressions and pass their values to Vim script.
Bram Moolenaar7e506b62010-01-19 15:55:06 +0100253
254==============================================================================
Bram Moolenaar75676462013-01-30 14:55:42 +01002556. Using Function references *mzscheme-funcref*
256
257MzScheme interface allows use of |Funcref|s so you can call Vim functions
258directly from Scheme. For instance: >
259 function! MyAdd2(arg)
260 return a:arg + 2
261 endfunction
262 mz (define f2 (vim-eval "function(\"MyAdd2\")"))
263 mz (f2 7)
264< or : >
265 :mz (define indent (vim-eval "function('indent')"))
266 " return Vim indent for line 12
267 :mz (indent 12)
268<
269
270==============================================================================
Bram Moolenaar705ada12016-01-24 17:56:50 +01002717. Dynamic loading *mzscheme-dynamic* *E815*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000272
273On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
274output then includes |+mzscheme/dyn|.
275
276This means that Vim will search for the MzScheme DLL files only when needed.
277When you don't use the MzScheme interface you don't need them, thus you can
278use Vim without these DLL files.
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100279NOTE: Newer version of MzScheme (Racket) require earlier (trampolined)
280initialisation via scheme_main_setup. So Vim always loads the MzScheme DLL at
Bram Moolenaar0ab35b22017-10-08 17:41:37 +0200281startup if possible. This may make Vim startup slower.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000282
283To use the MzScheme interface the MzScheme DLLs must be in your search path.
284In a console window type "path" to see what directories are used.
285
Bram Moolenaar0ab35b22017-10-08 17:41:37 +0200286On MS-Windows the options 'mzschemedll' and 'mzschemegcdll' are used for the
287name of the library to load. The initial value is specified at build time.
288
289The version of the DLL must match the MzScheme version Vim was compiled with.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000290For MzScheme version 209 they will be "libmzsch209_000.dll" and
Bram Moolenaar9964e462007-05-05 17:54:07 +0000291"libmzgc209_000.dll". To know for sure look at the output of the ":version"
292command, look for -DDYNAMIC_MZSCH_DLL="something" and
293-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000294
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100295For example, if MzScheme (Racket) is installed at C:\Racket63, you may need
296to set the environment variable as the following: >
297
298 PATH=%PATH%;C:\Racket63\lib
299 PLTCOLLECTS=C:\Racket63\collects
300 PLTCONFIGDIR=C:\Racket63\etc
301<
302==============================================================================
Bram Moolenaar705ada12016-01-24 17:56:50 +01003038. MzScheme setup *mzscheme-setup* *E895*
Bram Moolenaar4e640bd2016-01-16 16:20:38 +0100304
305Vim requires "racket/base" module for if_mzsch core (fallback to "scheme/base"
306if it doesn't exist), "r5rs" module for test and "raco ctool" command for
307building Vim. If MzScheme did not have them, you can install them with
308MzScheme's raco command:
309>
310 raco pkg install scheme-lib # scheme/base module
311 raco pkg install r5rs-lib # r5rs module
312 raco pkg install cext-lib # raco ctool command
313<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000314======================================================================
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200315 vim:tw=78:ts=8:noet:sts=4:ft=help:norl: