guile string conversion functions
[bpt/emacs.git] / src / fns.c
index ba6fabe..01a1ea7 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -1074,6 +1074,23 @@ an error is signaled.  */)
   return string;
 }
 
+DEFUN ("string-to-scheme", Fstring_to_scheme, Sstring_to_scheme, 1, 1, 0, 0)
+  (Lisp_Object string)
+{
+  CHECK_STRING (string);
+  return scm_from_utf8_stringn (SSDATA (string), SBYTES (string));
+}
+
+DEFUN ("string-from-scheme", Fstring_from_scheme, Sstring_from_scheme, 1, 1, 0, 0)
+  (Lisp_Object string)
+{
+  char *s;
+  size_t lenp;
+
+  CHECK_STRING (string);
+  s = scm_to_utf8_stringn (string, &lenp);
+  return make_string (s, lenp);
+}
 \f
 DEFUN ("copy-alist", Fcopy_alist, Scopy_alist, 1, 1, 0,
        doc: /* Return a copy of ALIST.
@@ -1906,7 +1923,7 @@ This is the last value stored with `(put SYMBOL PROPNAME VALUE)'.  */)
   (Lisp_Object symbol, Lisp_Object propname)
 {
   CHECK_SYMBOL (symbol);
-  return Fplist_get (XSYMBOL (symbol)->plist, propname);
+  return Fplist_get (symbol_plist (symbol), propname);
 }
 
 DEFUN ("plist-put", Fplist_put, Splist_put, 3, 3, 0,
@@ -1949,7 +1966,7 @@ It can be retrieved with `(get SYMBOL PROPNAME)'.  */)
 {
   CHECK_SYMBOL (symbol);
   set_symbol_plist
-    (symbol, Fplist_put (XSYMBOL (symbol)->plist, propname, value));
+    (symbol, Fplist_put (symbol_plist (symbol), propname, value));
   return value;
 }
 \f
@@ -2042,10 +2059,10 @@ of strings.  (`equal' ignores text properties.)  */)
 {
   Lisp_Object tem;
 
-  scm_dynwind_begin (0);
+  dynwind_begin ();
   scm_dynwind_fluid (compare_text_properties, SCM_BOOL_T);
   tem = Fequal (o1, o2);
-  scm_dynwind_end ();
+  dynwind_end ();
   return tem;
 }
 
@@ -2618,7 +2635,7 @@ The normal messages at start and end of loading FILENAME are suppressed.  */)
 
   if (NILP (tem))
     {
-      ptrdiff_t count = SPECPDL_INDEX ();
+      dynwind_begin ();
       int nesting = 0;
 
       /* This is to make sure that loadup.el gives a clear picture
@@ -2656,8 +2673,11 @@ The normal messages at start and end of loading FILENAME are suppressed.  */)
       UNGCPRO;
 
       /* If load failed entirely, return nil.  */
-      if (NILP (tem))
-       return unbind_to (count, Qnil);
+      if (NILP (tem)){
+       
+         dynwind_end ();
+       return Qnil;
+       }
 
       tem = Fmemq (feature, Vfeatures);
       if (NILP (tem))
@@ -2666,7 +2686,7 @@ The normal messages at start and end of loading FILENAME are suppressed.  */)
 
       /* Once loading finishes, don't undo it.  */
       Vautoload_queue = Qt;
-      feature = unbind_to (count, feature);
+      dynwind_end ();
     }
 
   return feature;
@@ -2740,16 +2760,13 @@ usage: (widget-apply WIDGET PROPERTY &rest ARGS)  */)
   (ptrdiff_t nargs, Lisp_Object *args)
 {
   /* This function can GC.  */
-  Lisp_Object newargs[3];
   struct gcpro gcpro1, gcpro2;
   Lisp_Object result;
 
-  newargs[0] = Fwidget_get (args[0], args[1]);
-  newargs[1] = args[0];
-  newargs[2] = Flist (nargs - 2, args + 2);
-  GCPRO2 (newargs[0], newargs[2]);
-  result = Fapply (3, newargs);
-  UNGCPRO;
+  result = call3 (intern ("apply"),
+                  Fwidget_get (args[0], args[1]),
+                  args[0],
+                  Flist (nargs - 2, args + 2));
   return result;
 }
 
@@ -4280,7 +4297,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start,
     }
   else
     {
-      struct buffer *prev = current_buffer;
+      dynwind_begin ();
 
       record_unwind_current_buffer ();
 
@@ -4374,10 +4391,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start,
        }
 
       object = make_buffer_string (b, e, 0);
-      set_buffer_internal (prev);
-      /* Discard the unwind protect for recovering the current
-        buffer.  */
-      specpdl_ptr--;
+      dynwind_end ();
 
       if (STRING_MULTIBYTE (object))
        object = code_convert_string (object, coding_system, Qnil, 1, 0, 0);
@@ -4489,6 +4503,19 @@ If BINARY is non-nil, returns a string in binary form.  */)
   return secure_hash (algorithm, object, start, end, Qnil, Qnil, binary);
 }
 \f
+DEFUN ("eval-scheme", Feval_scheme, Seval_scheme, 1, 1,
+       "sEval Scheme: ",
+       doc: /* Evaluate a string containing a Scheme expression.  */)
+  (Lisp_Object string)
+{
+  Lisp_Object tem;
+
+  CHECK_STRING (string);
+
+  tem = scm_c_eval_string (SSDATA (string));
+  return (INTERACTIVE ? Fprin1 (tem, Qt) : tem);
+}
+\f
 void
 init_fns_once (void)
 {