blob: ceecdba3028e858d70f11fa60b711f26ad8572a1 [file] [log] [blame]
Bram Moolenaarb849e712009-06-24 15:51:37 +00001*if_mzsch.txt* For Vim version 7.2. Last change: 2009 Jun 24
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
Bram Moolenaar9964e462007-05-05 17:54:07 +000026Note: On FreeBSD you should use the "drscheme" port.
27
Bram Moolenaar325b7a22004-07-05 15:58:32 +000028==============================================================================
291. Commands *mzscheme-commands*
30
31 *:mzscheme* *:mz*
32:[range]mz[scheme] {stmt}
33 Execute MzScheme statement {stmt}. {not in Vi}
34
35:[range]mz[scheme] << {endmarker}
36{script}
37{endmarker}
38 Execute inlined MzScheme script {script}.
39 Note: This command doesn't work if the MzScheme
40 feature wasn't compiled in. To avoid errors, see
41 |script-here|.
42
43 *:mzfile* *:mzf*
44:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
Bram Moolenaar325b7a22004-07-05 15:58:32 +000045
46All of these commands do essentially the same thing - they execute a piece of
47MzScheme code, with the "current range" set to the given line
48range.
49
50In the case of :mzscheme, the code to execute is in the command-line.
51In the case of :mzfile, the code to execute is the contents of the given file.
52
Bram Moolenaar325b7a22004-07-05 15:58:32 +000053MzScheme interface defines exception exn:vim, derived from exn.
54It is raised for various Vim errors.
55
56During compilation, the MzScheme interface will remember the current MzScheme
57collection path. If you want to specify additional paths use the
58'current-library-collection-paths' parameter. E.g., to cons the user-local
59MzScheme collection path: >
60 :mz << EOF
61 (current-library-collection-paths
62 (cons
63 (build-path (find-system-path 'addon-dir) (version) "collects")
64 (current-library-collection-paths)))
65 EOF
66<
67
68All functionality is provided through module vimext.
69
70The exn:vim is available without explicit import.
71
72To avoid clashes with MzScheme, consider using prefix when requiring module,
73e.g.: >
74 :mzscheme (require (prefix vim- vimext))
75<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000076All the examples below assume this naming scheme.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000077
Bram Moolenaar051b7822005-05-19 21:00:46 +000078 *mzscheme-sandbox*
79When executed in the |sandbox|, access to some filesystem and Vim interface
80procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +000081
82==============================================================================
832. Examples *mzscheme-examples*
84>
85 :mzscheme (display "Hello")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000086 :mz (display (string-append "Using MzScheme version " (version)))
87 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
88 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
Bram Moolenaar325b7a22004-07-05 15:58:32 +000089 :mzscheme (vim-set-buff-line 10 "This is line #10")
90<
91Inline script usage: >
92 function! <SID>SetFirstLine()
93 :mz << EOF
94 (display "!!!")
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000095 (require (prefix vim- vimext))
96 ; for newer versions (require (prefix-in vim- 'vimext))
Bram Moolenaar325b7a22004-07-05 15:58:32 +000097 (vim-set-buff-line 1 "This is line #1")
98 (vim-beep)
Bram Moolenaar9e70cf12009-05-26 20:59:55 +000099 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000100 endfunction
101
102 nmap <F9> :call <SID>SetFirstLine() <CR>
103<
104File execution: >
105 :mzfile supascript.scm
106<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000107Vim exception handling: >
108 :mz << EOF
109 (require (prefix vim- vimext))
110 ; for newer versions (require (prefix-in vim- 'vimext))
111 (with-handlers
112 ([exn:vim? (lambda (e) (display (exn-message e)))])
113 (vim-eval "nonsense-string"))
114 EOF
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000115<
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000116Auto-instantiation of vimext module (can be placed in your |vimrc|): >
117 function! MzRequire()
118 :redir => l:mzversion
119 :mz (version)
120 :redir END
121 if strpart(l:mzversion, 1, 1) < "4"
122 " MzScheme versions < 4.x:
123 :mz (require (prefix vim- vimext))
124 else
125 " newer versions:
126 :mz (require (prefix-in vim- 'vimext))
127 endif
128 endfunction
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000129
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000130 if has("mzscheme")
131 silent call MzRequire()
132 endif
133<
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000134==============================================================================
1353. Threads *mzscheme-threads*
136
137The MzScheme interface supports threads. They are independent from OS threads,
138thus scheduling is required. The option 'mzquantum' determines how often
139Vim should poll for available MzScheme threads.
140NOTE
141Thread scheduling in the console version of Vim is less reliable than in the
142GUI version.
143
144==============================================================================
1455. VIM Functions *mzscheme-vim*
146
147 *mzscheme-vimext*
148The 'vimext' module provides access to procedures defined in the MzScheme
149interface.
150
151Common
152------
153 (command {command-string}) Perform the vim ":Ex" style command.
Bram Moolenaar9e70cf12009-05-26 20:59:55 +0000154 (eval {expr-string}) Evaluate the vim expression into
155 respective MzScheme object: |Lists| are
156 represented as Scheme lists,
157 |Dictionaries| as hash tables.
158 NOTE the name clashes with MzScheme eval
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000159 (range-start) Start/End of the range passed with
160 (range-end) the Scheme command.
161 (beep) beep
162 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
163 local or global, see set-option).
164 (set-option {string} [buffer-or-window])
165 Set a Vim option. String must have option
166 setting form (like optname=optval, or
167 optname+=optval, etc.) When called with
168 {buffer} or {window} the local option will
169 be set. The symbol 'global can be passed
170 as {buffer-or-window}. Then |:setglobal|
171 will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000172
173Buffers *mzscheme-buffer*
174-------
175 (buff? {object}) Is object a buffer?
176 (buff-valid? {object}) Is object a valid buffer? (i.e.
177 corresponds to the real Vim buffer)
178 (get-buff-line {linenr} [buffer])
179 Get line from a buffer.
180 (set-buff-line {linenr} {string} [buffer])
181 Set a line in a buffer. If {string} is #f,
182 the line gets deleted. The [buffer]
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000183 argument is optional. If omitted, the
184 current buffer will be used.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000185 (get-buff-line-list {start} {end} [buffer])
186 Get a list of lines in a buffer. {Start}
187 and {end} are 1-based. {Start} is
188 inclusive, {end} - exclusive.
189 (set-buff-line-list {start} {end} {string-list} [buffer])
190 Set a list of lines in a buffer. If
191 string-list is #f or null, the lines get
192 deleted. If a list is shorter than
193 {end}-{start} the remaining lines will
194 be deleted.
195 (get-buff-name [buffer]) Get a buffer's text name.
196 (get-buff-num [buffer]) Get a buffer's number.
197 (get-buff-size [buffer]) Get buffer line count.
198 (insert-buff-line-list {linenr} {string/string-list} [buffer])
199 Insert a list of lines into a buffer after
200 {linenr}. If {linenr} is 0, lines will be
201 inserted at start.
202 (curr-buff) Get the current buffer. Use procedures
Bram Moolenaarc236c162008-07-13 17:41:49 +0000203 from "vimcmd" module to change it.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000204 (buff-count) Get count of total buffers in the editor.
205 (get-next-buff [buffer]) Get next buffer.
206 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
207 are no more buffers.
208 (open-buff {filename}) Open a new buffer (for file "name")
209 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
210 if there is no such buffer.
211 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
212 there is no buffer with this number).
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000213
214Windows *mzscheme-window*
215------
216 (win? {object}) Is object a window?
217 (win-valid? {object}) Is object a valid window (i.e. corresponds
218 to the real Vim window)?
219 (curr-win) Get the current window.
220 (win-count) Get count of windows.
221 (get-win-num [window]) Get window number.
222 (get-win-by-num {windownum}) Get window by its number.
223 (get-win-buffer [window]) Get the buffer for a given window.
224 (get-win-height [window])
225 (set-win-height {height} [window]) Get/Set height of window.
226 (get-win-width [window])
227 (set-win-width {width} [window])Get/Set width of window.
228 (get-win-list [buffer]) Get list of windows for a buffer.
229 (get-cursor [window]) Get cursor position in a window as
230 a pair (linenr . column).
231 (set-cursor (line . col) [window]) Set cursor position.
232
Bram Moolenaar4770d092006-01-12 23:22:24 +0000233==============================================================================
Bram Moolenaarb849e712009-06-24 15:51:37 +00002345. Dynamic loading *mzscheme-dynamic* *E815*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000235
236On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
237output then includes |+mzscheme/dyn|.
238
239This means that Vim will search for the MzScheme DLL files only when needed.
240When you don't use the MzScheme interface you don't need them, thus you can
241use Vim without these DLL files.
242
243To use the MzScheme interface the MzScheme DLLs must be in your search path.
244In a console window type "path" to see what directories are used.
245
246The names of the DLLs must match the MzScheme version Vim was compiled with.
247For MzScheme version 209 they will be "libmzsch209_000.dll" and
Bram Moolenaar9964e462007-05-05 17:54:07 +0000248"libmzgc209_000.dll". To know for sure look at the output of the ":version"
249command, look for -DDYNAMIC_MZSCH_DLL="something" and
250-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
Bram Moolenaar4770d092006-01-12 23:22:24 +0000251
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000252======================================================================
253 vim:tw=78:ts=8:sts=4:ft=help:norl: