diff --git a/editor/editor.asd b/editor/editor.asd index c994b0a..65e069f 100644 --- a/editor/editor.asd +++ b/editor/editor.asd @@ -3,7 +3,7 @@ (asdf:defsystem #:editor :version "0.1.0" :serial t - :depends-on (#:user-side-compiler #:trivial-gray-streams) + :depends-on (#:user-side-compiler #:trivial-gray-streams #:split-sequence) :components ((:file "package") (:file "editor") (:file "binary-build"))) diff --git a/editor/editor.lisp b/editor/editor.lisp index 4e2a203..be805ff 100644 --- a/editor/editor.lisp +++ b/editor/editor.lisp @@ -414,6 +414,23 @@ serial connection the editor normally runs under.") :do (write-string (line-content line) output) (terpri output)))) +(defmethod (setf buffer-string) (new-value (buffer buffer)) + (declare (optimize (debug 3))) + (let ((lines (split-sequence #\Newline new-value))) + (setf (first-line buffer) (make-instance 'line)) + (set-line-text (first-line buffer) (first lines)) + (loop :for lines-left := (rest lines) :then (rest lines-left) + :until (null lines-left) + :for line := (first lines-left) + :for prev-line := (first-line buffer) :then line-obj + :for line-obj := (make-instance 'line :prev-line prev-line) + :do (setf (next-line prev-line) line-obj) + (set-line-text line-obj line)) + (setf (top-line (buffer-view buffer)) (first-line buffer) + (bottom-line (buffer-view buffer)) nil + (cursor-line (cursor buffer)) (first-line buffer) + (cursor-column (cursor buffer)) 0))) + (defmethod update-buffer-cursor ((buffer buffer)) "Makes sure the screen cursor is the same as BUFFER's logical cursor. Additionally ensures correct line numbers on the way, as a bonus." diff --git a/editor/package.lisp b/editor/package.lisp index 8a22b55..59d979a 100644 --- a/editor/package.lisp +++ b/editor/package.lisp @@ -1,5 +1,5 @@ ;;;; package.lisp (defpackage #:editor - (:use #:cl #:trivial-gray-streams) + (:use #:cl #:trivial-gray-streams #:split-sequence) (:export #:main))