[Top][All Lists]

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

Re: Print out my key-sequences

From: Kevin Rodgers
Subject: Re: Print out my key-sequences
Date: Wed, 21 Apr 2010 01:09:59 -0600
User-agent: Thunderbird (Macintosh/20100228)

Andrea Crotti wrote:
Lennart Borgman <> writes:

On Sun, Apr 18, 2010 at 11:01 AM, Andrea Crotti

last-command => this-command-keys, this-command-keys-vector

You can find this information by searching in the elisp manual with
isearch for "last-command".

See also key-description.

Great I think this is what I was looking for : (this-command-keys)

Now I have this but I'm still getting an error
--8<---------------cut here---------------start------------->8---
(defun growl-popup (msg)
  "Show a popup using growl notification or say it, only working on OSX with 
growlnotify in the $PATH"
  (if window-system
      (shell-command (concat "growlnotify -a /Applications/ -m " msg))
    (message msg)))

(defun popup-last ()
  (growl-popup (this-command-keys)))
--8<---------------cut here---------------end--------------->8---

What doest that supposed to mean?
The function this-command-keys is returning a string, and growl-popup is
working just fine, so what could be the problem again?

this-command-keys may return a string or a vector, but concat returns a

--8<---------------cut here---------------start------------->8---
(Shell command killed by signal Trace/BPT trap)
--8<---------------cut here---------------end--------------->8---

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.


(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."
  (if (and window-system (executable-find "growlnotify"))
      (shell-command (concat "growlnotify -a /Applications/ -m "
                             (shell-quote-argument msg)))
    (message msg)))

(defun popup-last ()
  (growl-popup (key-description (this-command-keys))))

Kevin Rodgers
Denver, Colorado, USA

reply via email to

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