comparison src/if_mzsch.c @ 856:8cd729851562 v7.0g

updated for version 7.0g
author vimboss
date Sun, 30 Apr 2006 18:54:39 +0000
parents d8f905020502
children 96cd8222a819
comparison
equal deleted inserted replaced
855:d2a4f08396fe 856:8cd729851562
821 { 821 {
822 EMSG(_("???: Sorry, this command is disabled, the MzScheme library could not be loaded.")); 822 EMSG(_("???: Sorry, this command is disabled, the MzScheme library could not be loaded."));
823 return -1; 823 return -1;
824 } 824 }
825 #endif 825 #endif
826 startup_mzscheme(); 826 startup_mzscheme();
827 827
828 if (mzscheme_io_init()) 828 if (mzscheme_io_init())
829 return -1; 829 return -1;
830 830
831 } 831 }
909 &exn); 909 &exn);
910 910
911 if (!value) 911 if (!value)
912 { 912 {
913 value = extract_exn_message(exn); 913 value = extract_exn_message(exn);
914 /* Got an exn? */ 914 /* Got an exn? */
915 if (value) 915 if (value)
916 { 916 {
917 scheme_display(value, curerr); /* Send to stderr-vim */ 917 scheme_display(value, curerr); /* Send to stderr-vim */
918 do_flush(); 918 do_flush();
919 } 919 }
950 void 950 void
951 mzscheme_buffer_free(buf_T *buf) 951 mzscheme_buffer_free(buf_T *buf)
952 { 952 {
953 if (buf->b_mzscheme_ref) 953 if (buf->b_mzscheme_ref)
954 { 954 {
955 vim_mz_buffer *bp; 955 vim_mz_buffer *bp;
956
956 bp = buf->b_mzscheme_ref; 957 bp = buf->b_mzscheme_ref;
957 bp->buf = INVALID_BUFFER_VALUE; 958 bp->buf = INVALID_BUFFER_VALUE;
958 buf->b_mzscheme_ref = NULL; 959 buf->b_mzscheme_ref = NULL;
959 scheme_gc_ptr_ok(bp); 960 scheme_gc_ptr_ok(bp);
960 } 961 }
1081 { 1082 {
1082 if (!exn_catching_apply) 1083 if (!exn_catching_apply)
1083 { 1084 {
1084 char *e = 1085 char *e =
1085 "(lambda (thunk) " 1086 "(lambda (thunk) "
1086 "(with-handlers ([void (lambda (exn) (cons #f exn))]) " 1087 "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
1087 "(cons #t (thunk))))"; 1088 "(cons #t (thunk))))";
1088 1089
1089 /* make sure we have a namespace with the standard syntax: */ 1090 /* make sure we have a namespace with the standard syntax: */
1090 Scheme_Env *env = (Scheme_Env *)scheme_make_namespace(0, NULL); 1091 Scheme_Env *env = (Scheme_Env *)scheme_make_namespace(0, NULL);
1091 add_vim_exn(env); 1092 add_vim_exn(env);
1092 1093
1093 exn_catching_apply = scheme_eval_string(e, env); 1094 exn_catching_apply = scheme_eval_string(e, env);
1094 exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env); 1095 exn_p = scheme_lookup_global(scheme_intern_symbol("exn?"), env);
1095 exn_message = scheme_lookup_global( 1096 exn_message = scheme_lookup_global(
1096 scheme_intern_symbol("exn-message"), env); 1097 scheme_intern_symbol("exn-message"), env);
1097 } 1098 }
1098 } 1099 }
1099 1100
1100 /* 1101 /*
1344 switch (rc) 1345 switch (rc)
1345 { 1346 {
1346 case 1: 1347 case 1:
1347 return scheme_make_integer_value(value); 1348 return scheme_make_integer_value(value);
1348 case 0: 1349 case 0:
1349 rval = scheme_make_string(strval); 1350 rval = scheme_make_string(strval);
1350 vim_free(strval); 1351 vim_free(strval);
1351 return rval; 1352 return rval;
1352 case -1: 1353 case -1:
1353 case -2: 1354 case -2:
1354 raise_vim_exn(_("hidden option")); 1355 raise_vim_exn(_("hidden option"));
1355 case -3: 1356 case -3:
1356 raise_vim_exn(_("unknown option")); 1357 raise_vim_exn(_("unknown option"));
1357 } 1358 }
1358 /* unreachable */ 1359 /* unreachable */
1359 return scheme_void; 1360 return scheme_void;
1360 } 1361 }
1361 1362
1443 1444
1444 buf = get_buffer_arg(prim->name, 0, argc, argv); 1445 buf = get_buffer_arg(prim->name, 0, argc, argv);
1445 list = scheme_null; 1446 list = scheme_null;
1446 1447
1447 for (w = firstwin; w != NULL; w = w->w_next) 1448 for (w = firstwin; w != NULL; w = w->w_next)
1448 if (w->w_buffer == buf->buf) 1449 if (w->w_buffer == buf->buf)
1449 list = scheme_make_pair(window_new(w), list); 1450 list = scheme_make_pair(window_new(w), list);
1450 1451
1451 return list; 1452 return list;
1452 } 1453 }
1453 1454
1504 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); 1505 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
1505 if (fnum < 1) 1506 if (fnum < 1)
1506 scheme_signal_error(_("window index is out of range")); 1507 scheme_signal_error(_("window index is out of range"));
1507 1508
1508 for (win = firstwin; win != NULL; win = win->w_next, --fnum) 1509 for (win = firstwin; win != NULL; win = win->w_next, --fnum)
1509 if (fnum == 1) /* to be 1-based */ 1510 if (fnum == 1) /* to be 1-based */
1510 return window_new(win); 1511 return window_new(win);
1511 1512
1512 return scheme_false; 1513 return scheme_false;
1513 } 1514 }
1514 1515
1679 int fnum; 1680 int fnum;
1680 1681
1681 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); 1682 fnum = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
1682 1683
1683 for (buf = firstbuf; buf; buf = buf->b_next) 1684 for (buf = firstbuf; buf; buf = buf->b_next)
1684 if (buf->b_fnum == fnum) 1685 if (buf->b_fnum == fnum)
1685 return buffer_new(buf); 1686 return buffer_new(buf);
1686 1687
1687 return scheme_false; 1688 return scheme_false;
1688 } 1689 }
1689 1690
1784 /* We need to handle deletion of buffers underneath us. 1785 /* We need to handle deletion of buffers underneath us.
1785 * If we add a "b_mzscheme_ref" field to the buf_T structure, 1786 * If we add a "b_mzscheme_ref" field to the buf_T structure,
1786 * then we can get at it in buf_freeall() in vim. 1787 * then we can get at it in buf_freeall() in vim.
1787 */ 1788 */
1788 if (buf->b_mzscheme_ref) 1789 if (buf->b_mzscheme_ref)
1789 return buf->b_mzscheme_ref; 1790 return buf->b_mzscheme_ref;
1790 1791
1791 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer)); 1792 self = scheme_malloc_fail_ok(scheme_malloc, sizeof(vim_mz_buffer));
1792 1793
1793 vim_memset(self, 0, sizeof(vim_mz_buffer)); 1794 vim_memset(self, 0, sizeof(vim_mz_buffer));
1794 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */ 1795 scheme_dont_gc_ptr(self); /* because buf isn't visible to GC */
1861 1862
1862 /* 1863 /*
1863 * Handle some error conditions 1864 * Handle some error conditions
1864 */ 1865 */
1865 if (lo < 0) 1866 if (lo < 0)
1866 lo = 0; 1867 lo = 0;
1867 1868
1868 if (hi < 0) 1869 if (hi < 0)
1869 hi = 0; 1870 hi = 0;
1870 if (hi < lo) 1871 if (hi < lo)
1871 hi = lo; 1872 hi = lo;
1872 1873
1873 n = hi - lo; 1874 n = hi - lo;
1874 1875
1875 for (i = n; i >= 0; --i) 1876 for (i = n; i >= 0; --i)
1876 { 1877 {
1916 #ifdef HAVE_SANDBOX 1917 #ifdef HAVE_SANDBOX
1917 sandbox_check(); 1918 sandbox_check();
1918 #endif 1919 #endif
1919 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0)); 1920 n = SCHEME_INT_VAL(GUARANTEE_INTEGER(prim->name, 0));
1920 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1])) 1921 if (!SCHEME_STRINGP(argv[1]) && !SCHEME_FALSEP(argv[1]))
1921 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv); 1922 scheme_wrong_type(prim->name, "string or #f", 1, argc, argv);
1922 line = argv[1]; 1923 line = argv[1];
1923 buf = get_buffer_arg(prim->name, 2, argc, argv); 1924 buf = get_buffer_arg(prim->name, 2, argc, argv);
1924 1925
1925 check_line_range(n, buf->buf); 1926 check_line_range(n, buf->buf);
1926 1927
2070 (unsigned)(new_len * sizeof(char *))); 2071 (unsigned)(new_len * sizeof(char *)));
2071 2072
2072 rest = line_list; 2073 rest = line_list;
2073 for (i = 0; i < new_len; ++i) 2074 for (i = 0; i < new_len; ++i)
2074 { 2075 {
2075 line = SCHEME_CAR(rest); 2076 line = SCHEME_CAR(rest);
2076 rest = SCHEME_CDR(rest); 2077 rest = SCHEME_CDR(rest);
2077 if (!SCHEME_STRINGP(line)) 2078 if (!SCHEME_STRINGP(line))
2078 scheme_wrong_type(prim->name, "string-list", 2, argc, argv); 2079 scheme_wrong_type(prim->name, "string-list", 2, argc, argv);
2079 array[i] = string_to_line(line); 2080 array[i] = string_to_line(line);
2080 } 2081 }
2081 2082
2082 savebuf = curbuf; 2083 savebuf = curbuf;
2083 curbuf = buf->buf; 2084 curbuf = buf->buf;
2084 2085
2085 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL) 2086 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
2086 { 2087 {
2087 curbuf = savebuf; 2088 curbuf = savebuf;
2088 raise_vim_exn(_("cannot save undo information")); 2089 raise_vim_exn(_("cannot save undo information"));
2089 } 2090 }
2090 2091
2091 /* 2092 /*
2092 * If the size of the range is reducing (ie, new_len < old_len) we 2093 * If the size of the range is reducing (ie, new_len < old_len) we
2093 * need to delete some old_len. We do this at the start, by 2094 * need to delete some old_len. We do this at the start, by
2098 if (ml_delete((linenr_T)lo, FALSE) == FAIL) 2099 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
2099 { 2100 {
2100 curbuf = savebuf; 2101 curbuf = savebuf;
2101 raise_vim_exn(_("cannot delete line")); 2102 raise_vim_exn(_("cannot delete line"));
2102 } 2103 }
2103 extra--; 2104 extra--;
2104 } 2105 }
2105 2106
2106 /* 2107 /*
2107 * For as long as possible, replace the existing old_len with the 2108 * For as long as possible, replace the existing old_len with the
2108 * new old_len. This is a more efficient operation, as it requires 2109 * new old_len. This is a more efficient operation, as it requires
2120 * free the string passed back because MzScheme has control of that 2121 * free the string passed back because MzScheme has control of that
2121 * memory. 2122 * memory.
2122 */ 2123 */
2123 while (i < new_len) 2124 while (i < new_len)
2124 { 2125 {
2125 if (ml_append((linenr_T)(lo + i - 1), 2126 if (ml_append((linenr_T)(lo + i - 1),
2126 (char_u *)array[i], 0, FALSE) == FAIL) 2127 (char_u *)array[i], 0, FALSE) == FAIL)
2127 { 2128 {
2128 curbuf = savebuf; 2129 curbuf = savebuf;
2129 raise_vim_exn(_("cannot insert line")); 2130 raise_vim_exn(_("cannot insert line"));
2130 } 2131 }
2131 ++i; 2132 ++i;
2132 ++extra; 2133 ++extra;
2133 } 2134 }
2134 2135
2135 /* 2136 /*
2136 * Adjust marks. Invalidate any which lie in the 2137 * Adjust marks. Invalidate any which lie in the
2137 * changed range, and move any in the remainder of the buffer. 2138 * changed range, and move any in the remainder of the buffer.
2184 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list)) 2185 if (!SCHEME_STRINGP(list) && !SCHEME_PAIRP(list))
2185 scheme_wrong_type(prim->name, "string or list", 1, argc, argv); 2186 scheme_wrong_type(prim->name, "string or list", 1, argc, argv);
2186 buf = get_buffer_arg(prim->name, 2, argc, argv); 2187 buf = get_buffer_arg(prim->name, 2, argc, argv);
2187 2188
2188 if (n != 0) /* 0 can be used in insert */ 2189 if (n != 0) /* 0 can be used in insert */
2189 check_line_range(n, buf->buf); 2190 check_line_range(n, buf->buf);
2190 if (SCHEME_STRINGP(list)) 2191 if (SCHEME_STRINGP(list))
2191 { 2192 {
2192 str = string_to_line(list); 2193 str = string_to_line(list);
2193 2194
2194 savebuf = curbuf; 2195 savebuf = curbuf;
2227 scheme_malloc, (unsigned)(size * sizeof(char *))); 2228 scheme_malloc, (unsigned)(size * sizeof(char *)));
2228 2229
2229 rest = list; 2230 rest = list;
2230 for (i = 0; i < size; ++i) 2231 for (i = 0; i < size; ++i)
2231 { 2232 {
2232 line = SCHEME_CAR(rest); 2233 line = SCHEME_CAR(rest);
2233 rest = SCHEME_CDR(rest); 2234 rest = SCHEME_CDR(rest);
2234 array[i] = string_to_line(line); 2235 array[i] = string_to_line(line);
2235 } 2236 }
2236 2237
2237 savebuf = curbuf; 2238 savebuf = curbuf;
2238 curbuf = buf->buf; 2239 curbuf = buf->buf;
2239 2240
2240 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL) 2241 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
2241 { 2242 {
2242 curbuf = savebuf; 2243 curbuf = savebuf;
2243 raise_vim_exn(_("cannot save undo information")); 2244 raise_vim_exn(_("cannot save undo information"));
2244 } 2245 }
2245 else 2246 else
2246 { 2247 {
2247 for (i = 0; i < size; ++i) 2248 for (i = 0; i < size; ++i)
2248 if (ml_append((linenr_T)(n + i), (char_u *)array[i], 2249 if (ml_append((linenr_T)(n + i), (char_u *)array[i],
2249 0, FALSE) == FAIL) 2250 0, FALSE) == FAIL)
2250 { 2251 {
2251 curbuf = savebuf; 2252 curbuf = savebuf;
2252 raise_vim_exn(_("cannot insert line")); 2253 raise_vim_exn(_("cannot insert line"));
2253 } 2254 }
2254 2255
2255 if (i > 0) 2256 if (i > 0)
2256 appended_lines_mark((linenr_T)n, (long)i); 2257 appended_lines_mark((linenr_T)n, (long)i);
2257 } 2258 }
2258 2259
2259 curbuf = savebuf; 2260 curbuf = savebuf;
2260 update_screen(VALID); 2261 update_screen(VALID);
2261 2262