Mercurial > vim
comparison runtime/doc/if_mzsch.txt @ 1894:afb740b5dfab v7.2.191
updated for version 7.2-191
author | vimboss |
---|---|
date | Tue, 26 May 2009 20:59:55 +0000 |
parents | 5232b9862f23 |
children | 6e9c10c63e25 |
comparison
equal
deleted
inserted
replaced
1893:a75120dc3e26 | 1894:afb740b5dfab |
---|---|
1 *if_mzsch.txt* For Vim version 7.2. Last change: 2008 Jun 28 | 1 *if_mzsch.txt* For Vim version 7.2. Last change: 2009 May 26 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Sergey Khorev | 4 VIM REFERENCE MANUAL by Sergey Khorev |
5 | 5 |
6 | 6 |
40 feature wasn't compiled in. To avoid errors, see | 40 feature wasn't compiled in. To avoid errors, see |
41 |script-here|. | 41 |script-here|. |
42 | 42 |
43 *:mzfile* *:mzf* | 43 *:mzfile* *:mzf* |
44 :[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi} | 44 :[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi} |
45 All statements are executed in the namespace of the | |
46 buffer that was current during :mzfile start. | |
47 If you want to access other namespaces, use | |
48 'parameterize'. | |
49 | 45 |
50 All of these commands do essentially the same thing - they execute a piece of | 46 All of these commands do essentially the same thing - they execute a piece of |
51 MzScheme code, with the "current range" set to the given line | 47 MzScheme code, with the "current range" set to the given line |
52 range. | 48 range. |
53 | 49 |
54 In the case of :mzscheme, the code to execute is in the command-line. | 50 In the case of :mzscheme, the code to execute is in the command-line. |
55 In the case of :mzfile, the code to execute is the contents of the given file. | 51 In the case of :mzfile, the code to execute is the contents of the given file. |
56 | 52 |
57 Each buffer has its own MzScheme namespace. Global namespace is bound to | |
58 the "global-namespace" value from the 'vimext' module. | |
59 MzScheme interface defines exception exn:vim, derived from exn. | 53 MzScheme interface defines exception exn:vim, derived from exn. |
60 It is raised for various Vim errors. | 54 It is raised for various Vim errors. |
61 | 55 |
62 During compilation, the MzScheme interface will remember the current MzScheme | 56 During compilation, the MzScheme interface will remember the current MzScheme |
63 collection path. If you want to specify additional paths use the | 57 collection path. If you want to specify additional paths use the |
77 | 71 |
78 To avoid clashes with MzScheme, consider using prefix when requiring module, | 72 To avoid clashes with MzScheme, consider using prefix when requiring module, |
79 e.g.: > | 73 e.g.: > |
80 :mzscheme (require (prefix vim- vimext)) | 74 :mzscheme (require (prefix vim- vimext)) |
81 < | 75 < |
82 All the examples below assume this naming scheme. Note that you need to do | 76 All the examples below assume this naming scheme. |
83 this again for every buffer. | 77 |
84 | |
85 The auto-instantiation can be achieved with autocommands, e.g. you can put | |
86 something like this in your .vimrc (EOFs should not have indentation): > | |
87 function s:MzRequire() | |
88 if has("mzscheme") | |
89 :mz << EOF | |
90 (require (prefix vim- vimext)) | |
91 (let ((buf (vim-get-buff-by-name (vim-eval "expand(\"<afile>\")")))) | |
92 (when (and buf (not (eq? buf (vim-curr-buff)))) | |
93 (parameterize ((current-namespace (vim-get-buff-namespace buf))) | |
94 (namespace-attach-module vim-global-namespace 'vimext) | |
95 (namespace-require '(prefix vim vimext))))) | |
96 EOF | |
97 endif | |
98 endfunction | |
99 | |
100 function s:MzStartup() | |
101 if has("mzscheme") | |
102 au BufNew,BufNewFile,BufAdd,BufReadPre * :call s:MzRequire() | |
103 :mz << EOF | |
104 (current-library-collection-paths | |
105 (cons | |
106 (build-path (find-system-path 'addon-dir) (version) "collects") | |
107 (current-library-collection-paths))) | |
108 EOF | |
109 endif | |
110 endfunction | |
111 | |
112 call s:MzStartup() | |
113 < | |
114 | |
115 The global namespace just instantiated this module with the prefix "vimext:". | |
116 *mzscheme-sandbox* | 78 *mzscheme-sandbox* |
117 When executed in the |sandbox|, access to some filesystem and Vim interface | 79 When executed in the |sandbox|, access to some filesystem and Vim interface |
118 procedures is restricted. | 80 procedures is restricted. |
119 | 81 |
120 ============================================================================== | 82 ============================================================================== |
121 2. Examples *mzscheme-examples* | 83 2. Examples *mzscheme-examples* |
122 > | 84 > |
123 :mzscheme (display "Hello") | 85 :mzscheme (display "Hello") |
86 :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 | |
124 :mzscheme (vim-set-buff-line 10 "This is line #10") | 89 :mzscheme (vim-set-buff-line 10 "This is line #10") |
125 < | 90 < |
126 Inline script usage: > | 91 Inline script usage: > |
127 function! <SID>SetFirstLine() | 92 function! <SID>SetFirstLine() |
128 :mz << EOF | 93 :mz << EOF |
129 (display "!!!") | 94 (display "!!!") |
95 (require (prefix vim- vimext)) | |
96 ; for newer versions (require (prefix-in vim- 'vimext)) | |
130 (vim-set-buff-line 1 "This is line #1") | 97 (vim-set-buff-line 1 "This is line #1") |
131 (vim-beep) | 98 (vim-beep) |
132 EOF | 99 EOF |
133 endfunction | 100 endfunction |
134 | 101 |
135 nmap <F9> :call <SID>SetFirstLine() <CR> | 102 nmap <F9> :call <SID>SetFirstLine() <CR> |
136 < | 103 < |
137 File execution: > | 104 File execution: > |
138 :mzfile supascript.scm | 105 :mzfile supascript.scm |
139 < | 106 < |
140 Accessing the current buffer namespace from an MzScheme program running in | 107 Vim exception handling: > |
141 another buffer within |:mzfile|-executed script : > | 108 :mz << EOF |
142 ; Move to the window below | 109 (require (prefix vim- vimext)) |
143 (vim-command "wincmd j") | 110 ; for newer versions (require (prefix-in vim- 'vimext)) |
144 ; execute in the context of buffer, to which window belongs | 111 (with-handlers |
145 ; assume that buffer has 'textstring' defined | 112 ([exn:vim? (lambda (e) (display (exn-message e)))]) |
146 (parameterize ((current-namespace | 113 (vim-eval "nonsense-string")) |
147 (vim-get-buff-namespace (vim-curr-buff)))) | 114 EOF |
148 (eval '(vim-set-buff-line 1 textstring))) | 115 < |
149 < | 116 Auto-instantiation of vimext module (can be placed in your |vimrc|): > |
150 | 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 | |
129 | |
130 if has("mzscheme") | |
131 silent call MzRequire() | |
132 endif | |
133 < | |
151 ============================================================================== | 134 ============================================================================== |
152 3. Threads *mzscheme-threads* | 135 3. Threads *mzscheme-threads* |
153 | 136 |
154 The MzScheme interface supports threads. They are independent from OS threads, | 137 The MzScheme interface supports threads. They are independent from OS threads, |
155 thus scheduling is required. The option 'mzquantum' determines how often | 138 thus scheduling is required. The option 'mzquantum' determines how often |
166 interface. | 149 interface. |
167 | 150 |
168 Common | 151 Common |
169 ------ | 152 ------ |
170 (command {command-string}) Perform the vim ":Ex" style command. | 153 (command {command-string}) Perform the vim ":Ex" style command. |
171 (eval {expr-string}) Evaluate the vim expression to a string. | 154 (eval {expr-string}) Evaluate the vim expression into |
172 A |List| is turned into a string by | 155 respective MzScheme object: |Lists| are |
173 joining the items and inserting line | 156 represented as Scheme lists, |
174 breaks. | 157 |Dictionaries| as hash tables. |
175 NOTE clashes with MzScheme eval | 158 NOTE the name clashes with MzScheme eval |
176 (range-start) Start/End of the range passed with | 159 (range-start) Start/End of the range passed with |
177 (range-end) the Scheme command. | 160 (range-end) the Scheme command. |
178 (beep) beep | 161 (beep) beep |
179 (get-option {option-name} [buffer-or-window]) Get Vim option value (either | 162 (get-option {option-name} [buffer-or-window]) Get Vim option value (either |
180 local or global, see set-option). | 163 local or global, see set-option). |
184 optname+=optval, etc.) When called with | 167 optname+=optval, etc.) When called with |
185 {buffer} or {window} the local option will | 168 {buffer} or {window} the local option will |
186 be set. The symbol 'global can be passed | 169 be set. The symbol 'global can be passed |
187 as {buffer-or-window}. Then |:setglobal| | 170 as {buffer-or-window}. Then |:setglobal| |
188 will be used. | 171 will be used. |
189 global-namespace The MzScheme main namespace. | |
190 | 172 |
191 Buffers *mzscheme-buffer* | 173 Buffers *mzscheme-buffer* |
192 ------- | 174 ------- |
193 (buff? {object}) Is object a buffer? | 175 (buff? {object}) Is object a buffer? |
194 (buff-valid? {object}) Is object a valid buffer? (i.e. | 176 (buff-valid? {object}) Is object a valid buffer? (i.e. |
226 (open-buff {filename}) Open a new buffer (for file "name") | 208 (open-buff {filename}) Open a new buffer (for file "name") |
227 (get-buff-by-name {buffername}) Get a buffer by its filename or #f | 209 (get-buff-by-name {buffername}) Get a buffer by its filename or #f |
228 if there is no such buffer. | 210 if there is no such buffer. |
229 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if | 211 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if |
230 there is no buffer with this number). | 212 there is no buffer with this number). |
231 (get-buff-namespace [buffer]) Get buffer namespace. | |
232 | 213 |
233 Windows *mzscheme-window* | 214 Windows *mzscheme-window* |
234 ------ | 215 ------ |
235 (win? {object}) Is object a window? | 216 (win? {object}) Is object a window? |
236 (win-valid? {object}) Is object a valid window (i.e. corresponds | 217 (win-valid? {object}) Is object a valid window (i.e. corresponds |
248 (get-cursor [window]) Get cursor position in a window as | 229 (get-cursor [window]) Get cursor position in a window as |
249 a pair (linenr . column). | 230 a pair (linenr . column). |
250 (set-cursor (line . col) [window]) Set cursor position. | 231 (set-cursor (line . col) [window]) Set cursor position. |
251 | 232 |
252 ============================================================================== | 233 ============================================================================== |
253 5. Dynamic loading *mzscheme-dynamic* | 234 5. Dynamic loading *mzscheme-dynamic* *E812* |
254 | 235 |
255 On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version| | 236 On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version| |
256 output then includes |+mzscheme/dyn|. | 237 output then includes |+mzscheme/dyn|. |
257 | 238 |
258 This means that Vim will search for the MzScheme DLL files only when needed. | 239 This means that Vim will search for the MzScheme DLL files only when needed. |