Skip to content
Browse files

Added operation classes for point, range, cursor and selection

* rudel-operations.el (header): updated copyright; fixed and extended
  commentary section; bumped version to 0.2
  (rudel-point-operation): new abstract class; base class for
  point-type operations
  (rudel-range-operation): new abstract class; base class for
  range-type operations
  (rudel-insert-op): now subclass of rudel-point-operation
  (rudel-delete-op): now subclass of rudel-range-operation
  (rudel-delete-op::slot-missing): moved to `rudel-range-op'
  (rudel-move-cursor-op): new class; objects represent cursor
  movements
  (rudel-move-selection-op): new class; objects represent movements of
  the selection
  • Loading branch information...
1 parent 399536c commit 789c675a5fd08724fce7e8d9f50a7727dbe7886c @scymtym committed Feb 2, 2010
Showing with 87 additions and 33 deletions.
  1. +87 −33 rudel-operations.el
View
120 rudel-operations.el
@@ -1,6 +1,6 @@
;;; rudel-operations.el --- Rudel domain operations
;;
-;; Copyright (C) 2009 Jan Moringen
+;; Copyright (C) 2009, 2010 Jan Moringen
;;
;; Author: Jan Moringen <scymtym@users.sourceforge.net>
;; Keywords: Rudel, operations
@@ -25,13 +25,23 @@
;;; Commentary:
;;
;; This file contains classes representing operations like insertions
-;; and deletions, that are import for Rudel's domain of collaborative
-;; editing.
+;; and deletions, that are important for Rudel's domain of
+;; collaborative editing.
+;;
+;; Currently the following operations are available:
+;;
+;; + `rudel-operation' (abstract base class)
+;; + `rudel-insert-op'
+;; + `rudel-delete-op'
+;; + `rudel-move-cursor-op'
+;; + `rudel-move-selection-op'
;;; History:
;;
-;; 0.1 - Initial revision
+;; 0.2 - Added cursor and selection operations
+;;
+;; 0.1 - Initial version
;;; Code:
@@ -52,17 +62,56 @@
"Apply the change represented by THIS to OBJECT.")
-;;; Class rudel-insert-op
+;;; Class rudel-point-operation
;;
-;; TODO should be rudel-insert but there is a method of the same name
-(defclass rudel-insert-op (rudel-operation)
+(defclass rudel-point-operation (rudel-operation)
((from :initarg :from
:type (or null (integer 0))
:documentation
- "Start of the region affected by this operation or
-nil. nil means end of buffer")
- (data :initarg :data
+ "Position affected by this operation or nil. nil means
+end of buffer"))
+ ""
+ :abstract t)
+
+
+;;; Class rudel-range-operation
+;;
+
+(defclass rudel-range-operation (rudel-operation)
+ ((from :initarg :from
+ :type (integer 0)
+ :documentation
+ "Start of the region affected by this operation.")
+ (to :initarg :to
+ :type (integer 0)
+ :documentation
+ "End of the region affected by this operation."))
+ ""
+ :abstract t)
+
+(defmethod slot-missing ((this rudel-range-operation)
+ slot-name operation &optional new-value)
+ "Simulate slot :length"
+ (cond
+ ;; Slot :length
+ ((or (eq slot-name :length)
+ (eq slot-name 'length))
+ (with-slots (from to) this
+ (if (eq operation 'oref)
+ (- to from)
+ (setq to (+ from new-value)))))
+ ;; Call next method
+ (t (call-next-method)))
+ )
+
+
+;;; Class rudel-insert-op
+;;
+
+;; TODO should be rudel-insert but there is a method of the same name
+(defclass rudel-insert-op (rudel-point-operation)
+ ((data :initarg :data
:type string
:documentation
"The inserted string."))
@@ -98,36 +147,41 @@ nil. nil means end of buffer")
;;
;; TODO should be rudel-delete but there is a method of the same name
-(defclass rudel-delete-op (rudel-operation)
- ((from :initarg :from
- :type (integer 0)
- :documentation
- "Start of the region affected by this operation.")
- (to :initarg :to
- :type (integer 0)
- :documentation
- "End of the region affected by this operation."))
+(defclass rudel-delete-op (rudel-range-operation)
+ ()
"Objects of this class represent deletion operations.")
(defmethod rudel-apply ((this rudel-delete-op) object)
"Apply THIS to OBJECT by deleting the associated region."
(with-slots (from length) this
(rudel-delete object from length)))
-(defmethod slot-missing ((this rudel-delete-op)
- slot-name operation &optional new-value)
- "Simulate slot :length"
- (cond
- ;; Slot :length
- ((or (eq slot-name :length)
- (eq slot-name 'length))
- (with-slots (from to) this
- (if (eq operation 'oref)
- (- to from)
- (setq to (+ from new-value)))))
- ;; Call next method
- (t (call-next-method)))
- )
+
+;;; Class rudel-move-cursor-op
+;;
+
+(defclass rudel-move-cursor-op (rudel-point-operation)
+ ()
+ "Objects of this class represent cursor movements.")
+
+(defmethod rudel-apply ((this rudel-move-cursor-op) object)
+ "Apply THIS to OBJECT by changing the position of one user's cursor."
+ (with-slots (from) this
+ (rudel-move-cursor object from)))
+
+
+;;; Class rudel-move-selection-op
+;;
+
+(defclass rudel-move-selection-op (rudel-range-operation)
+ ()
+ "Objects of this class represent changes of users'
+selections.")
+
+(defmethod rudel-apply ((this rudel-move-selection-op) object)
+ "Apply THIS to OBJECT by changing one user's selection."
+ (with-slots (from to) this
+ (rudel-move-selection object from to)))
(provide 'rudel-operations)
;;; rudel-operations.el ends here

0 comments on commit 789c675

Please sign in to comment.
Something went wrong with that request. Please try again.