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

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

Re: Short-circuiting keybindings?


From: Elena
Subject: Re: Short-circuiting keybindings?
Date: Wed, 08 Dec 2010 15:35:25 -0000
User-agent: G2/1.0

On Nov 10, 7:19 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> You can create conditional key bindings:
>
>   (define-key map [?\C-b] '(menu-item "dummy" <command>
>                             :filter (lambda (binding)
>                                       (if <condition> binding))))
>
> The filter function will receive <command> as argument (this is so that
> the same filter function can be used for several bindings) and can opt
> to return it or not or to return anything else (so you can create
> dynamic bindings, which is typically used to construct dynamic menus,
> such as the Buffers menu).
> The <command> you put as the "static binding" that gets passed to the
> filter is only used in cases such as where-is.

Thank you for your suggestion.  I don't undestand the code, so I'm
asking you to edit an example skeleton.  Let's suppose we want to
emulate CUA mode's behavior on "C-c": if region is active, then copy
it, otherwise keep collecting keystrokes (for instance: "C-c C-c" for
SLIME's compile functions).  According to your suggestion, a skeleton
could be:

  (define-key map [?\C-c] '(menu-item "dummy" 'copy-region-as-kill
                            :filter (lambda (binding)
                                      (unless (region-active-p)
binding))))

How would you correct it?  Thanks.





reply via email to

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