unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: storm@cua.dk (Kim F. Storm)
Cc: <emacs-devel@gnu.org>
Subject: Re: Suggestion: Simple way to make conditional key bindings.
Date: 23 Aug 2002 15:16:11 +0200	[thread overview]
Message-ID: <5xadnd3eck.fsf@kfs2.cua.dk> (raw)
In-Reply-To: <3D49FF140074EFAE@mel-rta7.wanadoo.fr> (added by postmaster@wanadoo.fr)

"David PONCE" <David.Ponce@wanadoo.fr> 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
unflexible.


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 <storm@cua.dk> http://www.cua.dk

       reply	other threads:[~2002-08-23 13:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3D49FF140074EFAE@mel-rta7.wanadoo.fr>
2002-08-23 13:16 ` Kim F. Storm [this message]
2002-08-23 17:22   ` Suggestion: Simple way to make conditional key bindings Stefan Monnier
2002-08-25 23:33     ` Kim F. Storm
2002-08-26 15:47       ` Stefan Monnier
2002-08-26 19:33         ` Miles Bader
2002-08-27 19:05           ` Richard Stallman
2002-08-27 22:58             ` Kim F. Storm
2002-08-28 23:32               ` Richard Stallman
2002-08-29  8:54                 ` Kim F. Storm
2002-08-28  1:00             ` Miles Bader
2002-08-28  1:22               ` Stefan Monnier
2002-08-27 11:23         ` Kim F. Storm
2002-08-23 12:52 David PONCE
  -- strict thread matches above, loose matches on Subject: below --
2002-08-23 12:05 Kim F. Storm
2002-08-26  0:36 ` Richard Stallman
2002-08-26 16:21   ` Stefan Monnier
2002-08-30 10:27     ` Robert J. Chassell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5xadnd3eck.fsf@kfs2.cua.dk \
    --to=storm@cua.dk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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