On Wed, Jan 24, 2018 at 6:18 PM, 'Nasser M. Abbasi' via FriCAS -
computer algebra system <[email protected]> wrote:
>
> Having the option to append to a spool file would be very useful to
> many.
>
> There are many times, where one want to spool some commands,
> then turn spool off for others, then later start to spool other
> commands and so on.
>
> Now it is not possible to do, without manually going to the
> command line, saving the old file somewhere and starting over,
> then later merge the files manually again.
>
> Ideally, user should have an option when starting spool to
> either overwrite the spool file if it exists, or to append to it. This gives
> most flexibility.

See the patch bollow.

Now you can use
    )spool filename )append
to append to the end of 'filename', and
    )spool filename )replace
to replace the contents of 'filename'.

Warning: according to http://clhs.lisp.se/Body/f_dribbl.htm
DRIBBLE is implementation dependent.
This patch works for me in SBCL, I didn't test for other lisps.
We should use a more portable solution in the future.

diff --git a/src/interp/i-syscmd.boot b/src/interp/i-syscmd.boot
index 1922637d..219904c6 100644
--- a/src/interp/i-syscmd.boot
+++ b/src/interp/i-syscmd.boot
@@ -2353,15 +2353,27 @@

 --% )spool

-spool(filename) ==
-    null(filename) =>
+spool(args) ==
+    null(args) =>
         DRIBBLE()
         TERPRI()
         reset_highlight()
-    filename := first(filename)
+    # args > 1 => SAY ")spool takes a single argument."
+    # $options > 1 => SAY ")spool takes a single option."
+    filename := first args
     if SYMBOLP(filename) then filename := SYMBOL_-NAME(filename)
-    PROBE_-FILE(filename) =>
-        ERROR(FORMAT(nil, '"file ~a already exists", filename))
+    if PROBE_-FILE(filename) then
+        null $options =>
+            ERROR(FORMAT(nil, '"file ~a already exists", filename))
+        option := first first $options
+        option = 'append =>
+            "TODO: append file properly"
+            -- DRIBBLE is implementation dependent.
+            -- Currently DRIBBLE appends to a file in SBCL.
+            -- We need a more portable solution.
+        option = 'replace =>
+            deleteFile filename
+        SAY ")spool: invalid option."
     DRIBBLE(filename)
     TERPRI()
     clear_highlight()

> But if this is not possible, I'd go for the default being
> to append to the file if it exists.
>
> Thanks
> --Nasser
>

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to