backslash at end of line to continue on next line



Hello,

I'm working on some code to make it possible to continue
long atoms by putting a backslash at the end of a line,
e.g., 12345678\
90 => 1234567890

I have something that seems to work as intended and doesn't
change existing behavior of the input scanner wrt backslash.
Before I go any farther maybe someone can glance at it.

I've also appended some test inputs. As it stands the code
yields the second expression in each pair, as hoped.

For what it's worth,
Robert Dodier

Index: src/commac.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/commac.lisp,v
retrieving revision 1.25
diff -u -r1.25 commac.lisp
--- src/commac.lisp     13 Sep 2005 17:58:14 -0000      1.25
+++ src/commac.lisp     31 Oct 2005 05:24:56 -0000
@@ -674,7 +674,7 @@

 (defvar *prompt-on-read-hang* nil)
 (defvar *read-hang-prompt* "")
-(defun tyi (&optional (stream *standard-input*) eof-option)
+(defun tyi-raw (&optional (stream *standard-input*) eof-option)
   (let ((ch (read-char-no-hang stream nil eof-option)))
     (if ch
        ch
@@ -684,6 +684,23 @@
            (force-output *standard-output*))
          (read-char stream nil eof-option)))))

+(let ((previous-tyi #\a))
+  (defun tyi (&optional (stream *standard-input*) eof-option)
+    (let ((ch (tyi-raw stream eof-option)))
+      (if (eq ch eof-option)
+        ch
+        (backslash-check ch stream eof-option))))
+  (defun backslash-check (ch stream eof-option)
+    (if (char= previous-tyi #\\ )
+      (progn (setq previous-tyi #\a) ch)
+      (setq previous-tyi
+        (if (char= ch #\\ )
+          (let ((next-char (tyipeek nil stream)))
+            (if (char= next-char #\newline)
+              (progn (tyi-raw stream eof-option) (tyi stream eof-option))
+              ch))
+          ch)))))
+
 (defun tyipeek (&optional peek-type &rest read-args)
   (if read-args
       (peek-char peek-type (car read-args))
Index: src/displa.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/displa.lisp,v
retrieving revision 1.21
diff -u -r1.21 displa.lisp
--- src/displa.lisp     27 Aug 2005 17:41:00 -0000      1.21
+++ src/displa.lisp     31 Oct 2005 05:25:02 -0000
@@ -306,7 +306,7 @@
                (setq result nil w (f+ linel width)))
               (t (increment width)
                  (when (and (= w width) l)
-                   (forcebreak (cons #\# result) width)
+                   (forcebreak (cons #\\ result) width)
                    (setq result nil w (f+ linel width))
                    (increment width))
                  (setq result (rplacd dummy result))))))))


\f\o\o\b\a\r;
foobar;

"\f\o\o\b\a\r";
"foobar";

"foo\
\
\
\
\
bar";
"foobar";

"foo\\\
\
bar";
"foo\\bar";

"foo\"\
bar\"\
baz";
"foo\"bar\"baz";

"\?foo\ bar";
"?foo bar";

1\
2\
3\
4\
5\
6;
123456;

"a\ \ \ \ b";
"a    b";

"a\\\ \\\b";
"a\\ \\b";

125\
125e-3;
125125e-3;

125125\
e-3;
125125e-3;

125125e\
-3;
125125e-3;

125125e-\
3;
125125e-3;

si\
n(1);
sin(1);

cos(\
1);
cos(1);

12!\
!;
12!!;

(infix("blurfle"), 0);
0;

a blurf\
le b;
a blurfle b;