The following example is based, in part, on the idea used by set-transient-map
; however, this example uses a local
keymap that is only active on certain text within a buffer that was set with a text-property: 'local-map tda--dynamic-map
Q: How can the original keymap be restored automatically if the user presses any key other than: up
, down
or SPC
?
[Assumption: The user will be at a buffer position containing the active local keymap.]
(let ((var-one t)
(var-two "foo"))
(message "Do something first.")
(let ((primary-func
`(lambda ()
(message "This is the primary-func.")))
(secondary-func
`(lambda ()
(define-key tda-dynamic--map " " #'original-function-one)
(define-key tda-dynamic--map [up] #'original-function-two)
(define-key tda-dynamic--map [down] #'original-function-three)
(message "This is the secondary-func."))))
(define-key tda-dynamic--map " "
`(lambda ()
(interactive)
(funcall ,secondary-func)))
(define-key tda-dynamic--map [up]
`(lambda ( )
(interactive)
(funcall ,primary-func)))
(define-key tda-dynamic--map [down]
`(lambda ( )
(interactive)
(funcall ,primary-func)))))
let
andmessage
but I've no idea why you have those -- they seem totally irrelevant to the question. – phils Mar 26 '22 at 03:02secondary-func
, in my setup, does more than just restore the original keymap ... it is essentially a finishing / wrap-it-up function that does some additional things ... and I truncated that to just a message for simplicity purposes. It is, however, not essential to the minimal working example ... so you are correct. – lawlist Mar 26 '22 at 03:06