Skip to content

Commit 9844ca1

Browse files
authored
Merge pull request #1034 from fukamachi/undo-boundary-control
Add a feature to disable undo boundary temporarily
2 parents ad5bf64 + ab34a31 commit 9844ca1

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

extensions/vi-mode/vi-mode.lisp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,13 @@
7676
(eq (vi-command-repeat command) nil))
7777
(eq (command-name (this-command)) 'vi-end-insert))
7878
(appendf *last-repeat-keys*
79-
(vi-this-command-keys))))
80-
(when (and (member (command-name command)
81-
'(self-insert
82-
;; XXX: lem:call-command always adds a undo boundary
83-
;; Delete the last boundary after these commands executed.
84-
vi-open-below
85-
vi-open-above)
86-
:test 'eq)
87-
(eq :separator (lem-base::last-edit-history (current-buffer))))
88-
(vector-pop (lem-base::buffer-edit-history (current-buffer))))))
79+
(vi-this-command-keys))))))
8980

9081
(defmethod state-enabled-hook ((state insert))
9182
(when *enable-repeat-recording*
9283
(setf *last-repeat-keys* nil))
93-
(buffer-undo-boundary))
84+
(buffer-undo-boundary)
85+
(buffer-disable-undo-boundary (lem:current-buffer)))
9486

9587
(defmethod state-disabled-hook ((state insert))
96-
(unless (eq :separator (lem-base::last-edit-history (current-buffer)))
97-
(buffer-undo-boundary)))
88+
(buffer-enable-undo-boundary (lem:current-buffer)))

src/base/buffer.lisp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
:initarg :%enable-undo-p
3232
:accessor buffer-%enable-undo-p
3333
:type boolean)
34+
(%enable-undo-boundary-p
35+
:initarg :%enable-undo-boundary-p
36+
:initform t
37+
:accessor buffer-%enable-undo-boundary-p)
3438
(read-only-p
3539
:initarg :read-only-p
3640
:accessor buffer-read-only-p
@@ -194,6 +198,17 @@ Options that can be specified by arguments are ignored if `temporary` is NIL and
194198
(setf (buffer-redo-stack buffer) nil)
195199
nil)
196200

201+
(defun buffer-enable-undo-boundary-p (&optional (buffer (current-buffer)))
202+
(buffer-%enable-undo-boundary-p buffer))
203+
204+
(defun buffer-enable-undo-boundary (buffer)
205+
(setf (buffer-%enable-undo-boundary-p buffer) t)
206+
nil)
207+
208+
(defun buffer-disable-undo-boundary (buffer)
209+
(setf (buffer-%enable-undo-boundary-p buffer) nil)
210+
nil)
211+
197212
(defmethod print-object ((buffer buffer) stream)
198213
(print-unreadable-object (buffer stream :identity t :type t)
199214
(format stream "~A ~A"
@@ -339,8 +354,9 @@ Options that can be specified by arguments are ignored if `temporary` is NIL and
339354
result0)))
340355

341356
(defun buffer-undo-boundary (&optional (buffer (current-buffer)))
342-
(unless (eq :separator (last-edit-history buffer))
343-
(vector-push-extend :separator (buffer-edit-history buffer))))
357+
(when (buffer-enable-undo-boundary-p)
358+
(unless (eq :separator (last-edit-history buffer))
359+
(vector-push-extend :separator (buffer-edit-history buffer)))))
344360

345361
(defun buffer-value (buffer name &optional default)
346362
"`buffer`のバッファ変数`name`に束縛されている値を返します。

src/base/package.lisp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
:buffer-undo
110110
:buffer-redo
111111
:buffer-undo-boundary
112+
:buffer-enable-undo-boundary
113+
:buffer-disable-undo-boundary
112114
:buffer-value
113115
:buffer-unbound
114116
:clear-buffer-variables)

0 commit comments

Comments
 (0)