help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Print out my key-sequences


From: Andrea Crotti
Subject: Re: Print out my key-sequences
Date: Mon, 24 May 2010 19:07:19 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (darwin)

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)))
>
> (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?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]