aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-19 15:46:20 +0530
committerArun Isaac2022-06-19 15:46:20 +0530
commit1d3800a7cd2be55d5bf2ac0ba6ef8502161da97b (patch)
tree4574e20e57ca08d850b125fae2fedb3dce63d587
parent779594b51d25c7940ac99a59a6f1319e2ce749b7 (diff)
downloadthogai-1d3800a7cd2be55d5bf2ac0ba6ef8502161da97b.tar.gz
thogai-1d3800a7cd2be55d5bf2ac0ba6ef8502161da97b.tar.lz
thogai-1d3800a7cd2be55d5bf2ac0ba6ef8502161da97b.zip
Hook undo stroke into Emacs' undo system.
* thogai.el (thogai-process-stroke): Hook undo stroke into Emacs' undo system.
-rw-r--r--thogai.el21
1 files 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