-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersistent-undo.lisp
executable file
·50 lines (40 loc) · 1.66 KB
/
persistent-undo.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
;;; -*- mode: lisp -*-
;;;
;;; (c) copyright 2005 by Aleksandar Bakic (a_bakic@yahoo.com)
;;;
;;; Part of the Undo protocol that works with persistent buffers
(in-package :climacs-pane)
(defclass p-undo-mixin ()
((tree :initform (make-instance 'standard-undo-tree) :reader undo-tree)
(undo-accumulate :initform '() :accessor undo-accumulate)
(performing-undo :initform nil :accessor performing-undo)))
(defclass p-undo-record (climacs-undo-record)
((contents :initarg :contents)))
(defun save-p-undo-record (buffer)
(unless (performing-undo buffer)
(push (make-instance
'p-undo-record
:buffer buffer
:contents (slot-value buffer 'climacs-buffer::contents))
(undo-accumulate buffer))))
(defmethod insert-buffer-object :before ((buffer p-undo-mixin) offset object)
(declare (ignore offset object))
(save-p-undo-record buffer))
(defmethod insert-buffer-sequence :before ((buffer p-undo-mixin) offset seq)
(declare (ignore offset seq))
(save-p-undo-record buffer))
(defmethod delete-buffer-range :before ((buffer p-undo-mixin) offset n)
(declare (ignore offset n))
(save-p-undo-record buffer))
(defmethod (setf buffer-object) :before (object (buffer p-undo-mixin) offset)
(declare (ignore object offset))
(save-p-undo-record buffer))
(defmethod flip-undo-record ((record p-undo-record))
(with-slots (buffer contents) record
(setf (slot-value buffer 'climacs-buffer::contents) contents)
(climacs-buffer::filter-and-update
(climacs-buffer::cursors buffer)
#'(lambda (c) (flexichain::weak-pointer-value c buffer))
#'(lambda (wpc)
(setf (cursor-pos wpc)
(max 0 (min (cursor-pos wpc) (1- (size buffer)))))))))