;;; -*- Mode:LISP; Package:USER; Base:10; Readtable:CL -*-


;;; Global Variables (hold values if editor process reset):
(DEFVAR *TICK* 0 "A time-stamp, incremented whenever text is changed.")
(DEFVAR *BUFFER-LIST* nil)
(DEFVAR *BUFFER-COUNTER* 0)

;;; Special Variables bound only inside editor process:
(DEFVAR *BUFFER* :unbound "The buffer which is being edited.")
(DEFVAR *POINT-LINE* :UNBOUND "The point line of *BUFFER*.")
(DEFVAR *POINT-CHAR* :UNBOUND "The point char-count of *BUFFER*.")
(DEFVAR *MARK-LINE* :UNBOUND "The mark line of *BUFFER*.")
(DEFVAR *MARK-CHAR* :UNBOUND "The mark char-count of *BUFFER*.")
(DEFVAR *NUMERIC-ARG* :unbound "The value of the numeric argument, or NIL.")
(DEFVAR *LAST-COMMAND-TYPE* :unbound "The TYPE of the previous command executed.")
(DEFVAR *LINE-GOAL-XPOS* :unbound
  "Hpos in characters used as the goal by line up and down commands.")
(defvar *TOP-LINE* :unbound "Top line displayed on screen.")
(defvar *FIRST-LINE* :unbound "FIRST of buffer's linked list of lines.")
(defvar *LAST-LINE* :unbound "LAST of buffer's linked list of lines.")

(defstruct (buffer (:alterant nil))
  ;; These are slots for values SAVED when changing buffers.  For ordinary
  ;;  operations within a buffer the corresponding special variables are
  ;;  manipulated instead
  (buffer-point-line nil :documentation "POINT line pointer.")
  (buffer-point-char nil :documentation "POINT character count.")
  (buffer-mark-line nil :documentation "MARK line pointer.")
  (buffer-mark-char nil :documentation "MARK character count.")
  (buffer-top-line nil :documentation "Pointer to TOP-LINE displayed on screen.")
  (buffer-first-line nil :documentation "Pointer to FIRST-LINE of buffer.")
  (buffer-last-line nil :documentation "Pointer to LAST-LINE of buffer.")

(DEFSTRUCT (LINE :ARRAY-LEADER (:ALTERANT NIL))
  (LINE-LENGTH 0 :DOCUMENTATION "Number of characters in line (fill-pointer).")
  (LINE-NEXT NIL :DOCUMENTATION "Following line in buffer, or NIL if none.")
  (LINE-PREV NIL :DOCUMENTATION "Preceeding line in buffer, or NIL if none.")
  (LINE-TICK NIL :DOCUMENTATION "Tick at which this line was last modified.")
  (line-code1 nil :documentation "Encoded line contents for search ops.")
  (line-code2 nil :documentation "Encoded line contents for search ops.")
  (line-code3 nil :documentation "Encoded line contents for search ops.")
  (LINE-PLIST NIL :DOCUMENTATION "Plist of line properties.")
  )

(DEFSTRUCT (BP :LIST (:ALTERANT NIL))
  (BP-LINE NIL :DOCUMENTATION "Line to which this bp points.")
  (BP-INDEX NIL :DOCUMENTATION "Character position in line at which this bp points.")
  )

(DEFUN CREATE-LINE (length)
  (MAKE-LINE :MAKE-ARRAY (:element-type 'STRING-CHAR :LENGTH length)
	     :LINE-TICK *TICK*
	     :LINE-LENGTH length))

(defun emacs0 (&aux *BUFFER* *POINT-LINE* *POINT-CHAR* *MARK-LINE* *MARK-CHAR*
	       *NUMERIC-ARG* *LAST-COMMAND-TYPE* *LINE-GOAL-XPOS* *TOP-LINE*)
  (do ((char (read-char) (read-char)))

;;; End.
