[Linedit-cvs] CVS update: src/rewindable.lisp src/command-functions.lisp src/dumb-terminal.lisp src/editor.lisp src/line.lisp src/linedit.asd src/main.lisp src/sbcl-repl.lisp src/smart-terminal.lisp src/terminal.lisp src/version.txt src/pool.lisp

Nikodemus Siivola nsiivola at common-lisp.net
Mon Oct 20 15:34:04 UTC 2003


Update of /project/linedit/cvsroot/src
In directory common-lisp.net:/tmp/cvs-serv31798

Modified Files:
	command-functions.lisp dumb-terminal.lisp editor.lisp 
	line.lisp linedit.asd main.lisp sbcl-repl.lisp 
	smart-terminal.lisp terminal.lisp version.txt 
Added Files:
	rewindable.lisp 
Removed Files:
	pool.lisp 
Log Message:
- Fixed killring so that it retains state between invocations.
- Refactored internals. 

Date: Mon Oct 20 11:34:03 2003
Author: nsiivola



Index: src/command-functions.lisp
diff -u src/command-functions.lisp:1.5 src/command-functions.lisp:1.6
--- src/command-functions.lisp:1.5	Mon Oct 20 08:28:56 2003
+++ src/command-functions.lisp	Mon Oct 20 11:34:02 2003
@@ -31,29 +31,28 @@
 
 (defun add-char (char editor)
   (with-editor-point-and-string ((point string) editor)
-    (setf (editor-string editor)
-	  (concat (subseq string 0 point)
-		  (string char)
-		  (subseq string point)))
-    (incf (editor-point editor))))
+    (setf (get-string editor) (concat (subseq string 0 point)
+				      (string char)
+				      (subseq string point)))
+    (incf (get-point editor))))
 
 (defun delete-char-backwards (chord editor)
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     ;; Can't delegate to editor because of the SUBSEQ index calc.
     (unless (zerop point)
-      (setf (editor-string editor)
-	    (concat (subseq string 0 (1- point)) (subseq string point))
-	    (editor-point editor) (1- point)))))
+      (setf (get-string editor) (concat (subseq string 0 (1- point)) 
+					(subseq string point))
+	    (get-point editor) (1- point)))))
 
 (defun delete-char-forwards (chord editor)
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
-    (setf (editor-string editor)
-	  (concat (subseq string 0 point) (subseq string (1+ point))))))
+    (setf (get-string editor) (concat (subseq string 0 point) 
+				      (subseq string (1+ point))))))
 
 (defun delete-char-forwards-or-eof (chord editor)
-  (if (equal "" (editor-string editor))
+  (if (equal "" (get-string editor))
       (error 'end-of-file :stream *standard-input*)
       (delete-char-forwards chord editor)))
 
@@ -61,9 +60,9 @@
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     (let ((i (editor-word-start editor)))
-      (setf (editor-string editor)
-	    (concat (subseq string 0 i) (subseq string point))
-	    (editor-point editor) i))))
+      (setf (get-string editor) (concat (subseq string 0 i) 
+					(subseq string point))
+	    (get-point editor) i))))
 
 (defun finish-input (chord editor)
   (declare (ignore chord editor))
@@ -73,47 +72,47 @@
 
 (defun move-to-bol (chord editor)
   (declare (ignore chord))
-  (setf (editor-point editor) 0))
+  (setf (get-point editor) 0))
 
 (defun move-to-eol (chord editor)
   (declare (ignore chord))
-  (setf (editor-point editor) (length (editor-string editor))))
+  (setf (get-point editor) (length (get-string editor))))
 
 (defun move-char-right (chord editor)
   (declare (ignore chord))
-  (incf (editor-point editor)))
+  (incf (get-point editor)))
 
 (defun move-char-left (chord editor)
   (declare (ignore chord))
-  (decf (editor-point editor)))
+  (decf (get-point editor)))
 
 (defun move-word-backwards (chord editor)
   (declare (ignore chord))
-  (setf (editor-point editor) (editor-word-start editor)))
+  (setf (get-point editor) (editor-word-start editor)))
 
 (defun move-word-forwards (chord editor)
   (declare (ignore chord))
-  (setf (editor-point editor) (editor-word-end editor)))
+  (setf (get-point editor) (editor-word-end editor)))
 
 ;;; UNDO
 
 (defun undo (chord editor)
   (declare (ignore chord))
-  (setf (editor-line editor) (copy (rewind (undo-pool editor))))
+  (rewind-state editor)
   (throw 'linedit-loop t))
 
 ;;; HISTORY
 
 (defun history-previous (chord editor)
   (declare (ignore chord))
-  (aif (buffer-previous (editor-string editor) (editor-history editor))
-       (setf (editor-string editor) it)
+  (aif (buffer-previous (get-string editor) (editor-history editor))
+       (setf (get-string editor) it)
        (beep editor)))
 
 (defun history-next (chord editor) 
   (declare (ignore chord))
-  (aif (buffer-next (editor-string editor) (editor-history editor))
-       (setf (editor-string editor) it)
+  (aif (buffer-next (get-string editor) (editor-history editor))
+       (setf (get-string editor) it)
        (beep editor)))
 
 ;;; KILLING & YANKING
@@ -121,11 +120,11 @@
 (defun %yank (editor)
   (aif (buffer-peek (editor-killring editor))
        (with-editor-point-and-string ((point string) editor)
-	 (setf (editor-string editor)
+	 (setf (get-string editor)
 	       (concat (subseq string 0 (editor-yank editor))
 		       it
 		       (subseq string point))
-	       (editor-point editor) (+ (editor-yank editor) (length it))))
+	       (get-point editor) (+ (editor-yank editor) (length it))))
 	(beep editor)))
 
 (defun yank (chord editor)
@@ -145,15 +144,15 @@
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     (buffer-push (subseq string point) (editor-killring editor))
-    (setf (editor-string editor) (subseq string 0 point))))
+    (setf (get-string editor) (subseq string 0 point))))
 
 (defun kill-to-bol (chord editor)
   ;; Thanks to Andreas Fuchs
   (declare (ignore chord))
   (with-editor-point-and-string ((point string) editor)
     (buffer-push (subseq string 0 point) (editor-killring editor))
-    (setf (editor-string editor) (subseq string point)
-	  (editor-point editor) 0)))
+    (setf (get-string editor) (subseq string point)
+	  (get-point editor) 0)))
 
 (defun copy-region (chord editor)
   (declare (ignore chord))
@@ -171,15 +170,15 @@
        (let ((start (min it point))
 	     (end (max it point)))
 	(copy-region t editor)
-	(setf (editor-string editor)
-	      (concat (subseq string 0 start) (subseq string end))
-	      (editor-point editor) start)))))
+	(setf (get-string editor) (concat (subseq string 0 start) 
+					  (subseq string end))
+	      (get-point editor) start)))))
 
 (defun set-mark (chord editor)
   (declare (ignore chord))
   ;; FIXME: this was (setf mark (unless mark point)) -- modulo correct
   ;; accessors.  Why? Was I not thinking, or am I not thinking now?
-  (setf (editor-mark editor) (editor-point editor)))
+  (setf (editor-mark editor) (get-point editor)))
 
 ;;; SIGNALS
 
@@ -216,9 +215,9 @@
 		      :width (+ max-id max-f 2))))
 
 (defun unknown-command (chord editor)
-  (format *error-output*
-	  "~&Unknown command ~S.~%"
-	  chord))
+  (newline editor)
+  (format *standard-output* "Unknown command ~S." chord)
+  (newline editor))
 
 (defun complete (chord editor)
   (declare (ignore chord))


Index: src/dumb-terminal.lisp
diff -u src/dumb-terminal.lisp:1.5 src/dumb-terminal.lisp:1.6
--- src/dumb-terminal.lisp:1.5	Sun Oct 19 19:38:23 2003
+++ src/dumb-terminal.lisp	Mon Oct 20 11:34:03 2003
@@ -30,7 +30,7 @@
   (backend-columns backend))
 
 (defmethod display ((backend dumb-terminal) prompt line)
-  (let ((string (line-string line)))
+  (let ((string (get-string line)))
     (flet ((write-prompt ()
 	     (write-char #\Return)
 	     (write-string prompt)))
@@ -41,5 +41,6 @@
 		      (length string))
 	    do (write-char #\Space))
       (write-prompt)
-      (write-string (subseq string 0 (line-point line)))
+      (write-string (subseq string 0 (get-point line)))
       (force-output))))
+


Index: src/editor.lisp
diff -u src/editor.lisp:1.5 src/editor.lisp:1.6
--- src/editor.lisp:1.5	Sun Oct 19 19:47:21 2003
+++ src/editor.lisp	Mon Oct 20 11:34:03 2003
@@ -22,16 +22,10 @@
 (in-package :linedit)
 
 (defvar *history* nil)
+(defvar *killring* nil)
 
-(defclass editor ()
-  ((undo-pool :reader undo-pool :initform (make-instance 'pool))
-   (line :reader editor-line :initform (make-instance 'line))
-   (backend :reader editor-backend
-	    :initform (if (smart-terminal-p)
-			  (make-instance 'smart-terminal)
-			  (make-instance 'dumb-terminal))
-	    :initarg :backend)
-   (commands :reader editor-commands
+(defclass editor (line rewindable)
+  ((commands :reader editor-commands
 	     :initform *commands*
 	     :initarg :commands)
    (completer :reader editor-completer
@@ -41,7 +35,7 @@
 	    :initform (or *history* (setf *history* (make-instance 'buffer)))
 	    :initarg :history)
    (killring :reader editor-killring
-	     :initform (make-instance 'buffer)
+	     :initform (or *killring* (setf *killring* (make-instance 'buffer)))
 	     :initarg :killring)
    (insert :reader editor-insert-mode
 	   :initform t
@@ -56,75 +50,80 @@
 	   :initform ""
 	   :initarg :prompt)))
 
-(defun save-line-for-undo (editor)
-  (let ((pool (undo-pool editor))
-	(line (editor-line editor)))
-    (unless (equal? line (last-insert pool))
-      ;; Save only if different than last saved state.
-      (insert (copy line) pool))))
+(defmethod initialize-instance :after ((editor editor) &rest initargs)
+  (save-state editor))
+
+(defclass smart-editor (editor smart-terminal) ())
+(defclass dumb-editor (editor dumb-terminal) ())
+
+(defun make-editor (&rest args)
+  (apply 'make-instance
+	 (if (smart-terminal-p)
+	     'smart-editor
+	     'dumb-editor)
+	 args))
+
+;;; undo
+
+(defun save-state (editor)
+  (let ((string (get-string editor))
+	(last (last-state editor)))
+    (unless (and last (equal string (get-string last)))
+      ;; Save only if different than last saved state
+      (save-rewindable-state editor (make-instance 'line
+						   :string (copy-seq string) 
+						   :point (get-point editor))))))
+
+(defmethod rewind-state ((editor editor))
+  (let ((line (call-next-method)))
+    (setf (get-string editor) (copy-seq (get-string line))
+	  (get-point editor) (get-point line))))
 
 (defvar *debug-info* nil)
 
 (defun next-chord (editor)
-  (display (editor-backend editor)
-	   (editor-prompt editor)
-	   (editor-line editor))
+  (display editor (editor-prompt editor) editor) ; Hmm... ick?
   (forget-yank editor)
-  (let* ((chord (read-chord (editor-backend editor)))
+  (let* ((chord (read-chord editor))
 	 (command (gethash chord (editor-commands editor)
 			   (if (characterp chord)
 			       'add-char
 			       'unknown-command))))
     (setf *debug-info* (list command chord editor))
     (funcall command chord editor))
-  (save-line-for-undo editor))
-
-(defun editor-string (editor)
-  (line-string (editor-line editor)))
+  (save-state editor))
 
-(defun (setf editor-string) (string editor)
-  (let ((limit (line-length-limit (editor-backend editor))))
+(defmethod (setf get-string) (string editor)
+  (let ((limit (line-length-limit editor)))
     (if (and limit (>= (length string) limit))
 	(progn
 	  (beep editor)
 	  (throw 'linedit-loop t))
-	(setf (line-string (editor-line editor)) string))))
-
-(defun (setf editor-line) (line editor)
-  (setf (slot-value editor 'line) line))
-
-(defun editor-point (editor)
-  (line-point (editor-line editor)))
-
-(defun (setf editor-point) (point editor)
-  (setf (line-point (editor-line editor)) point))
+	(call-next-method))))
 
 (defun get-finished-string (editor)
-  (buffer-push (editor-string editor) (editor-history editor))
-  (newline (editor-backend editor))
-  (editor-string editor))
+  (buffer-push (get-string editor) (editor-history editor))
+  (newline editor)
+  (get-string editor))
 
 (defmacro with-editor-point-and-string (((point string) editor) &body forms)
-  `(let ((,point (editor-point ,editor))
-	 (,string (editor-string ,editor)))
+  `(let ((,point (get-point ,editor))
+	 (,string (get-string ,editor)))
      , at forms))
 
-(defmethod beep ((editor editor))
-  (beep (editor-backend editor)))
-
 (uffi:def-function ("linedit_interrupt" c-interrupt)
     ()
   :returning :void)
 
 (defun editor-interrupt (editor)
-  (without-backend (editor-backend editor) (c-interrupt)))
+  (without-backend editor (c-interrupt)))
 
 (uffi:def-function ("linedit_stop" c-stop)
     ()
   :returning :void)
 
 (defun editor-stop (editor)
-  (without-backend (editor-backend editor) (c-stop)))
+  (without-backend editor (c-stop)))
 
 (defun editor-word-start (editor)
   (with-editor-point-and-string ((point string) editor)
@@ -159,13 +158,13 @@
 (defun editor-word (editor)
   (let ((start (editor-word-start editor))
 	(end (editor-word-end editor)))
-    (subseq (editor-string editor) start end)))
+    (subseq (get-string editor) start end)))
 
 (defun editor-complete (editor)
   (funcall (editor-completer editor) (editor-word editor) editor))
 
 (defun remember-yank (editor)
-  (setf (editor-yank editor) (editor-point editor)))
+  (setf (editor-yank editor) (get-point editor)))
 
 (defun forget-yank (editor)
   (shiftf (editor-last-yank editor) (editor-yank editor) nil))
@@ -178,16 +177,10 @@
   (with-editor-point-and-string ((point string) editor)
     (let ((start (editor-word-start editor))
 	  (end (editor-word-end editor)))
-      (setf (editor-string editor)
+      (setf (get-string editor)
 	    (concat (subseq string 0 start) word (subseq string end))
-	    (editor-point editor) (+ start (length word))))))
-
-(defmethod print-in-columns ((editor editor) list &key width)
-  (print-in-columns (editor-backend editor) list :width width))
-
-(defmethod print-in-lines ((editor editor) string)
-  (print-in-lines (editor-backend editor) string))
+	    (get-point editor) (+ start (length word))))))
 
 (defun in-quoted-string-p (editor)
   (let ((i (editor-word-start editor)))
-    (and (plusp i) (eql #\" (schar (editor-string editor) (1- i))))))
+    (and (plusp i) (eql #\" (schar (get-string editor) (1- i))))))


Index: src/line.lisp
diff -u src/line.lisp:1.2 src/line.lisp:1.3
--- src/line.lisp:1.2	Sun Sep 28 07:37:43 2003
+++ src/line.lisp	Mon Oct 20 11:34:03 2003
@@ -22,20 +22,9 @@
 (in-package :linedit)
 
 (defclass line ()
-  ((string :accessor line-string :initform "" :initarg :string)
-   (point :reader line-point :initform 0 :initarg :point)))
+  ((string :accessor get-string :initform "" :initarg :string)
+   (point :accessor get-point :initform 0 :initarg :point)))
 
-(defun (setf line-point) (point line)
-  (when (<= 0 point (length (line-string line)))
-    (setf (slot-value line 'point) point)))
-
-(defmethod equal? ((a line) (b null))
-  nil)
-
-(defmethod equal? ((a line) (b line))
-  (equal (line-string a) (line-string b)))
-
-(defmethod copy ((line line))
-  (make-instance 'line
-		 :string (copy-seq (line-string line))
-		 :point (line-point line)))
+(defmethod (setf get-point) :around (point line)
+  (when (<= 0 point (length (get-string line)))
+    (call-next-method)))


Index: src/linedit.asd
diff -u src/linedit.asd:1.19 src/linedit.asd:1.20
--- src/linedit.asd:1.19	Mon Oct 20 08:28:56 2003
+++ src/linedit.asd	Mon Oct 20 11:34:03 2003
@@ -48,6 +48,7 @@
     (error 'operation-error :component c :operation o)))
 
 (defsystem :linedit
+    :version "0.14.2"
     :depends-on (:uffi :terminfo)
     :components
   (;; Common
@@ -64,12 +65,13 @@
    (:file "dumb-terminal" :depends-on ("terminal"))
 
    ;; Editor
-   (:file "pool" :depends-on ("utility-macros"))
+   (:file "rewindable" :depends-on ("utility-macros"))
    (:file "line" :depends-on ("utility-macros"))
    (:file "buffer" :depends-on ("utility-macros"))
    (:file "command-keys" :depends-on ("packages"))
    (:c-source-file "signals")
-   (:file "editor" :depends-on ("backend" "pool" "signals" "line" "buffer" "command-keys"))
+   (:file "editor" :depends-on ("backend" "rewindable" "signals"
+				"line" "buffer" "command-keys"))
    (:file "main" :depends-on ("editor"))
    (:file "complete" :depends-on ("utility-macros"))
    (:file "command-functions" :depends-on ("editor"))


Index: src/main.lisp
diff -u src/main.lisp:1.5 src/main.lisp:1.6
--- src/main.lisp:1.5	Mon Sep 29 14:25:20 2003
+++ src/main.lisp	Mon Oct 20 11:34:03 2003
@@ -22,9 +22,8 @@
 (in-package :linedit)
 
 (defun linedit (&rest keyword-args)
-  (let* ((editor (apply 'make-instance 'editor keyword-args))
-	 (backend (editor-backend editor)))
-    (with-backend backend      
+  (let ((editor (apply 'make-editor keyword-args)))
+    (with-backend editor
       (catch 'linedit-done
 	(loop
 	 (catch 'linedit-loop


Index: src/sbcl-repl.lisp
diff -u src/sbcl-repl.lisp:1.2 src/sbcl-repl.lisp:1.3
--- src/sbcl-repl.lisp:1.2	Sun Sep 28 07:37:43 2003
+++ src/sbcl-repl.lisp	Mon Oct 20 11:34:03 2003
@@ -46,7 +46,9 @@
 		(lambda (in out)
 		  (declare (type stream out in))
 		  (with-input-from-string (in (repl-reader in out))
-		    (terpri)
+		    ;; FIXME: Youch.
+		    (write-char #\newline)
+		    (write-char #\return)
 		    (funcall read-form-fun in out)))
 		(lambda (in out)
 		  (declare (type stream out in))


Index: src/smart-terminal.lisp
diff -u src/smart-terminal.lisp:1.2 src/smart-terminal.lisp:1.3
--- src/smart-terminal.lisp:1.2	Sun Oct 19 19:47:21 2003
+++ src/smart-terminal.lisp	Mon Oct 20 11:34:03 2003
@@ -38,7 +38,7 @@
 	     (ceiling (1+ n) columns))
 	   (find-col (n)
 	     (rem n columns)))
-      (let* ((new (concat prompt (line-string line)))
+      (let* ((new (concat prompt (get-string line)))
 	     (old (active-string backend))
 	     (end (length new))
 	     (rows (find-row end))
@@ -55,7 +55,7 @@
       (when (and (< start end) (zerop (find-col end)))
 	(ti:tputs ti:cursor-down))
       ;; Place point
-      (let* ((point (+ (length prompt) (line-point line)))
+      (let* ((point (+ (length prompt) (get-point line)))
 	     (point-row (find-row point))
 	     (point-col (find-col point)))
       (loop repeat (- rows point-row)
@@ -65,3 +65,4 @@
       (setf (point-row backend) point-row
 	    (active-string backend) new))))
     (force-output *terminal-io*)))
+


Index: src/terminal.lisp
diff -u src/terminal.lisp:1.2 src/terminal.lisp:1.3
--- src/terminal.lisp:1.2	Mon Oct 20 08:28:56 2003
+++ src/terminal.lisp	Mon Oct 20 11:34:03 2003
@@ -125,7 +125,7 @@
     (newline backend)))
 
 (defmethod print-in-lines ((backend terminal) string)
-  (terpri)
+  (newline backend)
   (do ((i 0 (1+ i))
        (lines 0))
       ((= i (length string)))
@@ -137,8 +137,9 @@
       (when (eql #\newline c)
 	(incf lines))
       (write-char c)))
-  (terpri))
+  (newline backend))
 
 (defmethod newline ((backend terminal))
   (write-char #\newline)
-  (write-char #\return))
+  (write-char #\return)
+  (force-output))


Index: src/version.txt
diff -u src/version.txt:1.6 src/version.txt:1.7
--- src/version.txt:1.6	Mon Oct 20 08:28:56 2003
+++ src/version.txt	Mon Oct 20 11:34:03 2003
@@ -1 +1 @@
-0.14.1
+0.14.2







More information about the linedit-cvs mailing list