Add method to copy whole text into editor buffer
This commit is contained in:
parent
4f096b9820
commit
8d4d462efc
3 changed files with 19 additions and 2 deletions
|
@ -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")))
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
;;;; package.lisp
|
||||
|
||||
(defpackage #:editor
|
||||
(:use #:cl #:trivial-gray-streams)
|
||||
(:use #:cl #:trivial-gray-streams #:split-sequence)
|
||||
(:export #:main))
|
||||
|
|
Loading…
Add table
Reference in a new issue