codekingpro/portable-devtools
114k
1*if_mzsch.txt* For Vim version 9.2. Last change: 2026 Feb 142 3 4 VIM REFERENCE MANUAL by Sergey Khorev5 6 7The MzScheme Interface to Vim *mzscheme* *MzScheme*8 91. Commands |mzscheme-commands|102. Examples |mzscheme-examples|113. Threads |mzscheme-threads|124. Vim access from MzScheme |mzscheme-vim|135. mzeval() Vim function |mzscheme-mzeval|146. Using Function references |mzscheme-funcref|157. Dynamic loading |mzscheme-dynamic|168. MzScheme setup |mzscheme-setup|17 18{only available when Vim was compiled with the |+mzscheme| feature}19 20Based on the work of Brent Fulgham.21Dynamic loading added by Sergey Khorev22 23MzScheme and PLT Scheme names have been rebranded as Racket. For more24information please check http://racket-lang.org25 26Futures and places of Racket version 5.x up to and including 5.3.1 do not27work correctly with processes created by Vim.28The simplest solution is to build Racket on your own with these features29disabled: >30 ./configure --disable-futures --disable-places --prefix=your-install-prefix31 32To speed up the process, you might also want to use --disable-gracket and33--disable-docs34 35==============================================================================361. Commands *mzscheme-commands*37 38 *:mzscheme* *:mz*39:[range]mz[scheme] {stmt}40 Execute MzScheme statement {stmt}.41 42:[range]mz[scheme] << [trim] [{endmarker}]43{script}44{endmarker}45 Execute inlined MzScheme script {script}.46 Note: This command doesn't work when the MzScheme47 feature wasn't compiled in. To avoid errors, see48 |script-here|.49 50 If [endmarker] is omitted from after the "<<", a dot51 '.' must be used after {script}, like for the52 |:append| and |:insert| commands. Refer to53 |:let-heredoc| for more information.54 55 56 *:mzfile* *:mzf*57:[range]mzf[ile] {file} Execute the MzScheme script in {file}.58 59All of these commands do essentially the same thing - they execute a piece of60MzScheme code, with the "current range" set to the given line61range.62 63In the case of :mzscheme, the code to execute is in the command-line.64In the case of :mzfile, the code to execute is the contents of the given file.65 66MzScheme interface defines exception exn:vim, derived from exn.67It is raised for various Vim errors.68 69During compilation, the MzScheme interface will remember the current MzScheme70collection path. If you want to specify additional paths use the71"current-library-collection-paths" parameter. E.g., to cons the user-local72MzScheme collection path: >73 :mz << EOF74 (current-library-collection-paths75 (cons76 (build-path (find-system-path 'addon-dir) (version) "collects")77 (current-library-collection-paths)))78 EOF79<80 81All functionality is provided through module vimext.82 83The exn:vim is available without explicit import.84 85To avoid clashes with MzScheme, consider using prefix when requiring module,86e.g.: >87 :mzscheme (require (prefix vim- vimext))88<89All the examples below assume this naming scheme.90 91 *mzscheme-sandbox*92When executed in the |sandbox|, access to some filesystem and Vim interface93procedures is restricted.94 95==============================================================================962. Examples *mzscheme-examples*97>98 :mzscheme (display "Hello")99 :mz (display (string-append "Using MzScheme version " (version)))100 :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x101 :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x102 :mzscheme (vim-set-buff-line 10 "This is line #10")103 104To see what version of MzScheme you have: >105 :mzscheme (display (version))106<107Inline script usage: >108 function! <SID>SetFirstLine()109 :mz << EOF110 (display "!!!")111 (require (prefix vim- vimext))112 ; for newer versions (require (prefix-in vim- 'vimext))113 (vim-set-buff-line 1 "This is line #1")114 (vim-beep)115 EOF116 endfunction117 118 nmap <F9> :call <SID>SetFirstLine() <CR>119<120File execution: >121 :mzfile supascript.scm122<123Vim exception handling: >124 :mz << EOF125 (require (prefix vim- vimext))126 ; for newer versions (require (prefix-in vim- 'vimext))127 (with-handlers128 ([exn:vim? (lambda (e) (display (exn-message e)))])129 (vim-eval "nonsense-string"))130 EOF131<132Auto-instantiation of vimext module (can be placed in your |vimrc|): >133 function! MzRequire()134 :redir => l:mzversion135 :mz (version)136 :redir END137 if strpart(l:mzversion, 1, 1) < "4"138 " MzScheme versions < 4.x:139 :mz (require (prefix vim- vimext))140 else141 " newer versions:142 :mz (require (prefix-in vim- 'vimext))143 endif144 endfunction145 146 if has("mzscheme")147 silent call MzRequire()148 endif149<150==============================================================================1513. Threads *mzscheme-threads*152 153The MzScheme interface supports threads. They are independent from OS154threads, thus scheduling is required. The option 'mzquantum' determines how155often Vim should poll for available MzScheme threads.156NOTE157Thread scheduling in the console version of Vim is less reliable than in the158GUI version.159 160==============================================================================1614. Vim access from MzScheme *mzscheme-vim*162 163 *mzscheme-vimext*164The 'vimext' module provides access to procedures defined in the MzScheme165interface.166 167Common168------169 (command {command-string}) Perform the vim ":Ex" style command.170 (eval {expr-string}) Evaluate the vim expression into171 respective MzScheme object: |Lists| are172 represented as Scheme lists,173 |Dictionaries| as hash tables,174 |Funcref|s as functions (see also175 |mzscheme-funcref|)176 NOTE the name clashes with MzScheme eval,177 use module qualifiers to overcome this.178 (range-start) Start/End of the range passed with179 (range-end) the Scheme command.180 (beep) beep181 (get-option {option-name} [buffer-or-window]) Get Vim option value (either182 local or global, see set-option).183 (set-option {string} [buffer-or-window])184 Set a Vim option. String must have option185 setting form (like optname=optval, or186 optname+=optval, etc.) When called with187 {buffer} or {window} the local option will188 be set. The symbol 'global can be passed189 as {buffer-or-window}. Then |:setglobal|190 will be used.191 192Buffers *mzscheme-buffer*193-------194 (buff? {object}) Is object a buffer?195 (buff-valid? {object}) Is object a valid buffer? (i.e.196 corresponds to the real Vim buffer)197 (get-buff-line {linenr} [buffer])198 Get line from a buffer.199 (set-buff-line {linenr} {string} [buffer])200 Set a line in a buffer. If {string} is201 #f, the line gets deleted. The [buffer]202 argument is optional. If omitted, the203 current buffer will be used.204 (get-buff-line-list {start} {end} [buffer])205 Get a list of lines in a buffer. {Start}206 and {end} are 1-based and inclusive.207 (set-buff-line-list {start} {end} {string-list} [buffer])208 Set a list of lines in a buffer. If209 string-list is #f or null, the lines get210 deleted. If a list is shorter than211 {end}-{start} the remaining lines will212 be deleted.213 (get-buff-name [buffer]) Get a buffer's text name.214 (get-buff-num [buffer]) Get a buffer's number.215 (get-buff-size [buffer]) Get buffer line count.216 (insert-buff-line-list {linenr} {string/string-list} [buffer])217 Insert a list of lines into a buffer after218 {linenr}. If {linenr} is 0, lines will be219 inserted at start.220 (curr-buff) Get the current buffer. Use other221 MzScheme interface procedures to change222 it.223 (buff-count) Get count of total buffers in the editor.224 (get-next-buff [buffer]) Get next buffer.225 (get-prev-buff [buffer]) Get previous buffer. Return #f when there226 are no more buffers.227 (open-buff {filename}) Open a new buffer (for file "name")228 (get-buff-by-name {buffername}) Get a buffer by its filename or #f229 if there is no such buffer.230 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if231 there is no buffer with this number).232 233Windows *mzscheme-window*234------235 (win? {object}) Is object a window?236 (win-valid? {object}) Is object a valid window (i.e. corresponds237 to the real Vim window)?238 (curr-win) Get the current window.239 (win-count) Get count of windows.240 (get-win-num [window]) Get window number.241 (get-win-by-num {windownum}) Get window by its number.242 (get-win-buffer [window]) Get the buffer for a given window.243 (get-win-height [window])244 (set-win-height {height} [window]) Get/Set height of window.245 (get-win-width [window])246 (set-win-width {width} [window])Get/Set width of window.247 (get-win-list [buffer]) Get list of windows for a buffer.248 (get-cursor [window]) Get cursor position in a window as249 a pair (linenr . column).250 (set-cursor (line . col) [window]) Set cursor position.251 252==============================================================================2535. mzeval() Vim function *mzscheme-mzeval*254 255To facilitate bi-directional interface, you can use |mzeval()| function to256evaluate MzScheme expressions and pass their values to Vim script.257 258==============================================================================2596. Using Function references *mzscheme-funcref*260 261MzScheme interface allows use of |Funcref|s so you can call Vim functions262directly from Scheme. For instance: >263 function! MyAdd2(arg)264 return a:arg + 2265 endfunction266 mz (define f2 (vim-eval "function(\"MyAdd2\")"))267 mz (f2 7)268< or : >269 :mz (define indent (vim-eval "function('indent')"))270 " return Vim indent for line 12271 :mz (indent 12)272<273 274==============================================================================2757. Dynamic loading *mzscheme-dynamic* *E815*276 277On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|278output then includes |+mzscheme/dyn|.279 280This means that Vim will search for the MzScheme DLL files only when needed.281When you don't use the MzScheme interface you don't need them, thus you can282use Vim without these DLL files.283NOTE: Newer version of MzScheme (Racket) require earlier (trampolined)284initialisation via scheme_main_setup. So Vim always loads the MzScheme DLL at285startup if possible. This may make Vim startup slower.286 287To use the MzScheme interface the MzScheme DLLs must be in your search path.288In a console window type "path" to see what directories are used.289 290On MS-Windows the options 'mzschemedll' and 'mzschemegcdll' are used for the291name of the library to load. The initial value is specified at build time.292 293The version of the DLL must match the MzScheme version Vim was compiled with.294For MzScheme version 209 they will be "libmzsch209_000.dll" and295"libmzgc209_000.dll". To know for sure look at the output of the ":version"296command, look for -DDYNAMIC_MZSCH_DLL="something" and297-DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.298 299For example, if MzScheme (Racket) is installed at C:\Racket63, you may need300to set the environment variable as the following: >301 302 PATH=%PATH%;C:\Racket63\lib303 PLTCOLLECTS=C:\Racket63\collects304 PLTCONFIGDIR=C:\Racket63\etc305<306==============================================================================3078. MzScheme setup *mzscheme-setup* *E895*308 309Vim requires "racket/base" module for if_mzsch core (fallback to "scheme/base"310if it doesn't exist), "r5rs" module for test and "raco ctool" command for311building Vim. If MzScheme did not have them, you can install them with312MzScheme's raco command:313>314 raco pkg install scheme-lib # scheme/base module315 raco pkg install r5rs-lib # r5rs module316 raco pkg install cext-lib # raco ctool command317<318======================================================================319 vim:tw=78:ts=8:noet:sts=4:ft=help:norl:320 