blob: 0580891e2420063179783f2c59f0c41a09466a64 [file] [log] [blame]
Bram Moolenaar051b7822005-05-19 21:00:46 +00001*if_mzsch.txt* For Vim version 7.0aa. Last change: 2005 May 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|
124. The Vim access procedures |mzscheme-vim|
13
14{Vi does not have any of these commands}
15
16The MzScheme interface is available only if Vim was compiled with the
17|+mzscheme| feature.
18
19Based on the work of Brent Fulgham.
Bram Moolenaar281bdce2005-01-25 21:53:18 +000020Dynamic loading added by Sergey Khorev
Bram Moolenaar325b7a22004-07-05 15:58:32 +000021
22For downloading MzScheme and other info:
23 http://www.plt-scheme.org/software/mzscheme/
24
25==============================================================================
261. Commands *mzscheme-commands*
27
28 *:mzscheme* *:mz*
29:[range]mz[scheme] {stmt}
30 Execute MzScheme statement {stmt}. {not in Vi}
31
32:[range]mz[scheme] << {endmarker}
33{script}
34{endmarker}
35 Execute inlined MzScheme script {script}.
36 Note: This command doesn't work if the MzScheme
37 feature wasn't compiled in. To avoid errors, see
38 |script-here|.
39
40 *:mzfile* *:mzf*
41:[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
42 All statements are executed in the namespace of the
43 buffer that was current during :mzfile start.
44 If you want to access other namespaces, use
45 'parameterize'.
46
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
54Each buffer has its own MzScheme namespace. Global namespace is bound to
55the `global-namespace' value from the 'vimext' module.
56MzScheme interface defines exception exn:vim, derived from exn.
57It is raised for various Vim errors.
58
59During compilation, the MzScheme interface will remember the current MzScheme
60collection path. If you want to specify additional paths use the
61'current-library-collection-paths' parameter. E.g., to cons the user-local
62MzScheme collection path: >
63 :mz << EOF
64 (current-library-collection-paths
65 (cons
66 (build-path (find-system-path 'addon-dir) (version) "collects")
67 (current-library-collection-paths)))
68 EOF
69<
70
71All functionality is provided through module vimext.
72
73The exn:vim is available without explicit import.
74
75To avoid clashes with MzScheme, consider using prefix when requiring module,
76e.g.: >
77 :mzscheme (require (prefix vim- vimext))
78<
79All the examples below assume this naming scheme. Note that you need to do
80this again for every buffer.
81
82The auto-instantiation can be achieved with autocommands, e.g. you can put
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +000083something like this in your .vimrc (EOFs should not have indentation): >
84 function s:MzRequire()
85 if has("mzscheme")
86 :mz << EOF
87 (require (prefix vim- vimext))
88 (let ((buf (vim-get-buff-by-name (vim-eval "expand(\"<afile>\")"))))
89 (when (and buf (not (eq? buf (vim-curr-buff))))
90 (parameterize ((current-namespace (vim-get-buff-namespace buf)))
91 (namespace-attach-module vim-global-namespace 'vimext)
92 (namespace-require '(prefix vim vimext)))))
93 EOF
94 endif
95 endfunction
96
97 function s:MzStartup()
98 if has("mzscheme")
99 au BufNew,BufNewFile,BufAdd,BufReadPre * :call s:MzRequire()
100 :mz << EOF
101 (current-library-collection-paths
102 (cons
103 (build-path (find-system-path 'addon-dir) (version) "collects")
104 (current-library-collection-paths)))
105 EOF
106 endif
107 endfunction
108
109 call s:MzStartup()
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000110<
111
112The global namespace just instantiated this module with the prefix "vimext:".
Bram Moolenaar051b7822005-05-19 21:00:46 +0000113 *mzscheme-sandbox*
114When executed in the |sandbox|, access to some filesystem and Vim interface
115procedures is restricted.
Bram Moolenaar325b7a22004-07-05 15:58:32 +0000116
117==============================================================================
1182. Examples *mzscheme-examples*
119>
120 :mzscheme (display "Hello")
121 :mzscheme (vim-set-buff-line 10 "This is line #10")
122<
123Inline script usage: >
124 function! <SID>SetFirstLine()
125 :mz << EOF
126 (display "!!!")
127 (vim-set-buff-line 1 "This is line #1")
128 (vim-beep)
129 EOF
130 endfunction
131
132 nmap <F9> :call <SID>SetFirstLine() <CR>
133<
134File execution: >
135 :mzfile supascript.scm
136<
137Accessing the current buffer namespace from an MzScheme program running in
138another buffer within |:mzfile|-executed script : >
139 ; Move to the window below
140 (vim-command "wincmd j")
141 ; execute in the context of buffer, to which window belongs
142 ; assume that buffer has 'textstring' defined
143 (parameterize ((current-namespace
144 (vim-get-buff-namespace (vim-curr-buff))))
145 (eval '(vim-set-buff-line 1 textstring)))
146<
147
148==============================================================================
1493. Threads *mzscheme-threads*
150
151The MzScheme interface supports threads. They are independent from OS threads,
152thus scheduling is required. The option 'mzquantum' determines how often
153Vim should poll for available MzScheme threads.
154NOTE
155Thread scheduling in the console version of Vim is less reliable than in the
156GUI version.
157
158==============================================================================
1595. VIM Functions *mzscheme-vim*
160
161 *mzscheme-vimext*
162The 'vimext' module provides access to procedures defined in the MzScheme
163interface.
164
165Common
166------
167 (command {command-string}) Perform the vim ":Ex" style command.
168 (eval {expr-string}) Evaluate the vim command string.
169 NOTE clashes with MzScheme eval
170 (range-start) Start/End of the range passed with
171 (range-end) the Scheme command.
172 (beep) beep
173 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
174 local or global, see set-option).
175 (set-option {string} [buffer-or-window])
176 Set a Vim option. String must have option
177 setting form (like optname=optval, or
178 optname+=optval, etc.) When called with
179 {buffer} or {window} the local option will
180 be set. The symbol 'global can be passed
181 as {buffer-or-window}. Then |:setglobal|
182 will be used.
183 global-namespace The MzScheme main namespace.
184
185Buffers *mzscheme-buffer*
186-------
187 (buff? {object}) Is object a buffer?
188 (buff-valid? {object}) Is object a valid buffer? (i.e.
189 corresponds to the real Vim buffer)
190 (get-buff-line {linenr} [buffer])
191 Get line from a buffer.
192 (set-buff-line {linenr} {string} [buffer])
193 Set a line in a buffer. If {string} is #f,
194 the line gets deleted. The [buffer]
195 argument is optional. If omitted, the
196 current buffer will be used.
197 (get-buff-line-list {start} {end} [buffer])
198 Get a list of lines in a buffer. {Start}
199 and {end} are 1-based. {Start} is
200 inclusive, {end} - exclusive.
201 (set-buff-line-list {start} {end} {string-list} [buffer])
202 Set a list of lines in a buffer. If
203 string-list is #f or null, the lines get
204 deleted. If a list is shorter than
205 {end}-{start} the remaining lines will
206 be deleted.
207 (get-buff-name [buffer]) Get a buffer's text name.
208 (get-buff-num [buffer]) Get a buffer's number.
209 (get-buff-size [buffer]) Get buffer line count.
210 (insert-buff-line-list {linenr} {string/string-list} [buffer])
211 Insert a list of lines into a buffer after
212 {linenr}. If {linenr} is 0, lines will be
213 inserted at start.
214 (curr-buff) Get the current buffer. Use procedures
215 from `vimcmd' module to change it.
216 (buff-count) Get count of total buffers in the editor.
217 (get-next-buff [buffer]) Get next buffer.
218 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
219 are no more buffers.
220 (open-buff {filename}) Open a new buffer (for file "name")
221 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
222 if there is no such buffer.
223 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
224 there is no buffer with this number).
225 (get-buff-namespace [buffer]) Get buffer namespace.
226
227Windows *mzscheme-window*
228------
229 (win? {object}) Is object a window?
230 (win-valid? {object}) Is object a valid window (i.e. corresponds
231 to the real Vim window)?
232 (curr-win) Get the current window.
233 (win-count) Get count of windows.
234 (get-win-num [window]) Get window number.
235 (get-win-by-num {windownum}) Get window by its number.
236 (get-win-buffer [window]) Get the buffer for a given window.
237 (get-win-height [window])
238 (set-win-height {height} [window]) Get/Set height of window.
239 (get-win-width [window])
240 (set-win-width {width} [window])Get/Set width of window.
241 (get-win-list [buffer]) Get list of windows for a buffer.
242 (get-cursor [window]) Get cursor position in a window as
243 a pair (linenr . column).
244 (set-cursor (line . col) [window]) Set cursor position.
245
246======================================================================
247 vim:tw=78:ts=8:sts=4:ft=help:norl: