blob: bb82c174428d4ee58ba7ad7d8f99c0260acf5fc6 [file] [log] [blame]
Bram Moolenaar281bdce2005-01-25 21:53:18 +00001*if_mzsch.txt* For Vim version 7.0aa. Last change: 2005 Jan 23
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:".
113
114==============================================================================
1152. Examples *mzscheme-examples*
116>
117 :mzscheme (display "Hello")
118 :mzscheme (vim-set-buff-line 10 "This is line #10")
119<
120Inline script usage: >
121 function! <SID>SetFirstLine()
122 :mz << EOF
123 (display "!!!")
124 (vim-set-buff-line 1 "This is line #1")
125 (vim-beep)
126 EOF
127 endfunction
128
129 nmap <F9> :call <SID>SetFirstLine() <CR>
130<
131File execution: >
132 :mzfile supascript.scm
133<
134Accessing the current buffer namespace from an MzScheme program running in
135another buffer within |:mzfile|-executed script : >
136 ; Move to the window below
137 (vim-command "wincmd j")
138 ; execute in the context of buffer, to which window belongs
139 ; assume that buffer has 'textstring' defined
140 (parameterize ((current-namespace
141 (vim-get-buff-namespace (vim-curr-buff))))
142 (eval '(vim-set-buff-line 1 textstring)))
143<
144
145==============================================================================
1463. Threads *mzscheme-threads*
147
148The MzScheme interface supports threads. They are independent from OS threads,
149thus scheduling is required. The option 'mzquantum' determines how often
150Vim should poll for available MzScheme threads.
151NOTE
152Thread scheduling in the console version of Vim is less reliable than in the
153GUI version.
154
155==============================================================================
1565. VIM Functions *mzscheme-vim*
157
158 *mzscheme-vimext*
159The 'vimext' module provides access to procedures defined in the MzScheme
160interface.
161
162Common
163------
164 (command {command-string}) Perform the vim ":Ex" style command.
165 (eval {expr-string}) Evaluate the vim command string.
166 NOTE clashes with MzScheme eval
167 (range-start) Start/End of the range passed with
168 (range-end) the Scheme command.
169 (beep) beep
170 (get-option {option-name} [buffer-or-window]) Get Vim option value (either
171 local or global, see set-option).
172 (set-option {string} [buffer-or-window])
173 Set a Vim option. String must have option
174 setting form (like optname=optval, or
175 optname+=optval, etc.) When called with
176 {buffer} or {window} the local option will
177 be set. The symbol 'global can be passed
178 as {buffer-or-window}. Then |:setglobal|
179 will be used.
180 global-namespace The MzScheme main namespace.
181
182Buffers *mzscheme-buffer*
183-------
184 (buff? {object}) Is object a buffer?
185 (buff-valid? {object}) Is object a valid buffer? (i.e.
186 corresponds to the real Vim buffer)
187 (get-buff-line {linenr} [buffer])
188 Get line from a buffer.
189 (set-buff-line {linenr} {string} [buffer])
190 Set a line in a buffer. If {string} is #f,
191 the line gets deleted. The [buffer]
192 argument is optional. If omitted, the
193 current buffer will be used.
194 (get-buff-line-list {start} {end} [buffer])
195 Get a list of lines in a buffer. {Start}
196 and {end} are 1-based. {Start} is
197 inclusive, {end} - exclusive.
198 (set-buff-line-list {start} {end} {string-list} [buffer])
199 Set a list of lines in a buffer. If
200 string-list is #f or null, the lines get
201 deleted. If a list is shorter than
202 {end}-{start} the remaining lines will
203 be deleted.
204 (get-buff-name [buffer]) Get a buffer's text name.
205 (get-buff-num [buffer]) Get a buffer's number.
206 (get-buff-size [buffer]) Get buffer line count.
207 (insert-buff-line-list {linenr} {string/string-list} [buffer])
208 Insert a list of lines into a buffer after
209 {linenr}. If {linenr} is 0, lines will be
210 inserted at start.
211 (curr-buff) Get the current buffer. Use procedures
212 from `vimcmd' module to change it.
213 (buff-count) Get count of total buffers in the editor.
214 (get-next-buff [buffer]) Get next buffer.
215 (get-prev-buff [buffer]) Get previous buffer. Return #f when there
216 are no more buffers.
217 (open-buff {filename}) Open a new buffer (for file "name")
218 (get-buff-by-name {buffername}) Get a buffer by its filename or #f
219 if there is no such buffer.
220 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
221 there is no buffer with this number).
222 (get-buff-namespace [buffer]) Get buffer namespace.
223
224Windows *mzscheme-window*
225------
226 (win? {object}) Is object a window?
227 (win-valid? {object}) Is object a valid window (i.e. corresponds
228 to the real Vim window)?
229 (curr-win) Get the current window.
230 (win-count) Get count of windows.
231 (get-win-num [window]) Get window number.
232 (get-win-by-num {windownum}) Get window by its number.
233 (get-win-buffer [window]) Get the buffer for a given window.
234 (get-win-height [window])
235 (set-win-height {height} [window]) Get/Set height of window.
236 (get-win-width [window])
237 (set-win-width {width} [window])Get/Set width of window.
238 (get-win-list [buffer]) Get list of windows for a buffer.
239 (get-cursor [window]) Get cursor position in a window as
240 a pair (linenr . column).
241 (set-cursor (line . col) [window]) Set cursor position.
242
243======================================================================
244 vim:tw=78:ts=8:sts=4:ft=help:norl: