Browse code
refactor: move replace-char, add print-object method
Edward authored on 25/02/2021 11:22:19
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -12,16 +12,6 @@ |
12 | 12 |
(defgeneric apply-edits (base operations)) |
13 | 13 |
|
14 | 14 |
|
15 |
-(fw.lu:defclass+ replace-char () |
|
16 |
- ((%point :initarg :point :accessor point) |
|
17 |
- (%value :initarg :value :reader value))) |
|
18 |
-(defmethod transform-for-op ((op replace-char)) |
|
19 |
- (let ((point (point op)) |
|
20 |
- (insert-length (length (value op)))) |
|
21 |
- (lambda (new-point) |
|
22 |
- (if (<= new-point point) |
|
23 |
- new-point |
|
24 |
- (+ new-point -1 insert-length))))) |
|
25 | 15 |
|
26 | 16 |
(fw.lu:defclass+ insert () |
27 | 17 |
((%point :initarg :point :accessor point) |
... | ... |
@@ -56,6 +46,20 @@ |
56 | 46 |
(string-to-edit base) (do-insert string-to-edit (value operation) (point operation)) |
57 | 47 |
(transform base) (alexandria:compose (transform-for-op operation) current-transform)) |
58 | 48 |
base)) |
49 |
+ |
|
50 |
+(fw.lu:defclass+ replace-char (op) |
|
51 |
+ ((%point :initarg :point :accessor point) |
|
52 |
+ (%value :initarg :value :reader value))) |
|
53 |
+(defmethod print-object ((o replace-char) s) |
|
54 |
+ (print-unreadable-object (o s :type t :identity t) |
|
55 |
+ (format s "~d/~d" (point o) (epoch o)))) |
|
56 |
+(defmethod transform-for-op ((op replace-char)) |
|
57 |
+ (let ((point (point op)) |
|
58 |
+ (insert-length (length (value op)))) |
|
59 |
+ (lambda (new-point) |
|
60 |
+ (if (<= new-point point) |
|
61 |
+ new-point |
|
62 |
+ (+ new-point -1 insert-length))))) |
|
59 | 63 |
(defun do-replace-char (base new point) |
60 | 64 |
(let ((begin (subseq base 0 point)) |
61 | 65 |
(end (subseq base (1+ point)))) |