I wonder what is wrong with the following code?
(defvar my-forward-word-map (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'forward-word) (define-key map (kbd "p") 'my-backward-word) map)) (defvar my-backward-word-map (let ((map (make-sparse-keymap))) (define-key map (kbd "p") 'backward-word) (define-key map (kbd "n") 'my-forward-word) map)) (defun my-forward-word () (interactive) (set-transient-map my-forward-word-map t)) (defun my-backward-word () (interactive) (set-transient-map my-backward-word-map t)) (global-set-key (kbd "M-n") 'my-forward-word) (global-set-key (kbd "M-p") 'my-backward-word)
There is a buffer with the text: |Hello world
. |
- this is cursor.
I press M-n
, n
. I get Hello| world
as I expected.
Then I press p
, p
. I get |Hello world
as was previously. And that's fine.
But when I press n
again nothing happens i.e. cursor doesn't change its position no matter how many time I press n
.
After n
and n
I expected to get Hello| world
.
What's wrong?
$ emacs --version GNU Emacs 24.4.1
set-transient-map
(which ist
here) means to keep the map active as long as the user hits keys in the map, so we end up activing both maps and then activating them commulatively, which is not going to work right. – Stefan Mar 29 '15 at 04:30t
meaning keep is of course documented. But activating the map (hence both maps apparently, in this case) seems quite a different verb from setting the transient map. Apparently now that phrase means activating *a* transient map? So there can be more than one "transient*" map? And in that case this seems like an incompatible change, which presumably should have been documented in the NEWS for Emacs 24.4. Emacs 24.3 does not behave this way, in any case. Could you perhaps give a use case for multiple active transient maps? – Drew Mar 29 '15 at 14:28M-n n C-u 5 n
. TheC-u
now usesset-transient-map
. – Stefan Mar 29 '15 at 14:34C-u
now usesset-transient-map
, but OK. In that case, I suggest that you document the fact that this is not about setting the transient map but is about setting a transient map. IOW, document explicitly that there can be multiple (any number of?) transient maps, and describe how they interact (e.g. order). And it wouldn't hurt to provide such a use case in the doc, to motivate this feature. It's too bad that this wasn't done when this was introduced (and wasn't called out in NEWS). – Drew Mar 29 '15 at 14:47keyboard-escape-quit
before setting transient map but that doesn't help. – Andrii Tykhonov Mar 29 '15 at 20:26backward-word
andforward-word
and that's it. – Stefan Mar 29 '15 at 20:29keep=nil
) and that command sets the next map. – Stefan Mar 29 '15 at 23:52set-transient-map
. – Andrii Tykhonov Mar 30 '15 at 09:04