From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Print out my key-sequences
Date: Tue, 25 May 2010 00:47:59 -0600 [thread overview]
Message-ID: <htfrr4$bb6$1@dough.gmane.org> (raw)
In-Reply-To: <m17hmtut2w.fsf@gmail.com>
Andrea Crotti wrote:
> Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
>
>> this-command-keys can return a vector containing elements other than
>> integers (characters) e.g. symbols for function keys and mouse events. And
>> the vector can contain integers that cannot be put into a string. See
>> the Strings of Events node of the Emacs Lisp manual.
>>
>> So first you have to find a robust way of converting the result of
>> this-command-keys to a string, so it can incorporated into the COMMAND
>> string argument to shell-command. As Lennart suggested, key-description
>> is probably the way to go.
>>
>> And passing an arbitrary string as an argument to a program via
>> shell-command is itself risky, if it may contain a shell metacharacters
>> (which seems quite likely in this case). So the string should be escaped
>> using shell-quote-argument, or you could use call-process instead of
>> shell-command to avoid the quoting issue.
>>
>> So:
>>
>> (defun growl-popup (msg)
>> "Pop up a growl notification with MSG, or display an Emacs message.
>> The \"growlnotify\" program is used if `window-system' is non-nil and
>> the program is found in `exec-path'; otherwise `message' is used."
>> (interactive)
>> (if (and window-system (executable-find "growlnotify"))
>> (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m "
>> (shell-quote-argument msg)))
>> (message msg)))
Oops, that should be (message "%s" msg)
>> (defun popup-last ()
>> (interactive)
>> (growl-popup (key-description (this-command-keys))))
>
>
> That's really nice thanks, I've added it to my configuration, with also
> two functions to enable/disable it.
>
> I have to use setq-default to disable it by the way, is that correct?
> --8<---------------cut here---------------start------------->8---
> (defun growl-mode-off ()
> (interactive)
> (setq-default pre-command-hook (remq 'popup-last pre-command-hook)))
> --8<---------------cut here---------------end--------------->8---
>
> Only one more problem, here I display all the keys, but I don't really
> care about stuff like
> "C-n", "C-p", "m" (all the keys are inserted).
>
> Is there any kind of distinction between simple and more complex
> combinations?
How about:
(unless (= (length (this-command-keys-vector)) 1)
...)
or:
(unless (eq (lookup-key global-map (this-command-keys)) this-command)
...)
or both:
(unless (and (= (length (this-command-keys-vector)) 1)
(eq (lookup-key global-map (this-command-keys)) this-command))
...)
--
Kevin Rodgers
Denver, Colorado, USA
next prev parent reply other threads:[~2010-05-25 6:47 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-07 14:09 Print out my key-sequences Andrea Crotti
2010-04-07 14:23 ` Peter Dyballa
2010-04-07 14:43 ` Andrea Crotti
2010-04-07 15:07 ` suvayu ali
2010-04-08 8:44 ` Andrea Crotti
2010-04-10 5:47 ` Suvayu Ali
2010-04-17 10:11 ` Andrea Crotti
2010-04-17 15:58 ` Kevin Rodgers
2010-04-17 18:59 ` Andrea Crotti
2010-04-17 19:27 ` Lennart Borgman
2010-04-17 22:06 ` Andrea Crotti
2010-04-17 22:12 ` Drew Adams
2010-04-17 22:16 ` Drew Adams
2010-04-17 23:00 ` Lennart Borgman
2010-04-18 8:47 ` Andrea Crotti
2010-04-18 9:01 ` Andrea Crotti
2010-04-18 11:13 ` Lennart Borgman
2010-04-18 14:16 ` Andrea Crotti
2010-04-18 14:59 ` Thierry Volpiatto
2010-04-18 16:09 ` Lennart Borgman
2010-04-21 7:09 ` Kevin Rodgers
2010-05-24 17:07 ` Andrea Crotti
2010-05-24 18:02 ` Andrea Crotti
2010-05-25 6:47 ` Kevin Rodgers [this message]
2010-05-31 22:30 ` Andrea Crotti
2010-04-07 15:46 ` Thierry Volpiatto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='htfrr4$bb6$1@dough.gmane.org' \
--to=kevin.d.rodgers@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.