unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Function to insert a key sequence
@ 2009-12-25  1:38 Deniz Dogan
  2009-12-25  3:29 ` Lennart Borgman
  2009-12-26 22:14 ` Jeff Kowalczyk
  0 siblings, 2 replies; 5+ messages in thread
From: Deniz Dogan @ 2009-12-25  1:38 UTC (permalink / raw)
  To: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 248 bytes --]

Attached is a little function for inserting a key sequence entered by
the user into the current buffer. I don't know if it fits into any
existing Emacs library, but I find it quite useful, so I thought I'd
just throw it out there.

-- 
Deniz Dogan

[-- Attachment #2: insert-key-sequence.el --]
[-- Type: application/octet-stream, Size: 504 bytes --]

(defun insert-key-sequence ()
  "Reads a sequence of keys until C-g is hit, and inserts the
prettified key sequence with C-g excluded."
  (interactive "*")
  (let ((result "")
        key)
    (while (progn
             (setq key (read-key "Enter the key sequence: "))
             (unless (eq 7 key)
               (setq result (concat result (key-description (list key)) " ")))
             (not (eq 7 key))))
    (when (not (string= result ""))
      (insert result)
      (backward-delete-char 1))))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Function to insert a key sequence
  2009-12-25  1:38 Function to insert a key sequence Deniz Dogan
@ 2009-12-25  3:29 ` Lennart Borgman
  2009-12-25 13:34   ` Deniz Dogan
  2009-12-26 22:14 ` Jeff Kowalczyk
  1 sibling, 1 reply; 5+ messages in thread
From: Lennart Borgman @ 2009-12-25  3:29 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: Emacs-Devel devel

On Fri, Dec 25, 2009 at 2:38 AM, Deniz Dogan <deniz.a.m.dogan@gmail.com> wrote:
> Attached is a little function for inserting a key sequence entered by
> the user into the current buffer. I don't know if it fits into any
> existing Emacs library, but I find it quite useful, so I thought I'd
> just throw it out there.


When do you find it useful? I think there are some a bit similar
functionality in the  key-sequence widget - at least in the version I
have in ourcomments-widgets.el.


If it is not deemed to be interesting enough for most Emacs users you
could perhaps put it on EmacsWiki where other users can find it?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Function to insert a key sequence
  2009-12-25  3:29 ` Lennart Borgman
@ 2009-12-25 13:34   ` Deniz Dogan
  0 siblings, 0 replies; 5+ messages in thread
From: Deniz Dogan @ 2009-12-25 13:34 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: Emacs-Devel devel

2009/12/25 Lennart Borgman <lennart.borgman@gmail.com>:
> On Fri, Dec 25, 2009 at 2:38 AM, Deniz Dogan <deniz.a.m.dogan@gmail.com> wrote:
>> Attached is a little function for inserting a key sequence entered by
>> the user into the current buffer. I don't know if it fits into any
>> existing Emacs library, but I find it quite useful, so I thought I'd
>> just throw it out there.
>
>
> When do you find it useful? I think there are some a bit similar
> functionality in the  key-sequence widget - at least in the version I
> have in ourcomments-widgets.el.
>
>
> If it is not deemed to be interesting enough for most Emacs users you
> could perhaps put it on EmacsWiki where other users can find it?
>

Now that I think of it, maybe it's not all that useful after all. I
just thought it could be of some help when binding keys using `kbd',
to make sure the string argument is correctly formatted.

I personally could use it in conversations in #emacs when trying to
explain example uses of keybindings, especially when entering macros.
Example: C-x ( M-m C-SPC M-f M-f M-b C-w C-e SPC C-y DEL C-n C-x )
(This particular macro would move the first word of the current line
to the end of the line and then move one line down.)

Needless to say the function definition could be improved further by
echoing the input as the user enters it.

-- 
Deniz Dogan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Function to insert a key sequence
  2009-12-25  1:38 Function to insert a key sequence Deniz Dogan
  2009-12-25  3:29 ` Lennart Borgman
@ 2009-12-26 22:14 ` Jeff Kowalczyk
  2009-12-27  1:51   ` Deniz Dogan
  1 sibling, 1 reply; 5+ messages in thread
From: Jeff Kowalczyk @ 2009-12-26 22:14 UTC (permalink / raw)
  To: emacs-devel

Deniz Dogan <deniz.a.m.dogan <at> gmail.com> writes:
> Attached is a little function for inserting a key sequence entered by
> the user into the current buffer. I don't know if it fits into any
> existing Emacs library, but I find it quite useful, so I thought I'd
> just throw it out there.

Deniz,

Thanks, this function is interesting. It could be useful in tools like
ScreencastMode [1].

Is this version intended for use with Emacs 23? I had to change read-key to
read-key-sequence to get the prompt, but the function does not exit on C-g:


(defun insert-key-sequence ()
  "Reads a sequence of keys until C-g is hit, and inserts the
prettified key sequence with C-g excluded."
  (interactive)
  (let ((result "")
        key)
    (while (progn
             (setq key (read-key-sequence "Enter the key sequence: "))
             (unless (eq 7 key)
               (setq result (concat result (key-description (list key)) " ")))
             (not (eq 7 key))))
    (when (not (string= result ""))
      (insert result)
      (backward-delete-char 1))))


Thanks,
Jeff

[1] http://www.emacswiki.org/emacs/ScreencastMode





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Function to insert a key sequence
  2009-12-26 22:14 ` Jeff Kowalczyk
@ 2009-12-27  1:51   ` Deniz Dogan
  0 siblings, 0 replies; 5+ messages in thread
From: Deniz Dogan @ 2009-12-27  1:51 UTC (permalink / raw)
  To: Jeff Kowalczyk; +Cc: emacs-devel

2009/12/26 Jeff Kowalczyk <jtk@yahoo.com>:
> Deniz Dogan <deniz.a.m.dogan <at> gmail.com> writes:
>> Attached is a little function for inserting a key sequence entered by
>> the user into the current buffer. I don't know if it fits into any
>> existing Emacs library, but I find it quite useful, so I thought I'd
>> just throw it out there.
>
> Deniz,
>
> Thanks, this function is interesting. It could be useful in tools like
> ScreencastMode [1].
>
> Is this version intended for use with Emacs 23? I had to change read-key to
> read-key-sequence to get the prompt, but the function does not exit on C-g:
>

Yes, it is intended for use with Emacs 23.

read-key is a compiled Lisp function in `subr.el'.

(read-key &optional PROMPT)

Read a key from the keyboard.
Contrary to `read-event' this will not return a raw event but instead will
obey the input decoding and translations usually done by `read-key-sequence'.
So escape sequences and keyboard encoding are taken into account.
When there's an ambiguity because the key looks like the prefix of
some sort of escape sequence, the ambiguity is resolved via `read-key-delay'.

According to the CVS log, it was added on August 19 2009 by Stefan
Monnier (revision 1.644). That said, I don't know off-hand how to make
the function work without read-key.

-- 
Deniz Dogan




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-12-27  1:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-25  1:38 Function to insert a key sequence Deniz Dogan
2009-12-25  3:29 ` Lennart Borgman
2009-12-25 13:34   ` Deniz Dogan
2009-12-26 22:14 ` Jeff Kowalczyk
2009-12-27  1:51   ` Deniz Dogan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).