unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Print out my key-sequences
@ 2010-04-07 14:09 Andrea Crotti
  2010-04-07 14:23 ` Peter Dyballa
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-07 14:09 UTC (permalink / raw)
  To: help-gnu-emacs


I will have to do a presentation using Emacs in May, using Carbon Emacs
23 on OSX 10.6.
It would be really that while I type and do something it appears on the
screen what key-sequences I'm doing (C-M x C-c C-x C-o or whatever).

I know already that is possible to get the key sequences, what could be
a good way to show them?
Maybe using something like growl?

I looked for something useful some time ago but no luck...
Thanks





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

* Re: Print out my key-sequences
  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
  0 siblings, 1 reply; 26+ messages in thread
From: Peter Dyballa @ 2010-04-07 14:23 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs


Am 07.04.2010 um 16:09 schrieb Andrea Crotti:

> I know already that is possible to get the key sequences, what could  
> be
> a good way to show them?

C-h l ?

--
Greetings

   Pete

If you're not confused, you're not paying attention.





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

* Re: Print out my key-sequences
  2010-04-07 14:23 ` Peter Dyballa
@ 2010-04-07 14:43   ` Andrea Crotti
  2010-04-07 15:07     ` suvayu ali
  2010-04-07 15:46     ` Thierry Volpiatto
  0 siblings, 2 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-04-07 14:43 UTC (permalink / raw)
  To: help-gnu-emacs

Peter Dyballa <Peter_Dyballa@Web.DE> writes:
>
> C-h l ?

Oh great I don't know how I've never seen it...
But that shows the keystrokes in another buffer, I would like to 
- record the keystrokes while I type
- filter only the interesting ones (Meta and Control stuff)
- send them to some other program to display it nicely (I think growl
  could be perfect for that with applescript)





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

* Re: Print out my key-sequences
  2010-04-07 14:43   ` Andrea Crotti
@ 2010-04-07 15:07     ` suvayu ali
  2010-04-08  8:44       ` Andrea Crotti
  2010-04-07 15:46     ` Thierry Volpiatto
  1 sibling, 1 reply; 26+ messages in thread
From: suvayu ali @ 2010-04-07 15:07 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On 7 April 2010 07:43, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
> Peter Dyballa <Peter_Dyballa@Web.DE> writes:
>>
>> C-h l ?
>
> Oh great I don't know how I've never seen it...
> But that shows the keystrokes in another buffer, I would like to
> - record the keystrokes while I type
> - filter only the interesting ones (Meta and Control stuff)
> - send them to some other program to display it nicely (I think growl
>  could be perfect for that with applescript)
>

How about elisp that parses that buffer and uses growl to notify?

-- 
Suvayu

Open source is the future. It sets us free.




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

* Re: Print out my key-sequences
  2010-04-07 14:43   ` Andrea Crotti
  2010-04-07 15:07     ` suvayu ali
@ 2010-04-07 15:46     ` Thierry Volpiatto
  1 sibling, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2010-04-07 15:46 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Peter Dyballa <Peter_Dyballa@Web.DE> writes:
>>
>> C-h l ?
>
> Oh great I don't know how I've never seen it...
> But that shows the keystrokes in another buffer, I would like to 
> - record the keystrokes while I type
> - filter only the interesting ones (Meta and Control stuff)
> - send them to some other program to display it nicely (I think growl
>   could be perfect for that with applescript)

May be you can do something with:
(open-dribble-file "~/tmp/last-emacs-commands")

Then just tail the file.


-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/





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

* Re: Print out my key-sequences
  2010-04-07 15:07     ` suvayu ali
@ 2010-04-08  8:44       ` Andrea Crotti
  2010-04-10  5:47         ` Suvayu Ali
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-08  8:44 UTC (permalink / raw)
  To: help-gnu-emacs

suvayu ali <fatkasuvayu+linux@gmail.com> writes:

> On 7 April 2010 07:43, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
>>
>
> How about elisp that parses that buffer and uses growl to notify?

Great yes I also found this:
http://growl.info/documentation/growlnotify.php
and it's really easy to pass stuff to growl, maybe I just need a filter
now to make it appear in a certain position with a certain width...

Now I just need to parse the file with the keys, which looks like this
--8<---------------cut here---------------start------------->8---
<backspace><backspace><tab>ke<tab>y<tab>s<tab> 0x8000078tail<tab>
--8<---------------cut here---------------end--------------->8---

but I have no idea on how i should split interesting sequences by non
interesting ones, how does emacs understands that?
I mean I would only like to get in the end

C-M o   C-c C-o  etc etc,
Apparently there are space in between the same key sequence:
--8<---------------cut here---------------start------------->8---
<return>C-M o   C-c O<S-backspace>
--8<---------------cut here---------------end--------------->8---







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

* Re: Print out my key-sequences
  2010-04-08  8:44       ` Andrea Crotti
@ 2010-04-10  5:47         ` Suvayu Ali
  2010-04-17 10:11           ` Andrea Crotti
  0 siblings, 1 reply; 26+ messages in thread
From: Suvayu Ali @ 2010-04-10  5:47 UTC (permalink / raw)
  To: help-gnu-emacs

On Thursday 08 April 2010 01:44 AM, Andrea Crotti wrote:
> suvayu ali<fatkasuvayu+linux@gmail.com>  writes:
>
>> On 7 April 2010 07:43, Andrea Crotti<andrea.crotti.0@gmail.com>  wrote:
>>>
>>
>> How about elisp that parses that buffer and uses growl to notify?
>
> Great yes I also found this:
> http://growl.info/documentation/growlnotify.php
> and it's really easy to pass stuff to growl, maybe I just need a filter
> now to make it appear in a certain position with a certain width...
>
> Now I just need to parse the file with the keys, which looks like this
> --8<---------------cut here---------------start------------->8---
> <backspace><backspace><tab>ke<tab>y<tab>s<tab>  0x8000078tail<tab>
> --8<---------------cut here---------------end--------------->8---
>
> but I have no idea on how i should split interesting sequences by non
> interesting ones, how does emacs understands that?
> I mean I would only like to get in the end
>
> C-M o   C-c C-o  etc etc,
> Apparently there are space in between the same key sequence:
> --8<---------------cut here---------------start------------->8---
> <return>C-M o   C-c O<S-backspace>
> --8<---------------cut here---------------end--------------->8---
>

I am a elisp newbie and I have never used Macs, I couldn't give you a 
clue. But to setup the notifications you could try looking in this post.

http://emacs-fu.blogspot.com/2009/11/showing-pop-ups.html

Here the author uses notify-send (a GNU/Linux tool like growlnotify) to 
send notifications.

Good Luck and do post back if you have any solutions to your need. It 
would be interesting to know.

-- 
Suvayu

Open source is the future. It sets us free.




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

* Re: Print out my key-sequences
  2010-04-10  5:47         ` Suvayu Ali
@ 2010-04-17 10:11           ` Andrea Crotti
  2010-04-17 15:58             ` Kevin Rodgers
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-17 10:11 UTC (permalink / raw)
  To: help-gnu-emacs

Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:

> I am a elisp newbie and I have never used Macs, I couldn't give you a
> clue. But to setup the notifications you could try looking in this
> post.
>
> http://emacs-fu.blogspot.com/2009/11/showing-pop-ups.html
>
> Here the author uses notify-send (a GNU/Linux tool like growlnotify)
> to send notifications.
>
> Good Luck and do post back if you have any solutions to your need. It
> would be interesting to know.

Thanks a lot, but now the actually showing the popup is not hard at all,
now I would like to understand how to manage new keys instead.

I've seen the code of C-h l and in short I can use
- (recent-keys) which returns a vector of the last 300 keys inserted
- (single-key-description) which makes it more readable

I can check always the last element inserted in the vector and print it
out, is that supposed to work?





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

* Re: Print out my key-sequences
  2010-04-17 10:11           ` Andrea Crotti
@ 2010-04-17 15:58             ` Kevin Rodgers
  2010-04-17 18:59               ` Andrea Crotti
  0 siblings, 1 reply; 26+ messages in thread
From: Kevin Rodgers @ 2010-04-17 15:58 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti wrote:
> Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
> 
>> I am a elisp newbie and I have never used Macs, I couldn't give you a
>> clue. But to setup the notifications you could try looking in this
>> post.
>>
>> http://emacs-fu.blogspot.com/2009/11/showing-pop-ups.html
>>
>> Here the author uses notify-send (a GNU/Linux tool like growlnotify)
>> to send notifications.
>>
>> Good Luck and do post back if you have any solutions to your need. It
>> would be interesting to know.
> 
> Thanks a lot, but now the actually showing the popup is not hard at all,
> now I would like to understand how to manage new keys instead.
> 
> I've seen the code of C-h l and in short I can use
> - (recent-keys) which returns a vector of the last 300 keys inserted
> - (single-key-description) which makes it more readable
> 
> I can check always the last element inserted in the vector and print it
> out, is that supposed to work?

Not for multi-event keybindings.  C-h f this-command-keys

-- 
Kevin Rodgers
Denver, Colorado, USA





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

* Re: Print out my key-sequences
  2010-04-17 15:58             ` Kevin Rodgers
@ 2010-04-17 18:59               ` Andrea Crotti
  2010-04-17 19:27                 ` Lennart Borgman
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-17 18:59 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

>
> Not for multi-event keybindings.  C-h f this-command-keys

Great I can use directly "last-command", it would be great!

The only thing I still didn't get is how to intercept the event, is
there a simple daemon-client way to get if a new command has been typed?





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

* Re: Print out my key-sequences
  2010-04-17 18:59               ` Andrea Crotti
@ 2010-04-17 19:27                 ` Lennart Borgman
  2010-04-17 22:06                   ` Andrea Crotti
  0 siblings, 1 reply; 26+ messages in thread
From: Lennart Borgman @ 2010-04-17 19:27 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On Sat, Apr 17, 2010 at 8:59 PM, Andrea Crotti
<andrea.crotti.0@gmail.com> wrote:
> Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
>
>>
>> Not for multi-event keybindings.  C-h f this-command-keys
>
> Great I can use directly "last-command", it would be great!
>
> The only thing I still didn't get is how to intercept the event, is
> there a simple daemon-client way to get if a new command has been typed?

post-command-hook?




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

* Re: Print out my key-sequences
  2010-04-17 19:27                 ` Lennart Borgman
@ 2010-04-17 22:06                   ` Andrea Crotti
  2010-04-17 22:12                     ` Drew Adams
  2010-04-17 23:00                     ` Lennart Borgman
  0 siblings, 2 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-04-17 22:06 UTC (permalink / raw)
  To: help-gnu-emacs

Lennart Borgman <lennart.borgman@gmail.com> writes:

>
> post-command-hook?

Great almost there, it's really not so difficult apparently...
So given this function

--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"
  (interactive)
  (if (not (null window-system))
      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
    (message msg)))
--8<---------------cut here---------------end--------------->8---

I only need to pass the last command and add a hook that executes it
every time, the only thing missing is how to get a string from the
last-command variable.

Any help?
This doesn't work
(growl-popup last-command)

Debugger entered--Lisp error: (wrong-type-argument sequencep self-insert-command)

In the doc they say

The last command executed.
Normally a symbol with a function definition, but can be whatever was found
in the keymap, or whatever the variable `this-command' was set to by that
command.

So how am I supposed to print it out?
Thanks





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

* RE: Print out my key-sequences
  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
  1 sibling, 1 reply; 26+ messages in thread
From: Drew Adams @ 2010-04-17 22:12 UTC (permalink / raw)
  To: 'Andrea Crotti', help-gnu-emacs

> (not (null window-system))

No idea what you're really trying to do (I haven't followed this thread), but,
FYI, `not' and `null' are the same function, and (not (null X)) is the same as
X.





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

* RE: Print out my key-sequences
  2010-04-17 22:12                     ` Drew Adams
@ 2010-04-17 22:16                       ` Drew Adams
  0 siblings, 0 replies; 26+ messages in thread
From: Drew Adams @ 2010-04-17 22:16 UTC (permalink / raw)
  To: 'Andrea Crotti', help-gnu-emacs

> `not' and `null' are the same function, and (not (null X))
> is the same as X.

I should have said that they are the same in terms of truth value.

(not (null 3)) is t, which is not the same as 3.





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

* Re: Print out my key-sequences
  2010-04-17 22:06                   ` Andrea Crotti
  2010-04-17 22:12                     ` Drew Adams
@ 2010-04-17 23:00                     ` Lennart Borgman
  2010-04-18  8:47                       ` Andrea Crotti
  1 sibling, 1 reply; 26+ messages in thread
From: Lennart Borgman @ 2010-04-17 23:00 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On Sun, Apr 18, 2010 at 12:06 AM, Andrea Crotti
<andrea.crotti.0@gmail.com> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
>>
>> post-command-hook?
>
> Great almost there, it's really not so difficult apparently...
> So given this function
>
> --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"
>  (interactive)
>  (if (not (null window-system))
>      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
>    (message msg)))
> --8<---------------cut here---------------end--------------->8---
>
> I only need to pass the last command and add a hook that executes it
> every time, the only thing missing is how to get a string from the
> last-command variable.
>
> Any help?
> This doesn't work
> (growl-popup last-command)

(growl-popup (format "%s" last-command))

> Debugger entered--Lisp error: (wrong-type-argument sequencep self-insert-command)




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

* Re: Print out my key-sequences
  2010-04-17 23:00                     ` Lennart Borgman
@ 2010-04-18  8:47                       ` Andrea Crotti
  2010-04-18  9:01                         ` Andrea Crotti
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-18  8:47 UTC (permalink / raw)
  To: help-gnu-emacs

Lennart Borgman <lennart.borgman@gmail.com> writes:

> On Sun, Apr 18, 2010 at 12:06 AM, Andrea Crotti
> <andrea.crotti.0@gmail.com> wrote:
>> Lennart Borgman <lennart.borgman@gmail.com> writes:
>>
>>>
>>> post-command-hook?
>>
>> Great almost there, it's really not so difficult apparently...
>> So given this function
>>
>> --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"
>>  (interactive)
>>  (if (not (null window-system))
>>      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
>>    (message msg)))
>> --8<---------------cut here---------------end--------------->8---
>>
>> I only need to pass the last command and add a hook that executes it
>> every time, the only thing missing is how to get a string from the
>> last-command variable.
>>
>> Any help?
>> This doesn't work
>> (growl-popup last-command)
>
> (growl-popup (format "%s" last-command))
>
>> Debugger entered--Lisp error: (wrong-type-argument sequencep self-insert-command)


Oh great, I did this

--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"
  (interactive)
  (if window-system
      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
    (message msg)))

(defun popup-last ()
  (interactive)
  (growl-popup (format "%s" last-command)))

(add-hook 'post-command-hook 'popup-last)
--8<---------------cut here---------------end--------------->8---

And now emacs is going crazy, when I try to evaluate something it tries
to execute it in the shell.

I then removed the hook with
(setq post-command-hook (remq 'popup-last post-command-hook))

but it didn't listen, it's continuing to use it indefinitely...

Other problems are:
- the command is shown after (not during)
- I should remove useless stuff like self-insert-command
- I want to see the keyboard combination, not the full name of the
command...






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

* Re: Print out my key-sequences
  2010-04-18  8:47                       ` Andrea Crotti
@ 2010-04-18  9:01                         ` Andrea Crotti
  2010-04-18 11:13                           ` Lennart Borgman
  0 siblings, 1 reply; 26+ messages in thread
From: Andrea Crotti @ 2010-04-18  9:01 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
>
>
> And now emacs is going crazy, when I try to evaluate something it tries
> to execute it in the shell.
>
> I then removed the hook with
> (setq post-command-hook (remq 'popup-last post-command-hook))
>
> but it didn't listen, it's continuing to use it indefinitely...
>
> Other problems are:
> - the command is shown after (not during)
> - I should remove useless stuff like self-insert-command
> - I want to see the keyboard combination, not the full name of the
> command...

Ok I understood why it does so, it was for every command waiting to
growlnotify to finish, maybe in general it would be better to spawn a
shell process without waiting for it.

Another thing is that pre-command-hook is better, otherwise the command
is shown too late.

Last thing is that post-command-hook is modified globally but locally
somewhere there is still that command in the hook, that's why it keeps
getting crazy...





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

* Re: Print out my key-sequences
  2010-04-18  9:01                         ` Andrea Crotti
@ 2010-04-18 11:13                           ` Lennart Borgman
  2010-04-18 14:16                             ` Andrea Crotti
  0 siblings, 1 reply; 26+ messages in thread
From: Lennart Borgman @ 2010-04-18 11:13 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On Sun, Apr 18, 2010 at 11:01 AM, Andrea Crotti
<andrea.crotti.0@gmail.com> wrote:
>
> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
> >
> > - I want to see the keyboard combination, not the full name of the
> > command...

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.




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

* Re: Print out my key-sequences
  2010-04-18 11:13                           ` Lennart Borgman
@ 2010-04-18 14:16                             ` Andrea Crotti
  2010-04-18 14:59                               ` Thierry Volpiatto
                                                 ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-04-18 14:16 UTC (permalink / raw)
  To: help-gnu-emacs

Lennart Borgman <lennart.borgman@gmail.com> 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"
  (interactive)
  (if window-system
      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
    (message msg)))

(defun popup-last ()
  (interactive)
  (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?

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





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

* Re: Print out my key-sequences
  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
  2 siblings, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2010-04-18 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Lennart Borgman <lennart.borgman@gmail.com> 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
> (defun growl-popup (msg)
>   "Show a popup using growl notification or say it, only working on OSX with growlnotify in the $PATH"
>   (interactive)
>   (if window-system
>       (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
>     (message msg)))
>
> (defun popup-last ()
>   (interactive)
>   (growl-popup (this-command-keys)))
>
> What doest that supposed to mean?
> The function this-command-keys is returning a string, 

Not always.

> and growl-popup is
> working just fine, so what could be the problem again?
>
> (Shell command killed by signal Trace/BPT trap)

See man page of trap and the list of signals with kill -l.

-- 
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/





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

* Re: Print out my key-sequences
  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
  2 siblings, 0 replies; 26+ messages in thread
From: Lennart Borgman @ 2010-04-18 16:09 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On Sun, Apr 18, 2010 at 4:16 PM, Andrea Crotti
<andrea.crotti.0@gmail.com> wrote:
>
> (defun popup-last ()
>  (interactive)
>  (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?


Are you sure this-command-keys is always returning a string?




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

* Re: Print out my key-sequences
  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
  2 siblings, 1 reply; 26+ messages in thread
From: Kevin Rodgers @ 2010-04-21  7:09 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti wrote:
> Lennart Borgman <lennart.borgman@gmail.com> 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"
>   (interactive)
>   (if window-system
>       (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m " msg))
>     (message msg)))
> 
> (defun popup-last ()
>   (interactive)
>   (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
string.

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

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

-- 
Kevin Rodgers
Denver, Colorado, USA





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

* Re: Print out my key-sequences
  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
  0 siblings, 2 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-05-24 17:07 UTC (permalink / raw)
  To: help-gnu-emacs

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?




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

* Re: Print out my key-sequences
  2010-05-24 17:07                                 ` Andrea Crotti
@ 2010-05-24 18:02                                   ` Andrea Crotti
  2010-05-25  6:47                                   ` Kevin Rodgers
  1 sibling, 0 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-05-24 18:02 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> I have to use setq-default to disable it by the way, is that correct?
>   (defun growl-mode-off ()
>     (interactive)
>     (setq-default pre-command-hook (remq 'popup-last pre-command-hook)))
>
> 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?


This is one possible way to solve the problem

--8<---------------cut here---------------start------------->8---
  (defun popup-last ()
    (interactive)
    (let
        ((last-key (key-description (this-command-keys))))
      (if
          (or
           (string-prefix-p "C-" last-key)
           (string-prefix-p "M-" last-key))
          (growl-popup last-key))))
--8<---------------cut here---------------end--------------->8---

But probably not the best one...




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

* Re: Print out my key-sequences
  2010-05-24 17:07                                 ` Andrea Crotti
  2010-05-24 18:02                                   ` Andrea Crotti
@ 2010-05-25  6:47                                   ` Kevin Rodgers
  2010-05-31 22:30                                     ` Andrea Crotti
  1 sibling, 1 reply; 26+ messages in thread
From: Kevin Rodgers @ 2010-05-25  6:47 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

* Re: Print out my key-sequences
  2010-05-25  6:47                                   ` Kevin Rodgers
@ 2010-05-31 22:30                                     ` Andrea Crotti
  0 siblings, 0 replies; 26+ messages in thread
From: Andrea Crotti @ 2010-05-31 22:30 UTC (permalink / raw)
  To: help-gnu-emacs

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> 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))
>   ...)

Yes great looks very nice I'm just using the first version...
Where could that posted for a better visibility, I was looking for
something like that some time ago but with no luck.

Maybe on emacs-wiki or just on my blog or somewhere else?




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

end of thread, other threads:[~2010-05-31 22:30 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-05-31 22:30                                     ` Andrea Crotti
2010-04-07 15:46     ` Thierry Volpiatto

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