* How to get in progress Key Sequence from Elisp
@ 2012-12-02 20:09 Barry OReilly
2012-12-02 21:15 ` Drew Adams
0 siblings, 1 reply; 3+ messages in thread
From: Barry OReilly @ 2012-12-02 20:09 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]
When I'm in the middle of inputting a Key Sequence, how may I get a data
structure with the Key Sequence entered thus far from Elisp?
More details: I create Key Translations that are contingent on the Evil
(Vim emulation) state. If in insert state, it's the idenity translation:
;; -*- lexical-binding: t -*-
(defun make-conditional-key-translation (key-from key-to translate-keys-p)
"Make a Key Translation such that if the translate-keys-p function
returns true,
key-from translates to key-to, else key-from translates to itself.
translate-keys-p
takes no args. "
(define-key key-translation-map key-from
(lambda (prompt)
(if (funcall translate-keys-p) key-to key-from))))
(defun my-translate-keys-p ()
"Returns whether conditional key translations should be active. See
make-conditional-key-translation function. "
(or (evil-motion-state-p) (evil-normal-state-p) (evil-visual-state-p)))
(make-conditional-key-translation (kbd "g") (kbd "C-x")
'my-translate-keys-p)
This works well, but one inconvenience is that for bindings like this:
(define-key evil-motion-state-map "sg" 'my-func)
"sg" gets translated into "s C-x". If I have my-translate-keys-p return
nil if not starting a Key Sequence, I will get the behavior I seek. I can
do this if I can get the Key Sequence as the user has been entered at that
time.
[-- Attachment #2: Type: text/html, Size: 1567 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: How to get in progress Key Sequence from Elisp
2012-12-02 20:09 How to get in progress Key Sequence from Elisp Barry OReilly
@ 2012-12-02 21:15 ` Drew Adams
2012-12-03 14:37 ` Barry OReilly
0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2012-12-02 21:15 UTC (permalink / raw)
To: 'Barry OReilly', 'help-gnu-emacs'
> When I'm in the middle of inputting a Key Sequence, how may
> I get a data structure with the Key Sequence entered thus
> far from Elisp?
> ...
> I can do this if I can get the Key Sequence as the user has
> been entered at that time.
If I understand what you are asking, see `this-command-keys'. E.g.:
(defun foo ()
"..."
(let* ((this-key (this-command-keys))
(prefix (substring
this-key
0 (1- (length this-key)))))
;; (message "PREFIX: %S, DESCRIPTION: %S"
;; prefix (key-description prefix))
prefix))
This is what I use in the code for Icicles key completion.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to get in progress Key Sequence from Elisp
2012-12-02 21:15 ` Drew Adams
@ 2012-12-03 14:37 ` Barry OReilly
0 siblings, 0 replies; 3+ messages in thread
From: Barry OReilly @ 2012-12-03 14:37 UTC (permalink / raw)
Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 805 bytes --]
That's exactly what I needed, thanks!
On Sun, Dec 2, 2012 at 4:15 PM, Drew Adams <drew.adams@oracle.com> wrote:
> > When I'm in the middle of inputting a Key Sequence, how may
> > I get a data structure with the Key Sequence entered thus
> > far from Elisp?
> > ...
> > I can do this if I can get the Key Sequence as the user has
> > been entered at that time.
>
> If I understand what you are asking, see `this-command-keys'. E.g.:
>
> (defun foo ()
> "..."
> (let* ((this-key (this-command-keys))
> (prefix (substring
> this-key
> 0 (1- (length this-key)))))
> ;; (message "PREFIX: %S, DESCRIPTION: %S"
> ;; prefix (key-description prefix))
> prefix))
>
> This is what I use in the code for Icicles key completion.
>
>
[-- Attachment #2: Type: text/html, Size: 1217 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-03 14:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-02 20:09 How to get in progress Key Sequence from Elisp Barry OReilly
2012-12-02 21:15 ` Drew Adams
2012-12-03 14:37 ` Barry OReilly
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).