From 1d3800a7cd2be55d5bf2ac0ba6ef8502161da97b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 19 Jun 2022 15:46:20 +0530 Subject: Hook undo stroke into Emacs' undo system. * thogai.el (thogai-process-stroke): Hook undo stroke into Emacs' undo system. --- thogai.el | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/thogai.el b/thogai.el index 1fc350f..2a4fa57 100644 --- a/thogai.el +++ b/thogai.el @@ -450,24 +450,15 @@ STROKES is injected first." Process the most recent stroke, and insert its translation or execute a command. STROKE-RING is the ring representing the current state, and should typically be `thogai-stroke-ring'." + (undo-boundary) (if (string= (ring-ref stroke-ring 0) "*") ;; Special case to handle the undo operation (progn - ;; Drop the "*" stroke from the state ring. - (ring-remove stroke-ring 0) - (let ((matched-strokes - (or (thogai-longest-match (reverse (ring-elements stroke-ring))) - (list (ring-ref stroke-ring 0))))) - ;; Reverse the previous group of strokes. - (thogai-reverse-strokes matched-strokes) - ;; Re-insert the previous group of strokes except for the - ;; newest stroke. - (pcase (reverse matched-strokes) - (`(,_ . ,other-strokes) - (thogai-inject-strokes (reverse other-strokes) - (make-ring (length other-strokes)))))) - ;; Remove the newest stroke from the state ring. - (ring-remove stroke-ring 0)) + (undo-only) + ;; Drop the "*" stroke and the stroke that was just undone. + (dotimes (i 2) + (unless (zerop (ring-length stroke-ring)) + (ring-remove stroke-ring 0)))) (let ((matched-strokes (thogai-longest-match (reverse (ring-elements stroke-ring))))) ;; Delete translation for earlier strokes that are captured by -- cgit v1.2.3