4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Mzscheme interface doesn't work on Ubuntu.
12 Solution: Change autoconf rules. Define missing macro. Some changes to
13 avoid gcc warnings. Remove per-buffer namespace. (Sergey Khorev)
14 Files: runtime/doc/if_mzsch.txt, src/Makefile, src/Make_ming.mak,
15 src/Make_mvc.mak, src/auto/configure, src/configure.in,
16 src/config.mk.in, src/eval.c, src/if_mzsch.c, src/if_mzsch.h,
17 src/main.c, src/proto/if_mzsch.pro
20 *** ../vim-7.2.190/runtime/doc/if_mzsch.txt 2008-08-09 19:36:48.000000000 +0200
21 --- runtime/doc/if_mzsch.txt 2009-05-26 18:49:53.000000000 +0200
24 ! *if_mzsch.txt* For Vim version 7.2. Last change: 2008 Jun 28
27 VIM REFERENCE MANUAL by Sergey Khorev
29 ! *if_mzsch.txt* For Vim version 7.2. Last change: 2009 May 26
32 VIM REFERENCE MANUAL by Sergey Khorev
37 :[range]mzf[ile] {file} Execute the MzScheme script in {file}. {not in Vi}
38 - All statements are executed in the namespace of the
39 - buffer that was current during :mzfile start.
40 - If you want to access other namespaces, use
43 All of these commands do essentially the same thing - they execute a piece of
44 MzScheme code, with the "current range" set to the given line
48 In the case of :mzscheme, the code to execute is in the command-line.
49 In the case of :mzfile, the code to execute is the contents of the given file.
51 - Each buffer has its own MzScheme namespace. Global namespace is bound to
52 - the "global-namespace" value from the 'vimext' module.
53 MzScheme interface defines exception exn:vim, derived from exn.
54 It is raised for various Vim errors.
60 :mzscheme (require (prefix vim- vimext))
62 ! All the examples below assume this naming scheme. Note that you need to do
63 ! this again for every buffer.
65 - The auto-instantiation can be achieved with autocommands, e.g. you can put
66 - something like this in your .vimrc (EOFs should not have indentation): >
67 - function s:MzRequire()
70 - (require (prefix vim- vimext))
71 - (let ((buf (vim-get-buff-by-name (vim-eval "expand(\"<afile>\")"))))
72 - (when (and buf (not (eq? buf (vim-curr-buff))))
73 - (parameterize ((current-namespace (vim-get-buff-namespace buf)))
74 - (namespace-attach-module vim-global-namespace 'vimext)
75 - (namespace-require '(prefix vim vimext)))))
80 - function s:MzStartup()
82 - au BufNew,BufNewFile,BufAdd,BufReadPre * :call s:MzRequire()
84 - (current-library-collection-paths
86 - (build-path (find-system-path 'addon-dir) (version) "collects")
87 - (current-library-collection-paths)))
95 - The global namespace just instantiated this module with the prefix "vimext:".
97 When executed in the |sandbox|, access to some filesystem and Vim interface
98 procedures is restricted.
101 :mzscheme (require (prefix vim- vimext))
103 ! All the examples below assume this naming scheme.
106 When executed in the |sandbox|, access to some filesystem and Vim interface
107 procedures is restricted.
110 2. Examples *mzscheme-examples*
112 :mzscheme (display "Hello")
113 :mzscheme (vim-set-buff-line 10 "This is line #10")
115 Inline script usage: >
116 function! <SID>SetFirstLine()
119 (vim-set-buff-line 1 "This is line #1")
124 nmap <F9> :call <SID>SetFirstLine() <CR>
126 2. Examples *mzscheme-examples*
128 :mzscheme (display "Hello")
129 + :mz (display (string-append "Using MzScheme version " (version)))
130 + :mzscheme (require (prefix vim- vimext)) ; for MzScheme < 4.x
131 + :mzscheme (require (prefix-in vim- 'vimext)) ; MzScheme 4.x
132 :mzscheme (vim-set-buff-line 10 "This is line #10")
134 Inline script usage: >
135 function! <SID>SetFirstLine()
138 + (require (prefix vim- vimext))
139 + ; for newer versions (require (prefix-in vim- 'vimext))
140 (vim-set-buff-line 1 "This is line #1")
145 nmap <F9> :call <SID>SetFirstLine() <CR>
149 :mzfile supascript.scm
151 ! Accessing the current buffer namespace from an MzScheme program running in
152 ! another buffer within |:mzfile|-executed script : >
153 ! ; Move to the window below
154 ! (vim-command "wincmd j")
155 ! ; execute in the context of buffer, to which window belongs
156 ! ; assume that buffer has 'textstring' defined
157 ! (parameterize ((current-namespace
158 ! (vim-get-buff-namespace (vim-curr-buff))))
159 ! (eval '(vim-set-buff-line 1 textstring)))
162 ==============================================================================
163 3. Threads *mzscheme-threads*
167 :mzfile supascript.scm
169 ! Vim exception handling: >
171 ! (require (prefix vim- vimext))
172 ! ; for newer versions (require (prefix-in vim- 'vimext))
174 ! ([exn:vim? (lambda (e) (display (exn-message e)))])
175 ! (vim-eval "nonsense-string"))
178 ! Auto-instantiation of vimext module (can be placed in your |vimrc|): >
179 ! function! MzRequire()
180 ! :redir => l:mzversion
183 ! if strpart(l:mzversion, 1, 1) < "4"
184 ! " MzScheme versions < 4.x:
185 ! :mz (require (prefix vim- vimext))
188 ! :mz (require (prefix-in vim- 'vimext))
193 + silent call MzRequire()
196 ==============================================================================
197 3. Threads *mzscheme-threads*
203 (command {command-string}) Perform the vim ":Ex" style command.
204 ! (eval {expr-string}) Evaluate the vim expression to a string.
205 ! A |List| is turned into a string by
206 ! joining the items and inserting line
208 ! NOTE clashes with MzScheme eval
209 (range-start) Start/End of the range passed with
210 (range-end) the Scheme command.
215 (command {command-string}) Perform the vim ":Ex" style command.
216 ! (eval {expr-string}) Evaluate the vim expression into
217 ! respective MzScheme object: |Lists| are
218 ! represented as Scheme lists,
219 ! |Dictionaries| as hash tables.
220 ! NOTE the name clashes with MzScheme eval
221 (range-start) Start/End of the range passed with
222 (range-end) the Scheme command.
226 be set. The symbol 'global can be passed
227 as {buffer-or-window}. Then |:setglobal|
229 - global-namespace The MzScheme main namespace.
231 Buffers *mzscheme-buffer*
236 if there is no such buffer.
237 (get-buff-by-num {buffernum}) Get a buffer by its number (return #f if
238 there is no buffer with this number).
239 - (get-buff-namespace [buffer]) Get buffer namespace.
241 Windows *mzscheme-window*
246 (set-cursor (line . col) [window]) Set cursor position.
248 ==============================================================================
249 ! 5. Dynamic loading *mzscheme-dynamic*
251 On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
252 output then includes |+mzscheme/dyn|.
254 (set-cursor (line . col) [window]) Set cursor position.
256 ==============================================================================
257 ! 5. Dynamic loading *mzscheme-dynamic* *E812*
259 On MS-Windows the MzScheme libraries can be loaded dynamically. The |:version|
260 output then includes |+mzscheme/dyn|.
261 *** ../vim-7.2.190/src/Makefile 2009-05-26 18:12:19.000000000 +0200
262 --- src/Makefile 2009-05-26 22:54:48.000000000 +0200
265 # Use this with GCC to check for mistakes, unused arguments, etc.
266 #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code
267 #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
268 ! #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code
270 # EFENCE - Electric-Fence malloc debugging: catches memory accesses beyond
271 # allocated memory (and makes every malloc()/free() very slow).
273 # Use this with GCC to check for mistakes, unused arguments, etc.
274 #CFLAGS = -g -Wall -Wextra -Wmissing-prototypes -Wunreachable-code
275 #PYTHON_CFLAGS_EXTRA = -Wno-missing-field-initializers
276 ! #MZSCHEME_CFLAGS_EXTRA = -Wno-unreachable-code -Wno-unused-parameter
278 # EFENCE - Electric-Fence malloc debugging: catches memory accesses beyond
279 # allocated memory (and makes every malloc()/free() very slow).
283 -rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c
284 -rm -f conftest* *~ auto/link.sed
286 + -rm -rf mzscheme_base.c
287 if test -d $(PODIR); then \
288 cd $(PODIR); $(MAKE) prefix=$(DESTDIR)$(prefix) clean; \
292 objects/if_xcmdsrv.o: if_xcmdsrv.c
293 $(CCC) -o $@ if_xcmdsrv.c
295 ! objects/if_mzsch.o: if_mzsch.c
296 $(CCC) -o $@ $(MZSCHEME_CFLAGS_EXTRA) if_mzsch.c
298 objects/if_perl.o: auto/if_perl.c
299 $(CCC) -o $@ auto/if_perl.c
301 objects/if_xcmdsrv.o: if_xcmdsrv.c
302 $(CCC) -o $@ if_xcmdsrv.c
304 ! objects/if_mzsch.o: if_mzsch.c $(MZSCHEME_EXTRA)
305 $(CCC) -o $@ $(MZSCHEME_CFLAGS_EXTRA) if_mzsch.c
308 + $(MZSCHEME_MZC) --c-mods mzscheme_base.c ++lib scheme/base
310 objects/if_perl.o: auto/if_perl.c
311 $(CCC) -o $@ auto/if_perl.c
312 *** ../vim-7.2.190/src/Make_ming.mak 2007-08-12 15:24:29.000000000 +0200
313 --- src/Make_ming.mak 2009-05-26 18:54:15.000000000 +0200
320 + ifndef MZSCHEME_PRECISE_GC
321 + MZSCHEME_PRECISE_GC=no
324 + # for version 4.x we need to generate byte-code for Scheme base
325 + ifndef MZSCHEME_GENERATE_BASE
326 + MZSCHEME_GENERATE_BASE=no
329 ifeq (no,$(DYNAMIC_MZSCHEME))
330 + ifeq (yes,$(MZSCHEME_PRECISE_GC))
331 + MZSCHEME_LIB=-lmzsch$(MZSCHEME_VER)
333 MZSCHEME_LIB = -lmzsch$(MZSCHEME_VER) -lmzgc$(MZSCHEME_VER)
335 # the modern MinGW can dynamically link to dlls directly.
336 # point MZSCHEME_DLLS to where you put libmzschXXXXXXX.dll and libgcXXXXXXX.dll
342 OBJ += $(OUTDIR)/if_mzsch.o
343 MZSCHEME_INCL = if_mzsch.h
344 + ifeq (yes,$(MZSCHEME_GENERATE_BASE))
345 + CFLAGS += -DINCLUDE_MZSCHEME_BASE
346 + MZ_EXTRA_DEP += mzscheme_base.c
348 + ifeq (yes,$(MZSCHEME_PRECISE_GC))
349 + CFLAGS += -DMZ_PRECISE_GC
353 OBJ += $(OUTDIR)/if_python.o
357 $(OUTDIR)/netbeans.o: netbeans.c $(INCL) $(NBDEBUG_INCL) $(NBDEBUG_SRC)
358 $(CC) -c $(CFLAGS) netbeans.c -o $(OUTDIR)/netbeans.o
360 + $(OUTDIR)/if_mzsch.o: if_mzsch.c $(INCL) if_mzsch.h $(MZ_EXTRA_DEP)
361 + $(CC) -c $(CFLAGS) if_mzsch.c -o $(OUTDIR)/if_mzsch.o
364 + $(MZSCHEME)/mzc --c-mods mzscheme_base.c ++lib scheme/base
367 ifneq (sh.exe, $(SHELL))
368 @echo creating pathdef.c
369 *** ../vim-7.2.190/src/Make_mvc.mak 2009-02-04 18:34:54.000000000 +0100
370 --- src/Make_mvc.mak 2009-05-26 18:54:51.000000000 +0200
374 # MZSCHEME=[Path to MzScheme directory]
375 # DYNAMIC_MZSCHEME=yes (to load the MzScheme DLLs dynamically)
376 # MZSCHEME_VER=[version, 205_000, ...]
377 + # MZSCHEME_DEBUG=no
380 # PERL=[Path to Perl directory]
384 MZSCHEME_VER = 205_000
386 CFLAGS = $(CFLAGS) -DFEAT_MZSCHEME -I $(MZSCHEME)\include
387 + !if EXIST("$(MZSCHEME)\collects\scheme\base.ss")
388 + # for MzScheme 4.x we need to include byte code for basic Scheme stuff
389 + MZSCHEME_EXTRA_DEP = mzscheme_base.c
390 + CFLAGS = $(CFLAGS) -DINCLUDE_MZSCHEME_BASE
392 + !if EXIST("$(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib") \
393 + && !EXIST("$(MZSCHEME)\lib\msvc\libmzgc$(MZSCHEME_VER).lib")
394 + !message Building with Precise GC
395 + MZSCHEME_PRECISE_GC = yes
396 + CFLAGS = $(CFLAGS) -DMZ_PRECISE_GC
398 !if "$(DYNAMIC_MZSCHEME)" == "yes"
399 + !if "$(MZSCHEME_PRECISE_GC)" == "yes"
400 + !error MzScheme with Precise GC cannot be loaded dynamically
402 !message MzScheme DLLs will be loaded dynamically
403 CFLAGS = $(CFLAGS) -DDYNAMIC_MZSCHEME \
404 -DDYNAMIC_MZSCH_DLL=\"libmzsch$(MZSCHEME_VER).dll\" \
405 -DDYNAMIC_MZGC_DLL=\"libmzgc$(MZSCHEME_VER).dll\"
407 + !if "$(MZSCHEME_DEBUG)" == "yes"
408 + CFLAGS = $(CFLAGS) -DMZSCHEME_FORCE_GC
410 + !if "$(MZSCHEME_PRECISE_GC)" == "yes"
411 + # Precise GC does not use separate dll
412 + MZSCHEME_LIB = $(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib
414 MZSCHEME_LIB = $(MZSCHEME)\lib\msvc\libmzgc$(MZSCHEME_VER).lib \
415 $(MZSCHEME)\lib\msvc\libmzsch$(MZSCHEME_VER).lib
418 MZSCHEME_OBJ = $(OUTDIR)\if_mzsch.obj
423 $(OUTDIR)/if_perlsfio.obj: $(OUTDIR) if_perlsfio.c $(INCL)
424 $(CC) $(CFLAGS) $(PERL_INC) if_perlsfio.c
426 ! $(OUTDIR)/if_mzsch.obj: $(OUTDIR) if_mzsch.c $(INCL)
427 $(CC) $(CFLAGS) if_mzsch.c \
428 -DMZSCHEME_COLLECTS=\"$(MZSCHEME:\=\\)\\collects\"
430 $(OUTDIR)/if_python.obj: $(OUTDIR) if_python.c $(INCL)
431 $(CC) $(CFLAGS) $(PYTHON_INC) if_python.c
433 $(OUTDIR)/if_perlsfio.obj: $(OUTDIR) if_perlsfio.c $(INCL)
434 $(CC) $(CFLAGS) $(PERL_INC) if_perlsfio.c
436 ! $(OUTDIR)/if_mzsch.obj: $(OUTDIR) if_mzsch.c $(INCL) $(MZSCHEME_EXTRA_DEP)
437 $(CC) $(CFLAGS) if_mzsch.c \
438 -DMZSCHEME_COLLECTS=\"$(MZSCHEME:\=\\)\\collects\"
440 + $(MZSCHEME)\mzc --c-mods mzscheme_base.c ++lib scheme/base
442 $(OUTDIR)/if_python.obj: $(OUTDIR) if_python.c $(INCL)
443 $(CC) $(CFLAGS) $(PYTHON_INC) if_python.c
444 *** ../vim-7.2.190/src/auto/configure 2009-05-21 23:25:38.000000000 +0200
445 --- src/auto/configure 2009-05-26 19:12:29.000000000 +0200
459 $as_echo "\"$PLTHOME\"" >&6; }
460 vi_cv_path_mzscheme_pfx="$PLTHOME"
462 ! { $as_echo "$as_me:$LINENO: result: \"not set\"" >&5
463 ! $as_echo "\"not set\"" >&6; }
464 # Extract the first word of "mzscheme", so it can be a program name with args.
465 set dummy mzscheme; ac_word=$2
466 { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
468 $as_echo "\"$PLTHOME\"" >&6; }
469 vi_cv_path_mzscheme_pfx="$PLTHOME"
471 ! { $as_echo "$as_me:$LINENO: result: not set" >&5
472 ! $as_echo "not set" >&6; }
473 # Extract the first word of "mzscheme", so it can be a program name with args.
474 set dummy mzscheme; ac_word=$2
475 { $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
478 if test "${vi_cv_path_mzscheme_pfx+set}" = set; then
479 $as_echo_n "(cached) " >&6
481 ! vi_cv_path_mzscheme_pfx=`
482 ! ${vi_cv_path_mzscheme} -evm \
483 ! "(display (simplify-path \
484 (build-path (call-with-values \
485 (lambda () (split-path (find-system-path (quote exec-file)))) \
486 ! (lambda (base name must-be-dir?) base)) (quote up))))"`
488 { $as_echo "$as_me:$LINENO: result: $vi_cv_path_mzscheme_pfx" >&5
489 $as_echo "$vi_cv_path_mzscheme_pfx" >&6; }
490 ! vi_cv_path_mzscheme_pfx=`echo "$vi_cv_path_mzscheme_pfx" | sed 's+/$++'`
495 if test "${vi_cv_path_mzscheme_pfx+set}" = set; then
496 $as_echo_n "(cached) " >&6
498 ! echo "(display (simplify-path \
499 (build-path (call-with-values \
500 (lambda () (split-path (find-system-path (quote exec-file)))) \
501 ! (lambda (base name must-be-dir?) base)) (quote up))))" > mzdirs.scm
502 ! vi_cv_path_mzscheme_pfx=`${vi_cv_path_mzscheme} -r mzdirs.scm | \
505 { $as_echo "$as_me:$LINENO: result: $vi_cv_path_mzscheme_pfx" >&5
506 $as_echo "$vi_cv_path_mzscheme_pfx" >&6; }
513 { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include" >&5
514 $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include... " >&6; }
515 if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
516 ! { $as_echo "$as_me:$LINENO: result: \"yes\"" >&5
517 ! $as_echo "\"yes\"" >&6; }
519 ! { $as_echo "$as_me:$LINENO: result: \"no\"" >&5
520 ! $as_echo "\"no\"" >&6; }
521 ! { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include" >&5
522 ! $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include... " >&6; }
523 if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
524 ! { $as_echo "$as_me:$LINENO: result: \"yes\"" >&5
525 ! $as_echo "\"yes\"" >&6; }
528 ! { $as_echo "$as_me:$LINENO: result: \"no\"" >&5
529 ! $as_echo "\"no\"" >&6; }
530 ! vi_cv_path_mzscheme_pfx=
535 { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include" >&5
536 $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include... " >&6; }
537 if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
538 ! SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include
539 ! { $as_echo "$as_me:$LINENO: result: yes" >&5
540 ! $as_echo "yes" >&6; }
542 ! { $as_echo "$as_me:$LINENO: result: no" >&5
543 ! $as_echo "no" >&6; }
544 ! { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt" >&5
545 ! $as_echo_n "checking if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt... " >&6; }
546 if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
547 ! { $as_echo "$as_me:$LINENO: result: yes" >&5
548 ! $as_echo "yes" >&6; }
549 ! SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include/plt
551 ! { $as_echo "$as_me:$LINENO: result: no" >&5
552 ! $as_echo "no" >&6; }
553 ! { $as_echo "$as_me:$LINENO: checking if scheme.h can be found in /usr/include/plt/" >&5
554 ! $as_echo_n "checking if scheme.h can be found in /usr/include/plt/... " >&6; }
555 ! if test -f /usr/include/plt/scheme.h; then
556 ! { $as_echo "$as_me:$LINENO: result: yes" >&5
557 ! $as_echo "yes" >&6; }
558 ! SCHEME_INC=/usr/include/plt
560 ! { $as_echo "$as_me:$LINENO: result: no" >&5
561 ! $as_echo "no" >&6; }
562 ! vi_cv_path_mzscheme_pfx=
569 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
570 if test "x$MACOSX" = "xyes"; then
571 MZSCHEME_LIBS="-framework PLT_MzScheme"
572 elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
573 MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
575 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
576 if test "$GCC" = yes; then
577 ! MZSCHEME_LIBS="$MZSCHEME_LIBS -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
578 elif test "`(uname) 2>/dev/null`" = SunOS &&
579 uname -r | grep '^5' >/dev/null; then
580 ! MZSCHEME_LIBS="$MZSCHEME_LIBS -R ${vi_cv_path_mzscheme_pfx}/lib"
583 if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
584 SCHEME_COLLECTS=lib/plt/
586 ! MZSCHEME_CFLAGS="-I${vi_cv_path_mzscheme_pfx}/include${SCHEME_INC} \
587 -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
588 MZSCHEME_SRC="if_mzsch.c"
589 MZSCHEME_OBJ="objects/if_mzsch.o"
591 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
592 if test "x$MACOSX" = "xyes"; then
593 MZSCHEME_LIBS="-framework PLT_MzScheme"
594 + elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
595 + MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
596 + MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
597 elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
598 MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
600 ! if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.so"; then
601 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme3m"
602 ! MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
604 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
606 if test "$GCC" = yes; then
607 ! MZSCHEME_LIBS="${MZSCHEME_LIBS} -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
608 elif test "`(uname) 2>/dev/null`" = SunOS &&
609 uname -r | grep '^5' >/dev/null; then
610 ! MZSCHEME_LIBS="${MZSCHEME_LIBS} -R ${vi_cv_path_mzscheme_pfx}/lib"
613 if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
614 SCHEME_COLLECTS=lib/plt/
616 ! if test -f "${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects/scheme/base.ss" ; then
617 ! MZSCHEME_EXTRA="mzscheme_base.c"
618 ! MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -DINCLUDE_MZSCHEME_BASE"
619 ! MZSCHEME_MZC="${vi_cv_path_mzscheme_pfx}/bin/mzc"
621 ! MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -I${SCHEME_INC} \
622 -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
623 MZSCHEME_SRC="if_mzsch.c"
624 MZSCHEME_OBJ="objects/if_mzsch.o"
636 *** ../vim-7.2.190/src/configure.in 2009-05-21 23:25:38.000000000 +0200
637 --- src/configure.in 2009-05-26 18:57:35.000000000 +0200
640 AC_MSG_RESULT("$PLTHOME")
641 vi_cv_path_mzscheme_pfx="$PLTHOME"
643 ! AC_MSG_RESULT("not set")
644 dnl -- try to find MzScheme executable
645 AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)
648 AC_MSG_RESULT("$PLTHOME")
649 vi_cv_path_mzscheme_pfx="$PLTHOME"
651 ! AC_MSG_RESULT(not set)
652 dnl -- try to find MzScheme executable
653 AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)
657 if test "X$vi_cv_path_mzscheme" != "X"; then
658 dnl -- find where MzScheme thinks it was installed
659 AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
660 ! [ vi_cv_path_mzscheme_pfx=`
661 ! ${vi_cv_path_mzscheme} -evm \
662 ! "(display (simplify-path \
663 (build-path (call-with-values \
664 (lambda () (split-path (find-system-path (quote exec-file)))) \
665 ! (lambda (base name must-be-dir?) base)) (quote up))))"` ])
666 ! dnl Remove a trailing slash.
667 ! vi_cv_path_mzscheme_pfx=`echo "$vi_cv_path_mzscheme_pfx" | sed 's+/$++'`
672 if test "X$vi_cv_path_mzscheme" != "X"; then
673 dnl -- find where MzScheme thinks it was installed
674 AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
675 ! dnl different versions of MzScheme differ in command line processing
676 ! dnl use universal approach
677 ! echo "(display (simplify-path \
678 (build-path (call-with-values \
679 (lambda () (split-path (find-system-path (quote exec-file)))) \
680 ! (lambda (base name must-be-dir?) base)) (quote up))))" > mzdirs.scm
681 ! dnl Remove a trailing slash
682 ! [ vi_cv_path_mzscheme_pfx=`${vi_cv_path_mzscheme} -r mzdirs.scm | \
683 ! sed -e 's+/$++'` ])
690 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
691 AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
692 if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
693 ! AC_MSG_RESULT("yes")
695 ! AC_MSG_RESULT("no")
696 ! AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/plt/include)
697 if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
698 ! AC_MSG_RESULT("yes")
701 ! AC_MSG_RESULT("no")
702 ! vi_cv_path_mzscheme_pfx=
707 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
708 AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
709 if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
710 ! SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include
714 ! AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt)
715 if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
717 ! SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include/plt
720 ! AC_MSG_CHECKING(if scheme.h can be found in /usr/include/plt/)
721 ! if test -f /usr/include/plt/scheme.h; then
723 ! SCHEME_INC=/usr/include/plt
726 ! vi_cv_path_mzscheme_pfx=
733 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
734 if test "x$MACOSX" = "xyes"; then
735 MZSCHEME_LIBS="-framework PLT_MzScheme"
736 elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
737 MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
739 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
740 if test "$GCC" = yes; then
741 dnl Make Vim remember the path to the library. For when it's not in
742 dnl $LD_LIBRARY_PATH.
743 ! MZSCHEME_LIBS="$MZSCHEME_LIBS -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
744 elif test "`(uname) 2>/dev/null`" = SunOS &&
745 uname -r | grep '^5' >/dev/null; then
746 ! MZSCHEME_LIBS="$MZSCHEME_LIBS -R ${vi_cv_path_mzscheme_pfx}/lib"
749 if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
750 SCHEME_COLLECTS=lib/plt/
752 ! MZSCHEME_CFLAGS="-I${vi_cv_path_mzscheme_pfx}/include${SCHEME_INC} \
753 -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
754 MZSCHEME_SRC="if_mzsch.c"
755 MZSCHEME_OBJ="objects/if_mzsch.o"
757 if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
758 if test "x$MACOSX" = "xyes"; then
759 MZSCHEME_LIBS="-framework PLT_MzScheme"
760 + elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
761 + MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
762 + MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
763 elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
764 MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
766 ! dnl Using shared objects
767 ! if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.so"; then
768 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme3m"
769 ! MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
771 ! MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
773 if test "$GCC" = yes; then
774 dnl Make Vim remember the path to the library. For when it's not in
775 dnl $LD_LIBRARY_PATH.
776 ! MZSCHEME_LIBS="${MZSCHEME_LIBS} -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
777 elif test "`(uname) 2>/dev/null`" = SunOS &&
778 uname -r | grep '^5' >/dev/null; then
779 ! MZSCHEME_LIBS="${MZSCHEME_LIBS} -R ${vi_cv_path_mzscheme_pfx}/lib"
782 if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
783 SCHEME_COLLECTS=lib/plt/
785 ! if test -f "${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects/scheme/base.ss" ; then
786 ! dnl need to generate bytecode for MzScheme base
787 ! MZSCHEME_EXTRA="mzscheme_base.c"
788 ! MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -DINCLUDE_MZSCHEME_BASE"
789 ! MZSCHEME_MZC="${vi_cv_path_mzscheme_pfx}/bin/mzc"
791 ! MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -I${SCHEME_INC} \
792 -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
793 MZSCHEME_SRC="if_mzsch.c"
794 MZSCHEME_OBJ="objects/if_mzsch.o"
798 AC_SUBST(MZSCHEME_PRO)
799 AC_SUBST(MZSCHEME_LIBS)
800 AC_SUBST(MZSCHEME_CFLAGS)
801 + AC_SUBST(MZSCHEME_EXTRA)
802 + AC_SUBST(MZSCHEME_MZC)
806 *** ../vim-7.2.190/src/config.mk.in 2008-06-25 00:49:03.000000000 +0200
807 --- src/config.mk.in 2009-05-26 18:57:49.000000000 +0200
811 MZSCHEME_OBJ = @MZSCHEME_OBJ@
812 MZSCHEME_CFLAGS = @MZSCHEME_CFLAGS@
813 MZSCHEME_PRO = @MZSCHEME_PRO@
814 + MZSCHEME_EXTRA = @MZSCHEME_EXTRA@
815 + MZSCHEME_MZC = @MZSCHEME_MZC@
817 PERL = @vi_cv_path_perl@
818 PERLLIB = @vi_cv_perllib@
819 *** ../vim-7.2.190/src/eval.c 2009-05-24 13:40:17.000000000 +0200
820 --- src/eval.c 2009-05-26 18:58:20.000000000 +0200
823 return item1 == NULL && item2 == NULL;
826 ! #if defined(FEAT_PYTHON) || defined(PROTO)
828 * Return the dictitem that an entry in a hashtable points to.
831 return item1 == NULL && item2 == NULL;
834 ! #if defined(FEAT_PYTHON) || defined(FEAT_MZSCHEME) || defined(PROTO)
836 * Return the dictitem that an entry in a hashtable points to.
838 *** ../vim-7.2.190/src/if_mzsch.c 2009-05-17 16:23:20.000000000 +0200
839 --- src/if_mzsch.c 2009-05-26 19:24:18.000000000 +0200
843 * Original work by Brent Fulgham <bfulgham@debian.org>
844 * (Based on lots of help from Matthew Flatt)
846 + * TODO Convert byte-strings to char strings?
848 * This consists of six parts:
849 * 1. MzScheme interpreter main program
850 * 2. Routines that handle the external interface between MzScheme and
853 * garbage collector will do it self
854 * 2. Requires at least NORMAL features. I can't imagine why one may want
855 * to build with SMALL or TINY features but with MzScheme interface.
856 ! * 3. I don't use K&R-style functions. Anyway, MzScheme headers are ANSI.
861 * garbage collector will do it self
862 * 2. Requires at least NORMAL features. I can't imagine why one may want
863 * to build with SMALL or TINY features but with MzScheme interface.
864 ! * 3. I don't use K&R-style functions. Anyways, MzScheme headers are ANSI.
871 #if defined(FEAT_MZSCHEME) || defined(PROTO)
873 /* Base data structures */
874 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
875 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
886 #if defined(FEAT_MZSCHEME) || defined(PROTO)
888 + #include <assert.h>
890 /* Base data structures */
891 #define SCHEME_VIMBUFFERP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_buffer_type)
892 #define SCHEME_VIMWINDOWP(obj) SAME_TYPE(SCHEME_TYPE(obj), mz_window_type)
922 - /* info for closed prim */
924 - * data have different means:
925 - * for do_eval it is char*
926 - * for do_apply is Apply_Onfo*
927 - * for do_load is Port_Info*
935 /* info for do_apply */
941 static Scheme_Object *insert_buffer_line_list(void *, int, Scheme_Object **);
942 static Scheme_Object *get_range_start(void *, int, Scheme_Object **);
943 static Scheme_Object *get_range_end(void *, int, Scheme_Object **);
944 - static Scheme_Object *get_buffer_namespace(void *, int, Scheme_Object **);
945 static vim_mz_buffer *get_vim_curr_buffer(void);
947 /* Window-related commands */
951 static int do_mzscheme_command(exarg_T *, void *, Scheme_Closed_Prim *what);
952 static void startup_mzscheme(void);
953 static char *string_to_line(Scheme_Object *obj);
954 - static int mzscheme_io_init(void);
955 - static void mzscheme_interface_init(vim_mz_buffer *self);
956 static void do_output(char *mesg, long len);
957 static void do_printf(char *format, ...);
958 static void do_flush(void);
962 static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
963 static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
964 static Scheme_Object *do_apply(void *, int noargc, Scheme_Object **noargv);
965 ! static void register_vim_exn(Scheme_Env *env);
966 static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
967 int argc, Scheme_Object **argv);
968 static vim_mz_window *get_window_arg(const char *fname, int argnum,
969 int argc, Scheme_Object **argv);
970 - static void add_vim_exn(Scheme_Env *env);
971 static int line_in_range(linenr_T, buf_T *);
972 static void check_line_range(linenr_T, buf_T *);
973 static void mz_fix_cursor(int lo, int hi, int extra);
975 ! static int eval_in_namespace(void *, Scheme_Closed_Prim *, Scheme_Env *,
976 ! Scheme_Object **ret);
977 ! static void make_modules(Scheme_Env *);
979 #ifdef DYNAMIC_MZSCHEME
982 static Scheme_Object *do_eval(void *, int noargc, Scheme_Object **noargv);
983 static Scheme_Object *do_load(void *, int noargc, Scheme_Object **noargv);
984 static Scheme_Object *do_apply(void *, int noargc, Scheme_Object **noargv);
985 ! static void register_vim_exn(void);
986 static vim_mz_buffer *get_buffer_arg(const char *fname, int argnum,
987 int argc, Scheme_Object **argv);
988 static vim_mz_window *get_window_arg(const char *fname, int argnum,
989 int argc, Scheme_Object **argv);
990 static int line_in_range(linenr_T, buf_T *);
991 static void check_line_range(linenr_T, buf_T *);
992 static void mz_fix_cursor(int lo, int hi, int extra);
994 ! static int eval_with_exn_handling(void *, Scheme_Closed_Prim *,
995 ! Scheme_Object **ret);
996 ! static void make_modules(void);
997 ! static void init_exn_catching_apply(void);
998 ! static int mzscheme_env_main(Scheme_Env *env, int argc, char **argv);
999 ! static int mzscheme_init(void);
1001 ! static Scheme_Object *vim_to_mzscheme(typval_T *vim_value, int depth,
1002 ! Scheme_Hash_Table *visited);
1005 ! #ifdef MZ_PRECISE_GC
1006 ! static int buffer_size_proc(void *obj)
1008 ! return gcBYTES_TO_WORDS(sizeof(vim_mz_buffer));
1010 ! static int buffer_mark_proc(void *obj)
1012 ! return buffer_size_proc(obj);
1014 ! static int buffer_fixup_proc(void *obj)
1016 ! return buffer_size_proc(obj);
1018 ! static int window_size_proc(void *obj)
1020 ! return gcBYTES_TO_WORDS(sizeof(vim_mz_window));
1022 ! static int window_mark_proc(void *obj)
1024 ! return window_size_proc(obj);
1026 ! static int window_fixup_proc(void *obj)
1028 ! return window_size_proc(obj);
1032 #ifdef DYNAMIC_MZSCHEME
1036 (Scheme_Closed_Prim *prim, void *data, const char *name, mzshort mina,
1038 static Scheme_Object *(*dll_scheme_make_integer_value)(long i);
1039 - static Scheme_Object *(*dll_scheme_make_namespace)(int argc,
1040 - Scheme_Object *argv[]);
1041 static Scheme_Object *(*dll_scheme_make_pair)(Scheme_Object *car,
1042 Scheme_Object *cdr);
1043 static Scheme_Object *(*dll_scheme_make_prim_w_arity)(Scheme_Prim *prim,
1048 static Scheme_Object *(*dll_scheme_char_string_to_path)
1051 + static Scheme_Hash_Table *(*dll_scheme_make_hash_table)(int type);
1052 + static void (*dll_scheme_hash_set)(Scheme_Hash_Table *table,
1053 + Scheme_Object *key, Scheme_Object *value);
1054 + static Scheme_Object *(*dll_scheme_hash_get)(Scheme_Hash_Table *table,
1055 + Scheme_Object *key);
1056 + static Scheme_Object *(*dll_scheme_make_double)(double d);
1057 + # ifdef INCLUDE_MZSCHEME_BASE
1058 + static Scheme_Object *(*dll_scheme_make_sized_byte_string)(char *chars,
1059 + long len, int copy);
1060 + static Scheme_Object *(*dll_scheme_namespace_require)(Scheme_Object *req);
1063 /* arrays are imported directly */
1064 # define scheme_eof dll_scheme_eof
1067 # define scheme_lookup_global dll_scheme_lookup_global
1068 # define scheme_make_closed_prim_w_arity dll_scheme_make_closed_prim_w_arity
1069 # define scheme_make_integer_value dll_scheme_make_integer_value
1070 - # define scheme_make_namespace dll_scheme_make_namespace
1071 # define scheme_make_pair dll_scheme_make_pair
1072 # define scheme_make_prim_w_arity dll_scheme_make_prim_w_arity
1073 # if MZSCHEME_VERSION_MAJOR < 299
1078 # define scheme_char_string_to_path \
1079 dll_scheme_char_string_to_path
1081 + # define scheme_make_hash_table dll_scheme_make_hash_table
1082 + # define scheme_hash_set dll_scheme_hash_set
1083 + # define scheme_hash_get dll_scheme_hash_get
1084 + # define scheme_make_double dll_scheme_make_double
1085 + # ifdef INCLUDE_MZSCHEME_BASE
1086 + # define scheme_make_sized_byte_string dll_scheme_make_sized_byte_string
1087 + # define scheme_namespace_require dll_scheme_namespace_require
1094 {"scheme_make_closed_prim_w_arity",
1095 (void **)&dll_scheme_make_closed_prim_w_arity},
1096 {"scheme_make_integer_value", (void **)&dll_scheme_make_integer_value},
1097 - {"scheme_make_namespace", (void **)&dll_scheme_make_namespace},
1098 {"scheme_make_pair", (void **)&dll_scheme_make_pair},
1099 {"scheme_make_prim_w_arity", (void **)&dll_scheme_make_prim_w_arity},
1100 # if MZSCHEME_VERSION_MAJOR < 299
1104 {"scheme_current_config", (void **)&dll_scheme_current_config},
1105 {"scheme_char_string_to_byte_string",
1106 (void **)&dll_scheme_char_string_to_byte_string},
1107 ! {"scheme_char_string_to_path",
1108 ! (void **)&dll_scheme_char_string_to_path},
1112 static HINSTANCE hMzGC = 0;
1114 {"scheme_current_config", (void **)&dll_scheme_current_config},
1115 {"scheme_char_string_to_byte_string",
1116 (void **)&dll_scheme_char_string_to_byte_string},
1117 ! {"scheme_char_string_to_path", (void **)&dll_scheme_char_string_to_path},
1119 + {"scheme_make_hash_table", (void **)&dll_scheme_make_hash_table},
1120 + {"scheme_hash_set", (void **)&dll_scheme_hash_set},
1121 + {"scheme_hash_get", (void **)&dll_scheme_hash_get},
1122 + {"scheme_make_double", (void **)&dll_scheme_make_double},
1123 + # ifdef INCLUDE_MZSCHEME_BASE
1124 + {"scheme_make_sized_byte_string", (void **)&dll_scheme_make_sized_byte_string},
1125 + {"scheme_namespace_require", (void **)&dll_scheme_namespace_require},
1129 static HINSTANCE hMzGC = 0;
1134 #endif /* DYNAMIC_MZSCHEME */
1136 + /* need to put it here for dynamic stuff to work */
1137 + #ifdef INCLUDE_MZSCHEME_BASE
1138 + # include "mzscheme_base.c"
1142 *========================================================================
1143 * 1. MzScheme interpreter startup
1146 static Scheme_Type mz_buffer_type;
1147 static Scheme_Type mz_window_type;
1149 ! static int initialized = 0;
1151 /* global environment */
1152 static Scheme_Env *environment = NULL;
1153 /* output/error handlers */
1154 static Scheme_Object *curout = NULL;
1155 static Scheme_Object *curerr = NULL;
1156 ! /* vim:exn exception */
1157 static Scheme_Object *exn_catching_apply = NULL;
1158 static Scheme_Object *exn_p = NULL;
1159 static Scheme_Object *exn_message = NULL;
1160 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
1161 ! /* values for exn:vim - constructor, predicate, accessors etc */
1162 ! static Scheme_Object *vim_exn_names = NULL;
1163 ! static Scheme_Object *vim_exn_values = NULL;
1165 static long range_start;
1166 static long range_end;
1168 static Scheme_Type mz_buffer_type;
1169 static Scheme_Type mz_window_type;
1171 ! static int initialized = FALSE;
1173 /* global environment */
1174 static Scheme_Env *environment = NULL;
1175 /* output/error handlers */
1176 static Scheme_Object *curout = NULL;
1177 static Scheme_Object *curerr = NULL;
1178 ! /* exn:vim exception */
1179 static Scheme_Object *exn_catching_apply = NULL;
1180 static Scheme_Object *exn_p = NULL;
1181 static Scheme_Object *exn_message = NULL;
1182 static Scheme_Object *vim_exn = NULL; /* Vim Error exception */
1184 ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
1185 ! static void *stack_base = NULL;
1188 static long range_start;
1189 static long range_end;
1192 timer_proc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
1193 # elif defined(FEAT_GUI_GTK)
1195 ! timer_proc(gpointer data UNUSED)
1196 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
1198 ! timer_proc(XtPointer timed_out UNUSED, XtIntervalId *interval_id UNUSED)
1199 # elif defined(FEAT_GUI_MAC)
1201 timer_proc(EventLoopTimerRef theTimer, void *userData)
1203 timer_proc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
1204 # elif defined(FEAT_GUI_GTK)
1206 ! timer_proc(gpointer data)
1207 # elif defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
1209 ! timer_proc(XtPointer timed_out, XtIntervalId *interval_id)
1210 # elif defined(FEAT_GUI_MAC)
1212 timer_proc(EventLoopTimerRef theTimer, void *userData)
1219 startup_mzscheme(void)
1221 ! Scheme_Object *proc_make_security_guard;
1223 ! scheme_set_stack_base(NULL, 1);
1225 MZ_REGISTER_STATIC(environment);
1226 MZ_REGISTER_STATIC(curout);
1232 + mzscheme_main(void)
1234 + #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR >= 400
1235 + /* use trampoline for precise GC in MzScheme >= 4.x */
1236 + scheme_main_setup(TRUE, mzscheme_env_main, 0, NULL);
1238 + mzscheme_env_main(NULL, 0, NULL);
1243 + mzscheme_env_main(Scheme_Env *env, int argc, char **argv)
1245 + /* neither argument nor return values are used */
1246 + #ifdef MZ_PRECISE_GC
1247 + # if MZSCHEME_VERSION_MAJOR < 400
1249 + * Starting from version 4.x, embedding applications must use
1250 + * scheme_main_setup/scheme_main_stack_setup trampolines
1251 + * rather than setting stack base directly with scheme_set_stack_base
1253 + Scheme_Object *dummy = NULL;
1254 + MZ_GC_DECL_REG(1);
1255 + MZ_GC_VAR_IN_REG(0, dummy);
1257 + stack_base = &__gc_var_stack__;
1259 + /* environment has been created by us by Scheme */
1260 + environment = env;
1263 + * In 4.x, all activities must be performed inside trampoline
1264 + * so we are forced to initialise GC immediately
1265 + * This can be postponed in 3.x but I see no point in implementing
1266 + * a feature which will work in older versions only.
1267 + * One would better use conservative GC if he needs dynamic MzScheme
1272 + stack_base = (void *)&dummy;
1274 + main_loop(FALSE, FALSE);
1275 + #if defined(MZ_PRECISE_GC) && MZSCHEME_VERSION_MAJOR < 400
1276 + /* releasing dummy */
1284 startup_mzscheme(void)
1286 ! #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
1287 ! scheme_set_stack_base(stack_base, 1);
1290 MZ_REGISTER_STATIC(environment);
1291 MZ_REGISTER_STATIC(curout);
1294 MZ_REGISTER_STATIC(exn_p);
1295 MZ_REGISTER_STATIC(exn_message);
1296 MZ_REGISTER_STATIC(vim_exn);
1297 - MZ_REGISTER_STATIC(vim_exn_names);
1298 - MZ_REGISTER_STATIC(vim_exn_values);
1300 environment = scheme_basic_env();
1302 /* redirect output */
1303 scheme_console_output = do_output;
1305 MZ_REGISTER_STATIC(exn_p);
1306 MZ_REGISTER_STATIC(exn_message);
1307 MZ_REGISTER_STATIC(vim_exn);
1309 + #if !defined(MZ_PRECISE_GC) || MZSCHEME_VERSION_MAJOR < 400
1310 + /* in newer versions of precise GC the initial env has been created */
1311 environment = scheme_basic_env();
1315 + #ifdef INCLUDE_MZSCHEME_BASE
1318 + * versions 4.x do not provide Scheme bindings by defaults
1319 + * we need to add them explicitly
1321 + Scheme_Object *scheme_base_symbol = NULL;
1322 + MZ_GC_DECL_REG(1);
1323 + MZ_GC_VAR_IN_REG(0, scheme_base_symbol);
1325 + /* invoke function from generated and included base.c */
1326 + declare_modules(environment);
1327 + scheme_base_symbol = scheme_intern_symbol("scheme/base");
1329 + scheme_namespace_require(scheme_base_symbol);
1334 + register_vim_exn();
1335 + /* use new environment to initialise exception handling */
1336 + init_exn_catching_apply();
1338 /* redirect output */
1339 scheme_console_output = do_output;
1343 #ifdef MZSCHEME_COLLECTS
1344 /* setup 'current-library-collection-paths' parameter */
1345 - scheme_set_param(scheme_config, MZCONFIG_COLLECTION_PATHS,
1347 # if MZSCHEME_VERSION_MAJOR >= 299
1348 ! scheme_char_string_to_path(
1349 ! scheme_byte_string_to_char_string(
1350 ! scheme_make_byte_string(MZSCHEME_COLLECTS))),
1352 ! scheme_make_string(MZSCHEME_COLLECTS),
1357 ! /* setup sandbox guards */
1358 ! proc_make_security_guard = scheme_lookup_global(
1359 ! scheme_intern_symbol("make-security-guard"),
1361 ! if (proc_make_security_guard != NULL)
1363 ! Scheme_Object *args[3];
1364 ! Scheme_Object *guard;
1365 ! args[0] = scheme_get_param(scheme_config, MZCONFIG_SECURITY_GUARD);
1366 ! args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
1367 ! "sandbox-file-guard", 3, 3);
1368 ! args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
1369 ! "sandbox-network-guard", 4, 4);
1370 ! guard = scheme_apply(proc_make_security_guard, 3, args);
1371 ! scheme_set_param(scheme_config, MZCONFIG_SECURITY_GUARD, guard);
1374 /* Create buffer and window types for use in Scheme code */
1375 mz_buffer_type = scheme_make_type("<vim-buffer>");
1376 mz_window_type = scheme_make_type("<vim-window>");
1378 ! register_vim_exn(environment);
1379 ! make_modules(environment);
1382 * setup callback to receive notifications
1383 * whether thread scheduling is (or not) required
1385 scheme_notify_multithread = notify_multithread;
1392 #ifdef MZSCHEME_COLLECTS
1393 /* setup 'current-library-collection-paths' parameter */
1394 # if MZSCHEME_VERSION_MAJOR >= 299
1396 ! Scheme_Object *coll_byte_string = NULL;
1397 ! Scheme_Object *coll_char_string = NULL;
1398 ! Scheme_Object *coll_path = NULL;
1399 ! Scheme_Object *coll_pair = NULL;
1400 ! Scheme_Config *config = NULL;
1402 ! MZ_GC_DECL_REG(5);
1403 ! MZ_GC_VAR_IN_REG(0, coll_byte_string);
1404 ! MZ_GC_VAR_IN_REG(1, coll_char_string);
1405 ! MZ_GC_VAR_IN_REG(2, coll_path);
1406 ! MZ_GC_VAR_IN_REG(3, coll_pair);
1407 ! MZ_GC_VAR_IN_REG(4, config);
1409 ! coll_byte_string = scheme_make_byte_string(MZSCHEME_COLLECTS);
1411 ! coll_char_string = scheme_byte_string_to_char_string(coll_byte_string);
1413 ! coll_path = scheme_char_string_to_path(coll_char_string);
1415 ! coll_pair = scheme_make_pair(coll_path, scheme_null);
1417 ! config = scheme_config;
1419 ! scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
1425 ! Scheme_Object *coll_string = NULL;
1426 ! Scheme_Object *coll_pair = NULL;
1427 ! Scheme_Config *config = NULL;
1429 ! MZ_GC_DECL_REG(3);
1430 ! MZ_GC_VAR_IN_REG(0, coll_string);
1431 ! MZ_GC_VAR_IN_REG(1, coll_pair);
1432 ! MZ_GC_VAR_IN_REG(2, config);
1434 ! coll_string = scheme_make_string(MZSCHEME_COLLECTS);
1436 ! coll_pair = scheme_make_pair(coll_string, scheme_null);
1438 ! config = scheme_config;
1440 ! scheme_set_param(config, MZCONFIG_COLLECTION_PATHS, coll_pair);
1448 ! Scheme_Object *make_security_guard = NULL;
1449 ! MZ_GC_DECL_REG(1);
1450 ! MZ_GC_VAR_IN_REG(0, make_security_guard);
1453 ! #if MZSCHEME_VERSION_MAJOR < 400
1455 ! Scheme_Object *make_security_guard_symbol = NULL;
1456 ! MZ_GC_DECL_REG(1);
1457 ! MZ_GC_VAR_IN_REG(0, make_security_guard_symbol);
1459 ! make_security_guard_symbol = scheme_intern_symbol("make-security-guard");
1461 ! make_security_guard = scheme_lookup_global(
1462 ! make_security_guard_symbol, environment);
1466 ! make_security_guard = scheme_builtin_value("make-security-guard");
1470 ! /* setup sandbox guards */
1471 ! if (make_security_guard != NULL)
1473 ! Scheme_Object *args[3] = {NULL, NULL, NULL};
1474 ! Scheme_Object *guard = NULL;
1475 ! Scheme_Config *config = NULL;
1476 ! MZ_GC_DECL_REG(5);
1477 ! MZ_GC_ARRAY_VAR_IN_REG(0, args, 3);
1478 ! MZ_GC_VAR_IN_REG(3, guard);
1479 ! MZ_GC_VAR_IN_REG(4, config);
1481 ! config = scheme_config;
1483 ! args[0] = scheme_get_param(config, MZCONFIG_SECURITY_GUARD);
1485 ! args[1] = scheme_make_prim_w_arity(sandbox_file_guard,
1486 ! "sandbox-file-guard", 3, 3);
1487 ! args[2] = scheme_make_prim_w_arity(sandbox_network_guard,
1488 ! "sandbox-network-guard", 4, 4);
1489 ! guard = scheme_apply(make_security_guard, 3, args);
1491 ! scheme_set_param(config, MZCONFIG_SECURITY_GUARD, guard);
1498 /* Create buffer and window types for use in Scheme code */
1499 mz_buffer_type = scheme_make_type("<vim-buffer>");
1501 mz_window_type = scheme_make_type("<vim-window>");
1503 + #ifdef MZ_PRECISE_GC
1504 + GC_register_traversers(mz_buffer_type,
1505 + buffer_size_proc, buffer_mark_proc, buffer_fixup_proc,
1507 + GC_register_traversers(mz_window_type,
1508 + window_size_proc, window_mark_proc, window_fixup_proc,
1515 * setup callback to receive notifications
1516 * whether thread scheduling is (or not) required
1518 scheme_notify_multithread = notify_multithread;
1527 - int do_require = FALSE;
1531 - do_require = TRUE;
1532 #ifdef DYNAMIC_MZSCHEME
1533 if (!mzscheme_enabled(TRUE))
1535 ! EMSG(_("???: Sorry, this command is disabled, the MzScheme library could not be loaded."));
1541 ! if (mzscheme_io_init())
1545 ! /* recreate ports each call effectivelly clearing these ones */
1546 ! curout = scheme_make_string_output_port();
1547 ! curerr = scheme_make_string_output_port();
1548 ! scheme_set_param(scheme_config, MZCONFIG_OUTPUT_PORT, curout);
1549 ! scheme_set_param(scheme_config, MZCONFIG_ERROR_PORT, curerr);
1553 ! /* auto-instantiate in basic env */
1554 ! eval_in_namespace("(require (prefix vimext: vimext))", do_eval,
1555 ! environment, NULL);
1562 - * This routine fills the namespace with various important routines that can
1563 - * be used within MzScheme.
1566 - mzscheme_interface_init(vim_mz_buffer *mzbuff)
1568 - Scheme_Object *attach;
1570 - mzbuff->env = (Scheme_Env *)scheme_make_namespace(0, NULL);
1573 - * attach instantiated modules from global namespace
1574 - * so they can be easily instantiated in the buffer namespace
1576 - attach = scheme_lookup_global(
1577 - scheme_intern_symbol("namespace-attach-module"),
1580 - if (attach != NULL)
1582 ! Scheme_Object *ret;
1583 ! Scheme_Object *args[2];
1585 ! args[0] = (Scheme_Object *)environment;
1586 ! args[1] = scheme_intern_symbol("vimext");
1588 ! ret = (Scheme_Object *)mzvim_apply(attach, 2, args);
1591 ! add_vim_exn(mzbuff->env);
1601 #ifdef DYNAMIC_MZSCHEME
1602 if (!mzscheme_enabled(TRUE))
1604 ! EMSG(_("E812: Sorry, this command is disabled, the MzScheme libraries could not be loaded."));
1609 ! initialized = TRUE;
1612 ! Scheme_Config *config = NULL;
1613 ! MZ_GC_DECL_REG(1);
1614 ! MZ_GC_VAR_IN_REG(0, config);
1616 ! config = scheme_config;
1618 ! /* recreate ports each call effectivelly clearing these ones */
1619 ! curout = scheme_make_string_output_port();
1621 ! curerr = scheme_make_string_output_port();
1623 ! scheme_set_param(config, MZCONFIG_OUTPUT_PORT, curout);
1625 ! scheme_set_param(config, MZCONFIG_ERROR_PORT, curerr);
1639 ! * Evaluate command in namespace with exception handling
1642 ! eval_in_namespace(void *data, Scheme_Closed_Prim *what, Scheme_Env *env,
1643 ! Scheme_Object **ret)
1645 ! Scheme_Object *value;
1646 ! Scheme_Object *exn;
1647 ! Cmd_Info info; /* closure info */
1652 ! scheme_set_param(scheme_config, MZCONFIG_ENV,
1653 ! (Scheme_Object *) env);
1655 ! * ensure all evaluations will be in current buffer namespace,
1656 ! * the second argument to scheme_eval_string isn't enough!
1658 ! value = _apply_thunk_catch_exceptions(
1659 ! scheme_make_closed_prim_w_arity(what, &info, "mzvim", 0, 0),
1668 ! * Evaluate command with exception handling
1671 ! eval_with_exn_handling(void *data, Scheme_Closed_Prim *what, Scheme_Object **ret)
1673 ! Scheme_Object *value = NULL;
1674 ! Scheme_Object *exn = NULL;
1675 ! Scheme_Object *prim = NULL;
1677 ! MZ_GC_DECL_REG(3);
1678 ! MZ_GC_VAR_IN_REG(0, value);
1679 ! MZ_GC_VAR_IN_REG(1, exn);
1680 ! MZ_GC_VAR_IN_REG(2, prim);
1683 ! prim = scheme_make_closed_prim_w_arity(what, data, "mzvim", 0, 0);
1685 ! value = _apply_thunk_catch_exceptions(prim, &exn);
1695 ! scheme_display(value, curerr); /* Send to stderr-vim */
1698 /* `raise' was called on some arbitrary value */
1705 ! scheme_display(value, curerr); /* Send to stderr-vim */
1710 /* `raise' was called on some arbitrary value */
1717 /* Print any result, as long as it's not a void */
1718 else if (!SCHEME_VOIDP(value))
1720 scheme_display(value, curout); /* Send to stdout-vim */
1731 range_start = eap->line1;
1732 range_end = eap->line2;
1734 ! return eval_in_namespace(data, what, get_vim_curr_buffer()->env, NULL);
1739 range_start = eap->line1;
1740 range_end = eap->line2;
1742 ! return eval_with_exn_handling(data, what, NULL);
1749 bp->buf = INVALID_BUFFER_VALUE;
1750 buf->b_mzscheme_ref = NULL;
1751 scheme_gc_ptr_ok(bp);
1759 wp->win = INVALID_WINDOW_VALUE;
1760 win->w_mzscheme_ref = NULL;
1761 scheme_gc_ptr_ok(wp);
1771 - /* eval MzScheme string */
1773 - mzvim_eval_string(char_u *str)
1775 - Scheme_Object *ret = NULL;
1776 - if (mzscheme_init())
1779 - eval_in_namespace(str, do_eval, get_vim_curr_buffer()->env, &ret);
1784 * apply MzScheme procedure with arguments,
1790 mzvim_apply(Scheme_Object *proc, int argc, Scheme_Object **argv)
1793 - Scheme_Object *ret = NULL;
1795 if (mzscheme_init())
1802 ! eval_in_namespace(&data, do_apply, get_vim_curr_buffer()->env, &ret);
1806 static Scheme_Object *
1807 do_load(void *data, int noargc, Scheme_Object **noargv)
1809 ! Cmd_Info *info = (Cmd_Info *)data;
1810 ! Scheme_Object *result = scheme_void;
1811 ! Scheme_Object *expr;
1812 ! char_u *file = scheme_malloc_fail_ok(
1813 ! scheme_malloc_atomic, MAXPATHL + 1);
1814 ! Port_Info *pinfo = (Port_Info *)(info->data);
1816 /* make Vim expansion */
1817 ! expand_env((char_u *)pinfo->name, file, MAXPATHL);
1818 ! /* scheme_load looks strange working with namespaces and error handling*/
1819 pinfo->port = scheme_open_input_file(file, "mzfile");
1820 ! scheme_count_lines(pinfo->port); /* to get accurate read error location*/
1822 /* Like REPL but print only last result */
1823 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
1824 ! result = scheme_eval(expr, info->env);
1826 /* errors will be caught in do_mzscheme_comamnd and ex_mzfile */
1827 scheme_close_input_port(pinfo->port);
1834 mzvim_apply(Scheme_Object *proc, int argc, Scheme_Object **argv)
1836 if (mzscheme_init())
1840 + Apply_Info data = {NULL, 0, NULL};
1841 + Scheme_Object *ret = NULL;
1843 ! MZ_GC_DECL_REG(5);
1844 ! MZ_GC_VAR_IN_REG(0, ret);
1845 ! MZ_GC_VAR_IN_REG(1, data.proc);
1846 ! MZ_GC_ARRAY_VAR_IN_REG(2, data.argv, argc);
1853 ! eval_with_exn_handling(&data, do_apply, &ret);
1859 static Scheme_Object *
1860 do_load(void *data, int noargc, Scheme_Object **noargv)
1862 ! Scheme_Object *expr = NULL;
1863 ! Scheme_Object *result = NULL;
1864 ! char *file = NULL;
1865 ! Port_Info *pinfo = (Port_Info *)data;
1867 ! MZ_GC_DECL_REG(3);
1868 ! MZ_GC_VAR_IN_REG(0, expr);
1869 ! MZ_GC_VAR_IN_REG(1, result);
1870 ! MZ_GC_VAR_IN_REG(2, file);
1873 ! file = (char *)scheme_malloc_fail_ok(scheme_malloc_atomic, MAXPATHL + 1);
1876 /* make Vim expansion */
1877 ! expand_env((char_u *)pinfo->name, (char_u *)file, MAXPATHL);
1878 pinfo->port = scheme_open_input_file(file, "mzfile");
1880 ! scheme_count_lines(pinfo->port); /* to get accurate read error location*/
1883 /* Like REPL but print only last result */
1884 while (!SCHEME_EOFP(expr = scheme_read(pinfo->port)))
1886 ! result = scheme_eval(expr, environment);
1890 /* errors will be caught in do_mzscheme_comamnd and ex_mzfile */
1891 scheme_close_input_port(pinfo->port);
1901 ex_mzfile(exarg_T *eap)
1905 pinfo.name = (char *)eap->arg;
1906 - pinfo.port = NULL;
1907 if (do_mzscheme_command(eap, &pinfo, do_load) != OK
1908 && pinfo.port != NULL) /* looks like port was not closed */
1909 scheme_close_input_port(pinfo.port);
1915 ex_mzfile(exarg_T *eap)
1917 ! Port_Info pinfo = {NULL, NULL};
1919 ! MZ_GC_DECL_REG(1);
1920 ! MZ_GC_VAR_IN_REG(0, pinfo.port);
1923 pinfo.name = (char *)eap->arg;
1924 if (do_mzscheme_command(eap, &pinfo, do_load) != OK
1925 && pinfo.port != NULL) /* looks like port was not closed */
1927 scheme_close_input_port(pinfo.port);
1936 "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
1937 "(cons #t (thunk))))";
1939 ! /* make sure we have a namespace with the standard syntax: */
1940 ! Scheme_Env *env = (Scheme_Env *)scheme_make_namespace(0, NULL);
1943 ! exn_catching_apply = scheme_eval_string(e, env);
1944 ! exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env);
1945 ! exn_message = scheme_lookup_global(
1946 ! scheme_intern_symbol("exn-message"), env);
1951 "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
1952 "(cons #t (thunk))))";
1954 ! exn_catching_apply = scheme_eval_string(e, environment);
1956 ! exn_p = scheme_builtin_value("exn?");
1958 ! exn_message = scheme_builtin_value("exn-message");
1968 - init_exn_catching_apply();
1970 v = _scheme_apply(exn_catching_apply, 1, &f);
1971 /* v is a pair: (cons #t value) or (cons #f exn) */
1976 static Scheme_Object *
1977 extract_exn_message(Scheme_Object *v)
1979 - init_exn_catching_apply();
1981 if (SCHEME_TRUEP(_scheme_apply(exn_p, 1, &v)))
1982 return _scheme_apply(exn_message, 1, &v);
1987 static Scheme_Object *
1988 do_eval(void *s, int noargc, Scheme_Object **noargv)
1990 ! Cmd_Info *info = (Cmd_Info *)s;
1992 ! return scheme_eval_string_all((char *)(info->data), info->env, TRUE);
1995 static Scheme_Object *
1996 do_apply(void *a, int noargc, Scheme_Object **noargv)
1998 ! Apply_Info *info = (Apply_Info *)(((Cmd_Info *)a)->data);
2000 return scheme_apply(info->proc, info->argc, info->argv);
2004 static Scheme_Object *
2005 do_eval(void *s, int noargc, Scheme_Object **noargv)
2007 ! return scheme_eval_string_all((char *)s, environment, TRUE);
2010 static Scheme_Object *
2011 do_apply(void *a, int noargc, Scheme_Object **noargv)
2013 ! Apply_Info *info = (Apply_Info *)a;
2014 return scheme_apply(info->proc, info->argc, info->argv);
2022 buff = scheme_get_sized_string_output(curerr, &length);
2026 do_err_output(buff, length);
2031 buff = scheme_get_sized_string_output(curout, &length);
2033 do_output(buff, length);
2037 - mzscheme_io_init(void)
2039 - /* Nothing needed so far... */
2044 *========================================================================
2045 * 4. Implementation of the Vim Features for MzScheme
2049 buff = scheme_get_sized_string_output(curout, &length);
2052 do_output(buff, length);
2056 *========================================================================
2057 * 4. Implementation of the Vim Features for MzScheme
2060 vim_eval(void *data, int argc, Scheme_Object **argv)
2063 ! Vim_Prim *prim = (Vim_Prim *)data;
2066 ! Scheme_Object *result;
2068 ! expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2070 ! str = (char *)eval_to_string((char_u *)expr, NULL, TRUE);
2073 raise_vim_exn(_("invalid expression"));
2075 ! result = scheme_make_string(str);
2081 raise_vim_exn(_("expressions disabled at compile time"));
2083 vim_eval(void *data, int argc, Scheme_Object **argv)
2086 ! Vim_Prim *prim = (Vim_Prim *)data;
2088 ! Scheme_Object *result;
2089 ! /* hash table to store visited values to avoid infinite loops */
2090 ! Scheme_Hash_Table *visited = NULL;
2091 ! typval_T *vim_result;
2093 ! MZ_GC_DECL_REG(1);
2094 ! MZ_GC_VAR_IN_REG(0, visited);
2097 ! visited = scheme_make_hash_table(SCHEME_hash_ptr);
2100 ! expr = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2101 ! vim_result = eval_expr((char_u *)expr, NULL);
2103 ! if (vim_result == NULL)
2104 raise_vim_exn(_("invalid expression"));
2106 ! result = vim_to_mzscheme(vim_result, 1, visited);
2107 ! free_tv(vim_result);
2112 raise_vim_exn(_("expressions disabled at compile time"));
2115 Vim_Prim *prim = (Vim_Prim *)data;
2120 Scheme_Object *rval;
2123 Vim_Prim *prim = (Vim_Prim *)data;
2128 Scheme_Object *rval;
2134 MZ_REGISTER_STATIC(M_global);
2135 M_global = scheme_intern_symbol("global");
2139 if (argv[1] == M_global)
2142 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
2145 ! rc = get_option_value(name, &value, &strval, opt_flags);
2150 scheme_wrong_type(prim->name, "vim-buffer/window", 1, argc, argv);
2153 ! rc = get_option_value(name, &value, (char_u **)&strval, opt_flags);
2160 return scheme_make_integer_value(value);
2162 rval = scheme_make_string(strval);
2171 MZ_REGISTER_STATIC(M_global);
2172 M_global = scheme_intern_symbol("global");
2176 if (argv[1] == M_global)
2181 for (w = firstwin; w != NULL; w = w->w_next)
2182 if (w->w_buffer == buf->buf)
2184 list = scheme_make_pair(window_new(w), list);
2192 static Scheme_Object *
2193 window_new(win_T *win)
2195 ! vim_mz_window *self;
2197 /* We need to handle deletion of windows underneath us.
2198 * If we add a "w_mzscheme_ref" field to the win_T structure,
2200 static Scheme_Object *
2201 window_new(win_T *win)
2203 ! vim_mz_window *self = NULL;
2205 ! MZ_GC_DECL_REG(1);
2206 ! MZ_GC_VAR_IN_REG(0, self);
2209 /* We need to handle deletion of windows underneath us.
2210 * If we add a "w_mzscheme_ref" field to the win_T structure,
2213 return win->w_mzscheme_ref;
2215 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
2217 vim_memset(self, 0, sizeof(vim_mz_window));
2218 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */
2219 win->w_mzscheme_ref = self;
2221 ! self->tag = mz_window_type;
2223 return (Scheme_Object *)(self);
2227 return win->w_mzscheme_ref;
2229 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_window));
2230 vim_memset(self, 0, sizeof(vim_mz_window));
2231 scheme_dont_gc_ptr(self); /* because win isn't visible to GC */
2233 win->w_mzscheme_ref = self;
2235 ! self->so.type = mz_window_type;
2238 return (Scheme_Object *)(self);
2244 *===========================================================================
2245 * 6. Vim Buffer-related Manipulation Functions
2246 - * Note that each buffer should have its own private namespace.
2247 *===========================================================================
2253 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
2255 Vim_Prim *prim = (Vim_Prim *)data;
2258 Scheme_Object *onum;
2263 ! fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2264 /* TODO make open existing file */
2265 num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
2268 mzscheme_open_buffer(void *data, int argc, Scheme_Object **argv)
2270 Vim_Prim *prim = (Vim_Prim *)data;
2273 Scheme_Object *onum;
2278 ! fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2279 /* TODO make open existing file */
2280 num = buflist_add(fname, BLN_LISTED | BLN_CURBUF);
2287 ! fname = SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2289 for (buf = firstbuf; buf; buf = buf->b_next)
2290 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
2295 ! fname = (char_u *)SCHEME_STR_VAL(GUARANTEE_STRING(prim->name, 0));
2297 for (buf = firstbuf; buf; buf = buf->b_next)
2298 if (buf->b_ffname == NULL || buf->b_sfname == NULL)
2301 Vim_Prim *prim = (Vim_Prim *)data;
2302 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
2304 ! return scheme_make_string(buf->buf->b_ffname);
2309 Vim_Prim *prim = (Vim_Prim *)data;
2310 vim_mz_buffer *buf = get_buffer_arg(prim->name, 0, argc, argv);
2312 ! return scheme_make_string((char *)buf->buf->b_ffname);
2318 static Scheme_Object *
2319 buffer_new(buf_T *buf)
2321 ! vim_mz_buffer *self;
2323 /* We need to handle deletion of buffers underneath us.
2324 * If we add a "b_mzscheme_ref" field to the buf_T structure,
2326 static Scheme_Object *
2327 buffer_new(buf_T *buf)
2329 ! vim_mz_buffer *self = NULL;
2331 ! MZ_GC_DECL_REG(1);
2332 ! MZ_GC_VAR_IN_REG(0, self);
2335 /* We need to handle deletion of buffers underneath us.
2336 * If we add a "b_mzscheme_ref" field to the buf_T structure,
2339 return buf->b_mzscheme_ref;
2341 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
2343 vim_memset(self, 0, sizeof(vim_mz_buffer));
2344 ! scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
2345 buf->b_mzscheme_ref = self;
2347 ! self->tag = mz_buffer_type;
2349 ! mzscheme_interface_init(self); /* Set up namespace */
2351 return (Scheme_Object *)(self);
2355 return buf->b_mzscheme_ref;
2357 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
2358 vim_memset(self, 0, sizeof(vim_mz_buffer));
2359 ! scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
2361 buf->b_mzscheme_ref = self;
2363 ! self->so.type = mz_buffer_type;
2366 return (Scheme_Object *)(self);
2371 Vim_Prim *prim = (Vim_Prim *)data;
2376 buf = get_buffer_arg(prim->name, 1, argc, argv);
2377 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
2378 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
2381 ! return scheme_make_string(line);
2386 Vim_Prim *prim = (Vim_Prim *)data;
2391 buf = get_buffer_arg(prim->name, 1, argc, argv);
2392 linenr = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
2393 line = ml_get_buf(buf->buf, (linenr_T)linenr, FALSE);
2396 ! return scheme_make_string((char *)line);
2402 Vim_Prim *prim = (Vim_Prim *)data;
2405 ! Scheme_Object *list;
2407 buf = get_buffer_arg(prim->name, 2, argc, argv);
2410 Vim_Prim *prim = (Vim_Prim *)data;
2413 ! Scheme_Object *list = NULL;
2415 ! MZ_GC_DECL_REG(1);
2416 ! MZ_GC_VAR_IN_REG(0, list);
2419 buf = get_buffer_arg(prim->name, 2, argc, argv);
2424 /* Set the list item */
2425 list = scheme_make_pair(str, list);
2433 /* Set the list item */
2434 list = scheme_make_pair(str, list);
2444 Vim_Prim *prim = (Vim_Prim *)data;
2446 ! Scheme_Object *line;
2456 Vim_Prim *prim = (Vim_Prim *)data;
2458 ! Scheme_Object *line = NULL;
2462 + MZ_GC_DECL_REG(1);
2463 + MZ_GC_VAR_IN_REG(0, line);
2472 if (SCHEME_FALSEP(line))
2477 if (u_savedel((linenr_T)n, 1L) == FAIL)
2480 if (SCHEME_FALSEP(line))
2482 ! buf_T *savebuf = curbuf;
2486 if (u_savedel((linenr_T)n, 1L) == FAIL)
2496 ! /* Otherwise it's a line */
2497 ! save = string_to_line(line);
2500 ! curbuf = buf->buf;
2502 - if (u_savesub((linenr_T)n) == FAIL)
2505 - raise_vim_exn(_("cannot save undo information"));
2507 - else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
2510 - raise_vim_exn(_("cannot replace line"));
2513 - changed_bytes((linenr_T)n, 0);
2518 ! return scheme_void;
2532 + /* Otherwise it's a line */
2533 + buf_T *savebuf = curbuf;
2535 ! save = string_to_line(line);
2537 ! curbuf = buf->buf;
2539 ! if (u_savesub((linenr_T)n) == FAIL)
2543 ! raise_vim_exn(_("cannot save undo information"));
2545 ! else if (ml_replace((linenr_T)n, (char_u *)save, TRUE) == FAIL)
2549 ! raise_vim_exn(_("cannot replace line"));
2554 ! changed_bytes((linenr_T)n, 0);
2559 ! /* Check that the cursor is not beyond the end of the line now. */
2560 ! if (buf->buf == curwin->w_buffer)
2561 ! check_cursor_col();
2565 ! return scheme_void;
2570 ! free_array(char **array)
2572 ! char **curr = array;
2573 ! while (*curr != NULL)
2574 ! vim_free(*curr++);
2581 * 3. Anything else - this is an error.
2583 Vim_Prim *prim = (Vim_Prim *)data;
2584 ! vim_mz_buffer *buf;
2585 ! Scheme_Object *line_list;
2586 ! Scheme_Object *line;
2587 ! Scheme_Object *rest;
2590 int i, old_len, new_len, hi, lo;
2597 * 3. Anything else - this is an error.
2599 Vim_Prim *prim = (Vim_Prim *)data;
2600 ! vim_mz_buffer *buf = NULL;
2601 ! Scheme_Object *line_list = NULL;
2602 int i, old_len, new_len, hi, lo;
2605 + MZ_GC_DECL_REG(1);
2606 + MZ_GC_VAR_IN_REG(0, line_list);
2615 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
2620 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
2623 if (SCHEME_FALSEP(line_list) || SCHEME_NULLP(line_list))
2625 ! buf_T *savebuf = curbuf;
2628 if (u_savedel((linenr_T)lo, (long)old_len) == FAIL)
2639 ! new_len = scheme_proper_list_length(line_list);
2640 ! if (new_len < 0) /* improper or cyclic list */
2641 ! scheme_wrong_type(prim->name, "proper list",
2644 ! /* Using MzScheme allocator, so we don't need to free this and
2645 ! * can safely keep pointers to GC collected strings
2647 ! array = (char **)scheme_malloc_fail_ok(scheme_malloc,
2648 ! (unsigned)(new_len * sizeof(char *)));
2651 ! for (i = 0; i < new_len; ++i)
2653 ! line = SCHEME_CAR(rest);
2654 ! rest = SCHEME_CDR(rest);
2655 ! if (!SCHEME_STRINGP(line))
2656 ! scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
2657 ! array[i] = string_to_line(line);
2661 ! curbuf = buf->buf;
2663 ! if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
2666 ! raise_vim_exn(_("cannot save undo information"));
2670 ! * If the size of the range is reducing (ie, new_len < old_len) we
2671 ! * need to delete some old_len. We do this at the start, by
2672 ! * repeatedly deleting line "lo".
2674 ! for (i = 0; i < old_len - new_len; ++i)
2676 ! if (ml_delete((linenr_T)lo, FALSE) == FAIL)
2679 ! raise_vim_exn(_("cannot delete line"));
2685 ! * For as long as possible, replace the existing old_len with the
2686 ! * new old_len. This is a more efficient operation, as it requires
2687 ! * less memory allocation and freeing.
2689 ! for (i = 0; i < old_len && i < new_len; i++)
2690 ! if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
2693 ! raise_vim_exn(_("cannot replace line"));
2697 ! * Now we may need to insert the remaining new_len. We don't need to
2698 ! * free the string passed back because MzScheme has control of that
2701 ! while (i < new_len)
2703 ! if (ml_append((linenr_T)(lo + i - 1),
2704 ! (char_u *)array[i], 0, FALSE) == FAIL)
2707 ! raise_vim_exn(_("cannot insert line"));
2714 ! * Adjust marks. Invalidate any which lie in the
2715 ! * changed range, and move any in the remainder of the buffer.
2717 ! mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
2718 ! changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
2720 ! if (buf->buf == curwin->w_buffer)
2721 ! mz_fix_cursor(lo, hi, extra);
2725 ! return scheme_void;
2739 + buf_T *savebuf = curbuf;
2742 ! new_len = scheme_proper_list_length(line_list);
2744 ! if (new_len < 0) /* improper or cyclic list */
2745 ! scheme_wrong_type(prim->name, "proper list",
2749 ! char **array = NULL;
2750 ! Scheme_Object *line = NULL;
2751 ! Scheme_Object *rest = NULL;
2753 ! MZ_GC_DECL_REG(2);
2754 ! MZ_GC_VAR_IN_REG(0, line);
2755 ! MZ_GC_VAR_IN_REG(1, rest);
2758 ! array = (char **)alloc(new_len * sizeof(char *));
2759 ! vim_memset(array, 0, new_len * sizeof(char *));
2762 ! for (i = 0; i < new_len; ++i)
2764 ! line = SCHEME_CAR(rest);
2765 ! rest = SCHEME_CDR(rest);
2766 ! if (!SCHEME_STRINGP(line))
2768 ! free_array(array);
2769 ! scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
2771 ! array[i] = string_to_line(line);
2774 ! curbuf = buf->buf;
2776 ! if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
2779 ! free_array(array);
2780 ! raise_vim_exn(_("cannot save undo information"));
2784 ! * If the size of the range is reducing (ie, new_len < old_len) we
2785 ! * need to delete some old_len. We do this at the start, by
2786 ! * repeatedly deleting line "lo".
2788 ! for (i = 0; i < old_len - new_len; ++i)
2790 ! if (ml_delete((linenr_T)lo, FALSE) == FAIL)
2793 ! free_array(array);
2794 ! raise_vim_exn(_("cannot delete line"));
2800 ! * For as long as possible, replace the existing old_len with the
2801 ! * new old_len. This is a more efficient operation, as it requires
2802 ! * less memory allocation and freeing.
2804 ! for (i = 0; i < old_len && i < new_len; i++)
2805 ! if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], TRUE) == FAIL)
2808 ! free_array(array);
2809 ! raise_vim_exn(_("cannot replace line"));
2813 ! * Now we may need to insert the remaining new_len. We don't need to
2814 ! * free the string passed back because MzScheme has control of that
2817 ! while (i < new_len)
2819 ! if (ml_append((linenr_T)(lo + i - 1),
2820 ! (char_u *)array[i], 0, FALSE) == FAIL)
2823 ! free_array(array);
2824 ! raise_vim_exn(_("cannot insert line"));
2830 ! free_array(array);
2834 ! * Adjust marks. Invalidate any which lie in the
2835 ! * changed range, and move any in the remainder of the buffer.
2837 ! mark_adjust((linenr_T)lo, (linenr_T)(hi - 1), (long)MAXLNUM, (long)extra);
2838 ! changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
2840 ! if (buf->buf == curwin->w_buffer)
2841 ! mz_fix_cursor(lo, hi, extra);
2846 ! return scheme_void;
2853 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
2855 Vim_Prim *prim = (Vim_Prim *)data;
2856 ! vim_mz_buffer *buf;
2857 ! Scheme_Object *list;
2858 ! Scheme_Object *line;
2859 ! Scheme_Object *rest;
2869 insert_buffer_line_list(void *data, int argc, Scheme_Object **argv)
2871 Vim_Prim *prim = (Vim_Prim *)data;
2872 ! vim_mz_buffer *buf = NULL;
2873 ! Scheme_Object *list = NULL;
2877 + MZ_GC_DECL_REG(1);
2878 + MZ_GC_VAR_IN_REG(0, list);
2886 check_line_range(n, buf->buf);
2887 if (SCHEME_STRINGP(list))
2889 ! str = string_to_line(list);
2894 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
2897 raise_vim_exn(_("cannot save undo information"));
2899 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
2902 raise_vim_exn(_("cannot insert line"));
2905 appended_lines_mark((linenr_T)n, 1L);
2908 update_screen(VALID);
2915 size = scheme_proper_list_length(list);
2916 if (size < 0) /* improper or cyclic list */
2917 scheme_wrong_type(prim->name, "proper list",
2920 ! /* Using MzScheme allocator, so we don't need to free this and
2921 ! * can safely keep pointers to GC collected strings
2923 ! array = (char **)scheme_malloc_fail_ok(
2924 ! scheme_malloc, (unsigned)(size * sizeof(char *)));
2927 ! for (i = 0; i < size; ++i)
2929 ! line = SCHEME_CAR(rest);
2930 ! rest = SCHEME_CDR(rest);
2931 ! array[i] = string_to_line(line);
2935 ! curbuf = buf->buf;
2937 ! if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
2940 ! raise_vim_exn(_("cannot save undo information"));
2944 for (i = 0; i < size; ++i)
2945 ! if (ml_append((linenr_T)(n + i), (char_u *)array[i],
2946 ! 0, FALSE) == FAIL)
2949 ! raise_vim_exn(_("cannot insert line"));
2953 ! appended_lines_mark((linenr_T)n, (long)i);
2957 ! update_screen(VALID);
2963 - /* (get-buff-namespace [buffer]) */
2964 - static Scheme_Object *
2965 - get_buffer_namespace(void *data, int argc, Scheme_Object **argv)
2967 - Vim_Prim *prim = (Vim_Prim *)data;
2969 - return (Scheme_Object *)get_buffer_arg(prim->name, 0, argc, argv)->env;
2976 check_line_range(n, buf->buf);
2977 if (SCHEME_STRINGP(list))
2979 ! buf_T *savebuf = curbuf;
2981 ! str = string_to_line(list);
2984 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
2988 raise_vim_exn(_("cannot save undo information"));
2990 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
2994 raise_vim_exn(_("cannot insert line"));
2999 appended_lines_mark((linenr_T)n, 1L);
3003 update_screen(VALID);
3011 size = scheme_proper_list_length(list);
3013 if (size < 0) /* improper or cyclic list */
3014 scheme_wrong_type(prim->name, "proper list",
3018 ! Scheme_Object *line = NULL;
3019 ! Scheme_Object *rest = NULL;
3021 ! buf_T *savebuf = curbuf;
3023 ! MZ_GC_DECL_REG(2);
3024 ! MZ_GC_VAR_IN_REG(0, line);
3025 ! MZ_GC_VAR_IN_REG(1, rest);
3028 ! array = (char **)alloc(size * sizeof(char *));
3029 ! vim_memset(array, 0, size * sizeof(char *));
3032 for (i = 0; i < size; ++i)
3034 ! line = SCHEME_CAR(rest);
3035 ! rest = SCHEME_CDR(rest);
3036 ! array[i] = string_to_line(line);
3039 ! curbuf = buf->buf;
3041 ! if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
3044 ! free_array(array);
3045 ! raise_vim_exn(_("cannot save undo information"));
3049 ! for (i = 0; i < size; ++i)
3050 ! if (ml_append((linenr_T)(n + i), (char_u *)array[i],
3051 ! 0, FALSE) == FAIL)
3054 ! free_array(array);
3055 ! raise_vim_exn(_("cannot insert line"));
3059 ! appended_lines_mark((linenr_T)n, (long)i);
3061 ! free_array(array);
3064 ! update_screen(VALID);
3078 * Convert an MzScheme string into a Vim line.
3080 ! * The result is in allocated memory. All internal nulls are replaced by
3081 ! * newline characters. It is an error for the string to contain newline
3086 string_to_line(Scheme_Object *obj)
3092 ! str = scheme_display_to_string(obj, &len);
3094 /* Error checking: String must not contain newlines, as we
3095 * are replacing a single line, and we must replace it with
3098 ! if (memchr(str, '\n', len))
3099 scheme_signal_error(_("string cannot contain newlines"));
3101 /* Create a copy of the string, with internal nulls replaced by
3102 * newline characters, as is the vim convention.
3104 for (i = 0; i < len; ++i)
3106 ! if (str[i] == '\0')
3116 * Check to see whether a Vim error has been reported, or a keyboard
3117 * interrupt (from vim --> got_int) has been detected.
3120 * Convert an MzScheme string into a Vim line.
3122 ! * All internal nulls are replaced by newline characters.
3123 ! * It is an error for the string to contain newline characters.
3125 + * Returns pointer to Vim allocated memory
3128 string_to_line(Scheme_Object *obj)
3130 ! char *scheme_str = NULL;
3131 ! char *vim_str = NULL;
3135 ! scheme_str = scheme_display_to_string(obj, &len);
3137 /* Error checking: String must not contain newlines, as we
3138 * are replacing a single line, and we must replace it with
3141 ! if (memchr(scheme_str, '\n', len))
3142 scheme_signal_error(_("string cannot contain newlines"));
3144 + vim_str = (char *)alloc(len + 1);
3146 /* Create a copy of the string, with internal nulls replaced by
3147 * newline characters, as is the vim convention.
3149 for (i = 0; i < len; ++i)
3151 ! if (scheme_str[i] == '\0')
3152 ! vim_str[i] = '\n';
3154 ! vim_str[i] = scheme_str[i];
3157 ! vim_str[i] = '\0';
3165 + * Convert Vim value into MzScheme, adopted from if_python.c
3167 + static Scheme_Object *
3168 + vim_to_mzscheme(typval_T *vim_value, int depth, Scheme_Hash_Table *visited)
3170 + Scheme_Object *result = NULL;
3171 + int new_value = TRUE;
3173 + MZ_GC_DECL_REG(1);
3174 + MZ_GC_VAR_IN_REG(0, result);
3177 + /* Avoid infinite recursion */
3181 + return scheme_void;
3184 + /* Check if we run into a recursive loop. The item must be in visited
3185 + * then and we can use it again.
3187 + result = scheme_hash_get(visited, (Scheme_Object *)vim_value);
3189 + if (result != NULL) /* found, do nothing */
3190 + new_value = FALSE;
3191 + else if (vim_value->v_type == VAR_STRING)
3193 + result = scheme_make_string((char *)vim_value->vval.v_string);
3196 + else if (vim_value->v_type == VAR_NUMBER)
3198 + result = scheme_make_integer((long)vim_value->vval.v_number);
3201 + # ifdef FEAT_FLOAT
3202 + else if (vim_value->v_type == VAR_FLOAT)
3204 + result = scheme_make_double((double)vim_value->vval.v_float);
3208 + else if (vim_value->v_type == VAR_LIST)
3210 + list_T *list = vim_value->vval.v_list;
3213 + if (list == NULL || list->lv_first == NULL)
3214 + result = scheme_null;
3217 + Scheme_Object *obj = NULL;
3219 + MZ_GC_DECL_REG(1);
3220 + MZ_GC_VAR_IN_REG(0, obj);
3223 + curr = list->lv_last;
3224 + obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
3225 + result = scheme_make_pair(obj, scheme_null);
3228 + while (curr != list->lv_first)
3230 + curr = curr->li_prev;
3231 + obj = vim_to_mzscheme(&curr->li_tv, depth + 1, visited);
3232 + result = scheme_make_pair(obj, result);
3238 + else if (vim_value->v_type == VAR_DICT)
3240 + Scheme_Object *key = NULL;
3241 + Scheme_Object *obj = NULL;
3243 + MZ_GC_DECL_REG(2);
3244 + MZ_GC_VAR_IN_REG(0, key);
3245 + MZ_GC_VAR_IN_REG(1, obj);
3248 + result = (Scheme_Object *)scheme_make_hash_table(SCHEME_hash_ptr);
3250 + if (vim_value->vval.v_dict != NULL)
3252 + hashtab_T *ht = &vim_value->vval.v_dict->dv_hashtab;
3253 + long_u todo = ht->ht_used;
3257 + for (hi = ht->ht_array; todo > 0; ++hi)
3259 + if (!HASHITEM_EMPTY(hi))
3263 + di = dict_lookup(hi);
3264 + obj = vim_to_mzscheme(&di->di_tv, depth + 1, visited);
3265 + key = scheme_make_string((char *)hi->hi_key);
3267 + scheme_hash_set((Scheme_Hash_Table *)result, key, obj);
3276 + result = scheme_void;
3277 + new_value = FALSE;
3281 + scheme_hash_set(visited, (Scheme_Object *)vim_value, result);
3290 * Check to see whether a Vim error has been reported, or a keyboard
3291 * interrupt (from vim --> got_int) has been detected.
3294 * register Scheme exn:vim
3297 ! register_vim_exn(Scheme_Env *env)
3299 ! Scheme_Object *exn_name = scheme_intern_symbol("exn:vim");
3301 if (vim_exn == NULL)
3302 vim_exn = scheme_make_struct_type(exn_name,
3303 ! scheme_builtin_value("struct:exn"), NULL, 0, 0, NULL, NULL
3304 #if MZSCHEME_VERSION_MAJOR >= 299
3309 - if (vim_exn_values == NULL)
3313 ! Scheme_Object **exn_names = scheme_make_struct_names(
3314 ! exn_name, scheme_null, 0, &nc);
3315 ! Scheme_Object **exn_values = scheme_make_struct_values(
3316 ! vim_exn, exn_names, nc, 0);
3318 ! vim_exn_names = scheme_make_vector(nc, scheme_false);
3319 ! vim_exn_values = scheme_make_vector(nc, scheme_false);
3320 ! /* remember names and values */
3321 ! mch_memmove(SCHEME_VEC_ELS(vim_exn_names), exn_names,
3322 ! nc * sizeof(Scheme_Object *));
3323 ! mch_memmove(SCHEME_VEC_ELS(vim_exn_values), exn_values,
3324 ! nc * sizeof(Scheme_Object *));
3331 ! * Add stuff of exn:vim to env
3334 ! add_vim_exn(Scheme_Env *env)
3338 ! for (i = 0; i < SCHEME_VEC_SIZE(vim_exn_values); i++)
3339 ! scheme_add_global_symbol(SCHEME_VEC_ELS(vim_exn_names)[i],
3340 ! SCHEME_VEC_ELS(vim_exn_values)[i], env);
3345 * register Scheme exn:vim
3348 ! register_vim_exn(void)
3352 ! Scheme_Object *struct_exn = NULL;
3353 ! Scheme_Object *exn_name = NULL;
3355 ! MZ_GC_DECL_REG(2);
3356 ! MZ_GC_VAR_IN_REG(0, struct_exn);
3357 ! MZ_GC_VAR_IN_REG(1, exn_name);
3360 ! exn_name = scheme_intern_symbol("exn:vim");
3362 ! struct_exn = scheme_builtin_value("struct:exn");
3365 if (vim_exn == NULL)
3366 vim_exn = scheme_make_struct_type(exn_name,
3367 ! struct_exn, NULL, 0, 0, NULL, NULL
3368 #if MZSCHEME_VERSION_MAJOR >= 299
3375 ! Scheme_Object **tmp = NULL;
3376 ! Scheme_Object *exn_names[5] = {NULL, NULL, NULL, NULL, NULL};
3377 ! Scheme_Object *exn_values[5] = {NULL, NULL, NULL, NULL, NULL};
3378 ! MZ_GC_DECL_REG(6);
3379 ! MZ_GC_ARRAY_VAR_IN_REG(0, exn_names, 5);
3380 ! MZ_GC_ARRAY_VAR_IN_REG(3, exn_values, 5);
3383 ! tmp = scheme_make_struct_names(exn_name, scheme_null, 0, &nc);
3385 ! mch_memmove(exn_names, tmp, nc * sizeof(Scheme_Object *));
3388 ! tmp = scheme_make_struct_values(vim_exn, exn_names, nc, 0);
3389 ! mch_memmove(exn_values, tmp, nc * sizeof(Scheme_Object *));
3392 ! for (i = 0; i < nc; i++)
3394 ! scheme_add_global_symbol(exn_names[i],
3395 ! exn_values[i], environment);
3407 raise_vim_exn(const char *add_info)
3409 ! Scheme_Object *argv[2];
3410 ! char_u *fmt = _("Vim error: ~a");
3412 if (add_info != NULL)
3414 ! Scheme_Object *info = scheme_make_string(add_info);
3415 ! argv[0] = scheme_byte_string_to_char_string(scheme_make_string(
3416 ! scheme_format(fmt, strlen(fmt), 1, &info, NULL)));
3417 SCHEME_SET_IMMUTABLE(argv[0]);
3420 argv[0] = scheme_make_string(_("Vim error"));
3422 #if MZSCHEME_VERSION_MAJOR < 360
3423 argv[1] = scheme_current_continuation_marks();
3425 argv[1] = scheme_current_continuation_marks(NULL);
3428 ! scheme_raise(scheme_make_struct_instance(vim_exn, 2, argv));
3434 raise_vim_exn(const char *add_info)
3436 ! char *fmt = _("Vim error: ~a");
3437 ! Scheme_Object *argv[2] = {NULL, NULL};
3438 ! Scheme_Object *exn = NULL;
3440 ! MZ_GC_DECL_REG(4);
3441 ! MZ_GC_ARRAY_VAR_IN_REG(0, argv, 2);
3442 ! MZ_GC_VAR_IN_REG(3, exn);
3445 if (add_info != NULL)
3447 ! char *c_string = NULL;
3448 ! Scheme_Object *byte_string = NULL;
3449 ! Scheme_Object *info = NULL;
3451 ! MZ_GC_DECL_REG(3);
3452 ! MZ_GC_VAR_IN_REG(0, c_string);
3453 ! MZ_GC_VAR_IN_REG(1, byte_string);
3454 ! MZ_GC_VAR_IN_REG(2, info);
3457 ! info = scheme_make_string(add_info);
3459 ! c_string = scheme_format(fmt, STRLEN(fmt), 1, &info, NULL);
3461 ! byte_string = scheme_make_string(c_string);
3463 ! argv[0] = scheme_byte_string_to_char_string(byte_string);
3465 SCHEME_SET_IMMUTABLE(argv[0]);
3469 argv[0] = scheme_make_string(_("Vim error"));
3472 #if MZSCHEME_VERSION_MAJOR < 360
3473 argv[1] = scheme_current_continuation_marks();
3476 argv[1] = scheme_current_continuation_marks(NULL);
3480 ! exn = scheme_make_struct_instance(vim_exn, 2, argv);
3482 ! scheme_raise(exn);
3490 curwin->w_cursor.lnum = lo;
3494 + check_cursor_col();
3495 changed_cline_bef_curs();
3497 invalidate_botline();
3500 {mzscheme_open_buffer, "open-buff", 1, 1},
3501 {get_buffer_by_name, "get-buff-by-name", 1, 1},
3502 {get_buffer_by_num, "get-buff-by-num", 1, 1},
3503 - {get_buffer_namespace, "get-buff-namespace", 0, 1},
3505 * Window-related commands
3513 ! make_modules(Scheme_Env *env)
3518 ! mod = scheme_primitive_module(scheme_intern_symbol("vimext"), env);
3519 /* all prims made closed so they can access their own names */
3520 ! for (i = 0; i < sizeof(prims)/sizeof(prims[0]); i++)
3522 Vim_Prim *prim = prims + i;
3523 ! scheme_add_global(prim->name,
3524 ! scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
3525 ! prim->mina, prim->maxa),
3528 - scheme_add_global("global-namespace", (Scheme_Object *)environment, mod);
3529 scheme_finish_primitive_module(mod);
3540 ! Scheme_Env *mod = NULL;
3541 ! Scheme_Object *vimext_symbol = NULL;
3542 ! Scheme_Object *closed_prim = NULL;
3544 ! MZ_GC_DECL_REG(3);
3545 ! MZ_GC_VAR_IN_REG(0, mod);
3546 ! MZ_GC_VAR_IN_REG(1, vimext_symbol);
3547 ! MZ_GC_VAR_IN_REG(2, closed_prim);
3550 ! vimext_symbol = scheme_intern_symbol("vimext");
3552 ! mod = scheme_primitive_module(vimext_symbol, environment);
3554 /* all prims made closed so they can access their own names */
3555 ! for (i = 0; i < (int)(sizeof(prims)/sizeof(prims[0])); i++)
3557 Vim_Prim *prim = prims + i;
3558 ! closed_prim = scheme_make_closed_prim_w_arity(prim->prim, prim, prim->name,
3559 ! prim->mina, prim->maxa);
3560 ! scheme_add_global(prim->name, closed_prim, mod);
3563 scheme_finish_primitive_module(mod);
3573 MZ_REGISTER_STATIC(M_write);
3574 M_write = scheme_intern_symbol("write");
3579 MZ_REGISTER_STATIC(M_read);
3580 M_read = scheme_intern_symbol("read");
3583 if (M_execute == NULL)
3585 MZ_REGISTER_STATIC(M_execute);
3586 M_execute = scheme_intern_symbol("execute");
3589 if (M_delete == NULL)
3591 MZ_REGISTER_STATIC(M_delete);
3592 M_delete = scheme_intern_symbol("delete");
3596 while (!SCHEME_NULLP(requested_access))
3597 *** ../vim-7.2.190/src/if_mzsch.h 2006-03-24 23:43:11.000000000 +0100
3598 --- src/if_mzsch.h 2009-05-26 19:08:21.000000000 +0200
3603 /* #ifdef needed for "make depend" */
3604 #ifdef FEAT_MZSCHEME
3605 + # include <schvers.h>
3606 # include <scheme.h>
3612 # define scheme_byte_string_to_char_string(obj) (obj)
3615 + /* Precise GC macros */
3616 + #ifndef MZ_GC_DECL_REG
3617 + # define MZ_GC_DECL_REG(size) /* empty */
3619 + #ifndef MZ_GC_VAR_IN_REG
3620 + # define MZ_GC_VAR_IN_REG(x, v) /* empty */
3622 + #ifndef MZ_GC_ARRAY_VAR_IN_REG
3623 + # define MZ_GC_ARRAY_VAR_IN_REG(x, v, l) /* empty */
3626 + # define MZ_GC_REG() /* empty */
3628 + #ifndef MZ_GC_UNREG
3629 + # define MZ_GC_UNREG() /* empty */
3632 + #ifdef MZSCHEME_FORCE_GC
3634 + * force garbage collection to check all references are registered
3635 + * seg faults will indicate not registered refs
3637 + # define MZ_GC_CHECK() scheme_collect_garbage();
3639 + # define MZ_GC_CHECK() /* empty */
3642 #endif /* _IF_MZSCH_H_ */
3643 *** ../vim-7.2.190/src/main.c 2009-05-17 13:30:58.000000000 +0200
3644 --- src/main.c 2009-05-26 19:09:01.000000000 +0200
3650 * Call the main command loop. This never returns.
3651 + * For embedded MzScheme the main_loop will be called by Scheme
3652 + * for proper stack tracking
3654 + #ifndef FEAT_MZSCHEME
3655 main_loop(FALSE, FALSE);
3662 *** ../vim-7.2.190/src/proto/if_mzsch.pro 2004-07-12 17:51:52.000000000 +0200
3663 --- src/proto/if_mzsch.pro 2009-05-26 19:09:55.000000000 +0200
3666 void *mzvim_eval_string __ARGS((char_u *str));
3667 struct Scheme_Object *mzvim_apply __ARGS((struct Scheme_Object *, int argc,
3668 struct Scheme_Object **));
3669 ! int mzthreads_allowed (void);
3670 ! #ifdef FEAT_GUI_KDE
3671 ! void timer_proc (void);
3672 ! void mzscheme_kde_start_timer (void);
3673 ! void mzscheme_kde_stop_timer (void);
3675 /* vim: set ft=c : */
3677 void *mzvim_eval_string __ARGS((char_u *str));
3678 struct Scheme_Object *mzvim_apply __ARGS((struct Scheme_Object *, int argc,
3679 struct Scheme_Object **));
3680 ! int mzthreads_allowed __ARGS((void));
3681 ! void mzscheme_main __ARGS((void));
3682 /* vim: set ft=c : */
3683 *** ../vim-7.2.190/src/version.c 2009-05-26 18:12:13.000000000 +0200
3684 --- src/version.c 2009-05-26 22:52:53.000000000 +0200
3688 { /* Add new patch number below this line */
3694 Scientists decoded the first message from an alien civilization:
3695 SIMPLY SEND 6 TIMES 10 TO THE 50 ATOMS OF HYDROGEN TO THE STAR
3696 SYSTEM AT THE TOP OF THE LIST, CROSS OFF THAT STAR SYSTEM, THEN PUT
3697 YOUR STAR SYSTEM AT THE BOTTOM OF THE LIST AND SEND IT TO 100 OTHER
3698 STAR SYSTEMS. WITHIN ONE TENTH GALACTIC ROTATION YOU WILL RECEIVE
3699 ENOUGH HYDROGREN TO POWER YOUR CIVILIZATION UNTIL ENTROPY REACHES ITS
3700 MAXIMUM! IT REALLY WORKS!
3702 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
3703 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3704 \\\ download, build and distribute -- http://www.A-A-P.org ///
3705 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///