[Top][All Lists]

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

Re: Suggestion: Simple way to make conditional key bindings.

From: Kim F. Storm
Subject: Re: Suggestion: Simple way to make conditional key bindings.
Date: 23 Aug 2002 15:16:11 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

"David PONCE" <address@hidden> writes:

> > (global-set-key "\C-y"
> >         '(cond
> >           ((and kill-ring (table-recognize-table (car kill-ring)))
> >             yank-with-properties)
> >           (t yank)))
> > 
> > 
> It seems that you can do something similar this way:
> (global-set-key "\C-y" '(menu-item "my-filter" :filter my-filter))
> (defun my-filter (&rest ignore)
>   (cond
>    ((and kill-ring (table-recognize-table (car kill-ring)))
>     'yank-with-properties)
>    (t 'yank)))
> Am I wrong?

Not at all [that's more or less how it is implemented].

But IMO, the `menu-item' syntax is awful, and using a
filter function is an added complexity which is pretty

I failed to mention a very important benefit of integrating this in
the keymaps directly:

It will then be quite trivial to enhance `define-key' to handle
conditional bindings:

(define-key global-map "\C-y" 'yank)  ; this sets the default

(define-key global-map "\C-y" 'yank-with-properties
        '(and kill-ring (table-recognize-table (car kill-ring))))

The second call would automatically changes the non-cond binding into
a cond binding with the previous binding as default.

To remove a conditional binding, we could use either of
the following:

(define-key global-map "\C-y" 'yank-with-properties t)

(define-key global-map "\C-y" nil
        '(and kill-ring (table-recognize-table (car kill-ring))))

Removing the last condtional binding could collapse the 
resulting (cond ((t yank))) back into 'yank.

Kim F. Storm <address@hidden> http://www.cua.dk

reply via email to

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