harbour-sextant/lisp/local-projects/sextant/org/commands.lisp
Renaud Casenave-Péré 52ef89147c WIP
2025-07-20 21:27:03 +09:00

111 lines
3.9 KiB
Common Lisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(uiop:define-package :sextant/org/commands
(:use :cl :s-base64 :alexandria
:sextant/org/cursor)
(:import-from :inferior-shell #:run))
(in-package :sextant/org/commands)
(defclass command ()
((index :initarg :index
:type integer
:accessor index-of
:initform 0
:documentation "The index of the related node.")
(previous :initarg :previous
:type command
:accessor previous-of
:initform nil
:documentation "A link to the previous command in the list.")
(next :initarg :next
:type command
:accessor next-of
:initform nil
:documentation "A link to the next command in the list.")))
(defclass command-initial-state (command)
())
(defclass command-edit-text (command)
((before-text :initarg :before-text
:type string
:accessor before-text-of
:initform ""
:documentation "The text node had before this command.")
(after-text :initarg :after-text
:type string
:accessor after-text-of
:initform ""
:documentation "The text this command needs to apply.")))
(defclass command-join/split-node (command)
((previous-text :initarg :previous-text
:type string
:accessor previous-text-of
:initform ""
:documentation "The text of the previous node.")
(previous-eol :initarg :previous-eol
:type string
:accessor previous-eol-of
:initform ""
:documentation "The line ending of the previous node.")
(next-text :initarg :next-text
:type string
:accessor next-text-of
:initform ""
:documentation "The text of the next node.")
(next-eol :initarg :next-eol
:type string
:accessor next-eol-of
:initform ""
:documentation "The line ending of the next node.")))
(defclass command-join-node (command-join/split-node)
())
(defclass command-split-node (command-join/split-node)
())
(defun make-command-edit-text (command index before-text after-text)
(make-instance 'command-edit-text :previous command
:index index
:before-text before-text
:after-text after-text))
(defun make-command-join-node (command index previous-text previous-eol next-text next-eol)
(make-instance 'command-join-node :previous command
:index index
:previous-text previous-text
:previous-eol previous-eol
:next-text next-text
:next-eol next-eol))
(defun make-command-split-node (command index previous-text previous-eol next-text next-eol)
(make-instance 'command-split-node :previous command
:index index
:previous-text previous-text
:previous-eol previous-eol
:next-text next-text
:next-eol next-eol))
(defun do-edit-text (cursor target-index new-text)
)
(defgeneric apply-command (cursor command))
(defmethod apply-command (cursor (command command-edit-text))
(do-edit-text ()))
(defun edit-text (cursor text)
(let ((command (make-command-edit-text (document-commands cursor)
(cursor-index cursor)
(raw-text-of (cursor-node cursor))
text)))
(setf (document-commands cursor) command)
(apply-command cursor command)))