Skip to content

Commit f5e5c6e

Browse files
committed
Use read-kbd-macro to make playback consistent
Had some issues, especially with characters like TAB not being interpreted correctly. This lead to a lengthy confirmation of a lot of behavior, ulimately switching to `read-kbd-macro' and getting rid of the motivating issue without much of a fight. As a result, no translation is used and we are back at a more straightforward world.
1 parent 080d95f commit f5e5c6e

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

NEWS.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Fixing bugs and filling some gaps in new features.
2828
- Keyboard macro backward steps are implemented
2929
- ~dslide-deck-forward~ no longer no-ops in some circumstances
3030
- kmacro action properly skips over non-matching directions when both forward and backward elements are present in a slide
31-
- 🚧 kmacro transcription of =M-RET= and =M-DEL= is now correct. There are likely more events that don't round trip nicely from ~last-kbd-macro~ through ~key-description~ and back through ~kbd~. *File issues*.
31+
- 🚧 kmacro playback of =M-<return>= and =M-<backspace>= and others is now correct. There are likely more events that don't round trip nicely from ~last-kbd-macro~ through ~key-description~ and back through ~read-kbd-macro~. *File issues*.
3232
* v0.6.0 Fighting Spam 💌
3333
- There is less markup (especially for babel)
3434
- Old actions are easier to use

dslide.el

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,7 @@ Optional NO-DIRECTION will match unlabelled kmacros."
20312031
(params (dslide-read-plist value)))
20322032
(let ((events (or (plist-get params :events)
20332033
(if-let ((keys (plist-get params :keys)))
2034-
(kbd keys)
2034+
(read-kbd-macro keys)
20352035
(error "No keys or events at %s"
20362036
(without-restriction
20372037
(line-number-at-pos
@@ -2046,14 +2046,14 @@ Optional NO-DIRECTION will match unlabelled kmacros."
20462046

20472047
(cl-defmethod dslide-backward ((obj dslide-action-kmacro))
20482048
(when dslide--kmacro-timer
2049-
(user-error "Dslide keboard macro already running"))
2049+
(user-error "Dslide keyboard macro already running"))
20502050
(when-let* ((keyword (dslide-section-previous
20512051
obj 'keyword (dslide--kmacro-predicate 'backward)))
20522052
(value (org-element-property :value keyword))
20532053
(params (dslide-read-plist value)))
20542054
(let ((events (or (plist-get params :events)
20552055
(if-let ((keys (plist-get params :keys)))
2056-
(kbd keys)
2056+
(read-kbd-macro keys)
20572057
(error "No keys or events at %s"
20582058
(without-restriction
20592059
(line-number-at-pos
@@ -2084,7 +2084,10 @@ some other input event and quit."
20842084
(if (eq last-input last-input-event)
20852085
(if (length> events index)
20862086
(let ((k (aref events index)))
2087-
(setq unread-command-events (list k))
2087+
(setq unread-command-events (if unread-command-events
2088+
(append unread-command-events
2089+
(cons k))
2090+
(cons k)))
20882091
(setq dslide--kmacro-timer
20892092
(run-with-timer
20902093
(dslide--laplace-jitter frequency jitter)
@@ -3124,14 +3127,6 @@ for commands without visible side effects."
31243127
(unless dslide--kmacro-transcribe-mark
31253128
(dslide-kmacro-transcribe-quit))
31263129
(when-let ((macro last-kbd-macro))
3127-
;; TODO I have forgotten the full list of events that can be recorded in
3128-
;; `last-kbd-macro' but do not properly round-trip through
3129-
;; `key-description' and back through `kbd'. Pretty sure it's small.
3130-
(cl-loop for i from 0 below (length macro)
3131-
do (let ((key (aref macro i)))
3132-
(pcase key
3133-
('M-return (aset macro i 134217741))
3134-
('M-backspace (aset macro i 134217855)))))
31353130
;; TODO seems like kmacro-end-macro is smart enough that we don't need to
31363131
;; check this
31373132
(if (eq macro dslide--kmacro-transcribe-last)

test/macro.org

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,24 @@ This is the best thing since 🔪🍞
2929

3030
# Go forward with no direction
3131
#+dslide_kmacro: :keys "M-x n o d i r e c t i o n"
32+
* Play Funky
33+
#+begin_comment
34+
This macro is interpreted by ~kbd~ to a string, which will fail if used as a key sequence vector.
35+
#+end_comment
36+
#+dslide_kmacro: :keys "<tab>"
37+
- The content here will be folded when the macro plays successfully
3238
* COMMENT Closed Conversion
33-
Record something using =M-RET= and =M-DEL=.
39+
Record something using =M-<return>= and =M-<backspace>=.
3440

35-
# M-RET test
36-
#+dslide_kmacro: :keys "M-> M-RET"
41+
# M-<return> test
42+
#+dslide_kmacro: :keys "M-> M-<return>"
3743

3844
# Plays back after this point
45+
* Recording Strange Events
46+
- M-<return>
47+
- M-<backspace>
48+
- <backspace>
49+
- <return>
50+
...possibly many more
51+
# weird keys
52+
#+dslide_kmacro: :keys "M-<return> M-<backspace> a a a <backspace> <backspace> <backspace> <return> <return> <return> a a"

0 commit comments

Comments
 (0)