if_mzsch.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. *if_mzsch.txt* For Vim version 9.0. Last change: 2020 Oct 14
  2. VIM REFERENCE MANUAL by Sergey Khorev
  3. The MzScheme Interface to Vim *mzscheme* *MzScheme*
  4. 1. Commands |mzscheme-commands|
  5. 2. Examples |mzscheme-examples|
  6. 3. Threads |mzscheme-threads|
  7. 4. Vim access from MzScheme |mzscheme-vim|
  8. 5. mzeval() Vim function |mzscheme-mzeval|
  9. 6. Using Function references |mzscheme-funcref|
  10. 7. Dynamic loading |mzscheme-dynamic|
  11. 8. MzScheme setup |mzscheme-setup|
  12. {only available when Vim was compiled with the |+mzscheme| feature}
  13. Based on the work of Brent Fulgham.
  14. Dynamic loading added by Sergey Khorev
  15. MzScheme and PLT Scheme names have been rebranded as Racket. For more
  16. information please check http://racket-lang.org
  17. Futures and places of Racket version 5.x up to and including 5.3.1 do not
  18. work correctly with processes created by Vim.
  19. The simplest solution is to build Racket on your own with these features
  20. disabled: >
  21. ./configure --disable-futures --disable-places --prefix=your-install-prefix
  22. To speed up the process, you might also want to use --disable-gracket and
  23. --disable-docs
  24. ==============================================================================
  25. 1. Commands *mzscheme-commands*
  26. *:mzscheme* *:mz*
  27. :[range]mz[scheme] {stmt}
  28. Execute MzScheme statement {stmt}.
  29. :[range]mz[scheme] << [trim] [{endmarker}]
  30. {script}
  31. {endmarker}
  32. Execute inlined MzScheme script {script}.
  33. Note: This command doesn't work when the MzScheme
  34. feature wasn't compiled in. To avoid errors, see
  35. |script-here|.
  36. If [endmarker] is omitted from after the "<<", a dot
  37. '.' must be used after {script}, like for the
  38. |:append| and |:insert| commands. Refer to
  39. |:let-heredoc| for more information.
  40. *:mzfile* *:mzf*
  41. :[range]mzf[ile] {file} Execute the MzScheme script in {file}.
  42. All of these commands do essentially the same thing - they execute a piece of
  43. MzScheme code, with the "current range" set to the given line
  44. range.
  45. In the case of :mzscheme, the code to execute is in the command-line.
  46. In the case of :mzfile, the code to execute is the contents of the given file.
  47. MzScheme interface defines exception exn:vim, derived from exn.
  48. It is raised for various Vim errors.
  49. During compilation, the MzScheme interface will remember the current MzScheme
  50. collection path. If you want to specify additional paths use the
  51. 'current-library-collection-paths' parameter. E.g., to cons the user-local
  52. MzScheme collection path: >
  53. :mz << EOF
  54. (current-library-collection-paths
  55. (cons
  56. (build-path (find-system-path 'addon-dir) (version) "collects")
  57. (current-library-collection-paths)))
  58. EOF
  59. <
  60. All functionality is provided through module vimext.
  61. The exn:vim is available without explicit import.
  62. To avoid clashes with MzScheme, consider using prefix when requiring module,
  63. e.g.: >
  64. :mzscheme (require (prefix vim- vimext))
  65. <
  66. All the examples below assume this naming scheme.
  67. *mzscheme-sandbox*
  68. When executed in the |sandbox|, access to some filesystem and Vim interface
  69. procedures is restricted.
  70. ==============================================================================
  71. 2. Examples *mzscheme-examples*
  72. >
  73. :mzscheme (display "Hello")
  74. :mz (display (string-append "Using MzScheme version " (version)))
  75. :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
  76. :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
  77. :mzscheme (vim-set-buff-line 10 "This is line #10")
  78. To see what version of MzScheme you have: >
  79. :mzscheme (display (version))
  80. <
  81. Inline script usage: >
  82. function! <SID>SetFirstLine()
  83. :mz << EOF
  84. (display "!!!")
  85. (require (prefix vim- vimext))
  86. ; for newer versions (require (prefix-in vim- 'vimext))
  87. (vim-set-buff-line 1 "This is line #1")
  88. (vim-beep)
  89. EOF
  90. endfunction
  91. nmap <F9> :call <SID>SetFirstLine() <CR>
  92. <
  93. File execution: >
  94. :mzfile supascript.scm
  95. <
  96. Vim exception handling: >
  97. :mz << EOF
  98. (require (prefix vim- vimext))
  99. ; for newer versions (require (prefix-in vim- 'vimext))
  100. (with-handlers
  101. ([exn:vim? (lambda (e) (display (exn-message e)))])
  102. (vim-eval "nonsense-string"))
  103. EOF
  104. <
  105. Auto-instantiation of vimext module (can be placed in your |vimrc|): >
  106. function! MzRequire()
  107. :redir => l:mzversion
  108. :mz (version)
  109. :redir END
  110. if strpart(l:mzversion, 1, 1) < "4"
  111. " MzScheme versions < 4.x:
  112. :mz (require (prefix vim- vimext))
  113. else
  114. " newer versions:
  115. :mz (require (prefix-in vim- 'vimext))
  116. endif
  117. endfunction
  118. if has("mzscheme")
  119. silent call MzRequire()
  120. endif
  121. <
  122. ==============================================================================
  123. 3. Threads *mzscheme-threads*
  124. The MzScheme interface supports threads. They are independent from OS threads,
  125. thus scheduling is required. The option 'mzquantum' determines how often
  126. Vim should poll for available MzScheme threads.
  127. NOTE
  128. Thread scheduling in the console version of Vim is less reliable than in the
  129. GUI version.
  130. ==============================================================================
  131. 4. Vim access from MzScheme *mzscheme-vim*
  132. *mzscheme-vimext*
  133. The 'vimext' module provides access to procedures defined in the MzScheme
  134. interface.
  135. Common
  136. ------
  137. (command {command-string}) Perform the vim ":Ex" style command.
  138. (eval {expr-string}) Evaluate the vim expression into
  139. respective MzScheme object: |Lists| are
  140. represented as Scheme lists,
  141. |Dictionaries| as hash tables,
  142. |Funcref|s as functions (see also
  143. |mzscheme-funcref|)
  144. NOTE the name clashes with MzScheme eval,
  145. use module qualifiers to overcome this.
  146. (range-start) Start/End of the range passed with
  147. (range-end) the Scheme command.
  148. (beep) beep
  149. (get-option {option-name} [buffer-or-window]) Get Vim option value (either
  150. local or global, see set-option).
  151. (set-option {string} [buffer-or-window])
  152. Set a Vim option. String must have option
  153. setting form (like optname=optval, or
  154. optname+=optval, etc.) When called with
  155. {buffer} or {window} the local option will
  156. be set. The symbol 'global can be passed
  157. as {buffer-or-window}. Then |:setglobal|
  158. will be used.
  159. Buffers *mzscheme-buffer*
  160. -------
  161. (buff? {object}) Is object a buffer?
  162. (buff-valid? {object}) Is object a valid buffer? (i.e.
  163. corresponds to the real Vim buffer)
  164. (get-buff-line {linenr} [buffer])
  165. Get line from a buffer.
  166. (set-buff-line {linenr} {string} [buffer])
  167. Set a line in a buffer. If {string} is #f,
  168. the line gets deleted. The [buffer]
  169. argument is optional. If omitted, the
  170. current buffer will be used.
  171. (get-buff-line-list {start} {end} [buffer])
  172. Get a list of lines in a buffer. {Start}
  173. and {end} are 1-based and inclusive.
  174. (set-buff-line-list {start} {end} {string-list} [buffer])
  175. Set a list of lines in a buffer. If
  176. string-list is #f or null, the lines get
  177. deleted. If a list is shorter than
  178. {end}-{start} the remaining lines will
  179. be deleted.
  180. (get-buff-name [buffer]) Get a buffer's text name.
  181. (get-buff-num [buffer]) Get a buffer's number.
  182. (get-buff-size [buffer]) Get buffer line count.
  183. (insert-buff-line-list {linenr} {string/string-list} [buffer])
  184. Insert a list of lines into a buffer after
  185. {linenr}. If {linenr} is 0, lines will be
  186. inserted at start.
  187. (curr-buff) Get the current buffer. Use other MzScheme
  188. interface procedures to change it.
  189. (buff-count) Get count of total buffers in the editor.
  190. (get-next-buff [buffer]) Get next buffer.
  191. (get-prev-buff [buffer]) Get previous buffer. Return #f when there
  192. are no more buffers.
  193. (open-buff {filename}) Open a new buffer (for file "name")
  194. (get-buff-by-name {buffername}) Get a buffer by its filename or #f
  195. if there is no such buffer.
  196. (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
  197. there is no buffer with this number).
  198. Windows *mzscheme-window*
  199. ------
  200. (win? {object}) Is object a window?
  201. (win-valid? {object}) Is object a valid window (i.e. corresponds
  202. to the real Vim window)?
  203. (curr-win) Get the current window.
  204. (win-count) Get count of windows.
  205. (get-win-num [window]) Get window number.
  206. (get-win-by-num {windownum}) Get window by its number.
  207. (get-win-buffer [window]) Get the buffer for a given window.
  208. (get-win-height [window])
  209. (set-win-height {height} [window]) Get/Set height of window.
  210. (get-win-width [window])
  211. (set-win-width {width} [window])Get/Set width of window.
  212. (get-win-list [buffer]) Get list of windows for a buffer.
  213. (get-cursor [window]) Get cursor position in a window as
  214. a pair (linenr . column).
  215. (set-cursor (line . col) [window]) Set cursor position.
  216. ==============================================================================
  217. 5. mzeval() Vim function *mzscheme-mzeval*
  218. To facilitate bi-directional interface, you can use |mzeval()| function to
  219. evaluate MzScheme expressions and pass their values to Vim script.
  220. ==============================================================================
  221. 6. Using Function references *mzscheme-funcref*
  222. MzScheme interface allows use of |Funcref|s so you can call Vim functions
  223. directly from Scheme. For instance: >
  224. function! MyAdd2(arg)
  225. return a:arg + 2
  226. endfunction
  227. mz (define f2 (vim-eval "function(\"MyAdd2\")"))
  228. mz (f2 7)
  229. < or : >
  230. :mz (define indent (vim-eval "function('indent')"))
  231. " return Vim indent for line 12
  232. :mz (indent 12)
  233. <
  234. ==============================================================================
  235. 7. Dynamic loading *mzscheme-dynamic* *E815*
  236. On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
  237. output then includes |+mzscheme/dyn|.
  238. This means that Vim will search for the MzScheme DLL files only when needed.
  239. When you don't use the MzScheme interface you don't need them, thus you can
  240. use Vim without these DLL files.
  241. NOTE: Newer version of MzScheme (Racket) require earlier (trampolined)
  242. initialisation via scheme_main_setup. So Vim always loads the MzScheme DLL at
  243. startup if possible. This may make Vim startup slower.
  244. To use the MzScheme interface the MzScheme DLLs must be in your search path.
  245. In a console window type "path" to see what directories are used.
  246. On MS-Windows the options 'mzschemedll' and 'mzschemegcdll' are used for the
  247. name of the library to load. The initial value is specified at build time.
  248. The version of the DLL must match the MzScheme version Vim was compiled with.
  249. For MzScheme version 209 they will be "libmzsch209_000.dll" and
  250. "libmzgc209_000.dll". To know for sure look at the output of the ":version"
  251. command, look for -DDYNAMIC_MZSCH_DLL="something" and
  252. -DDYNAMIC_MZGC_DLL="something" in the "Compilation" info.
  253. For example, if MzScheme (Racket) is installed at C:\Racket63, you may need
  254. to set the environment variable as the following: >
  255. PATH=%PATH%;C:\Racket63\lib
  256. PLTCOLLECTS=C:\Racket63\collects
  257. PLTCONFIGDIR=C:\Racket63\etc
  258. <
  259. ==============================================================================
  260. 8. MzScheme setup *mzscheme-setup* *E895*
  261. Vim requires "racket/base" module for if_mzsch core (fallback to "scheme/base"
  262. if it doesn't exist), "r5rs" module for test and "raco ctool" command for
  263. building Vim. If MzScheme did not have them, you can install them with
  264. MzScheme's raco command:
  265. >
  266. raco pkg install scheme-lib # scheme/base module
  267. raco pkg install r5rs-lib # r5rs module
  268. raco pkg install cext-lib # raco ctool command
  269. <
  270. ======================================================================
  271. vim:tw=78:ts=8:noet:sts=4:ft=help:norl: