unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* key binding question
@ 2007-11-03  1:10 Drew Adams
  2007-11-03  1:35 ` Lennart Borgman (gmail)
  2007-11-03 14:12 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Drew Adams @ 2007-11-03  1:10 UTC (permalink / raw)
  To: Emacs-Devel

I have a user variable `foo' whose value has the same form as a key-sequence
argument to `define-key'. That's all I know.

So, for example, `foo' might have value [S-iso-lefftab] or "\C-e" or [?\C-x
?] or "^E" (i.e. Control-E) or whatever might be acceptable to `define-key'.

How can I, in Lisp, bind command `bar' to `foo's key, but with the Control
and Meta modifiers added. So, for example, if `foo' = [S-iso-lefftab], then
the code would bind `bar' to [C-M-S-iso-lefttab].

If this is too difficult, suppose that `foo's value were guaranteed to
always be a vector - same question.

Can anyone help with this?

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

* Re: key binding question
  2007-11-03  1:10 key binding question Drew Adams
@ 2007-11-03  1:35 ` Lennart Borgman (gmail)
  2007-11-03 14:12 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Lennart Borgman (gmail) @ 2007-11-03  1:35 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

Drew Adams wrote:
> I have a user variable `foo' whose value has the same form as a key-sequence
> argument to `define-key'. That's all I know.
> 
> So, for example, `foo' might have value [S-iso-lefftab] or "\C-e" or [?\C-x
> ?] or "^E" (i.e. Control-E) or whatever might be acceptable to `define-key'.
> 
> How can I, in Lisp, bind command `bar' to `foo's key, but with the Control
> and Meta modifiers added. So, for example, if `foo' = [S-iso-lefftab], then
> the code would bind `bar' to [C-M-S-iso-lefttab].
> 
> If this is too difficult, suppose that `foo's value were guaranteed to
> always be a vector - same question.
> 
> Can anyone help with this?

I think you can do it with key-description and kbd. And some work.

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

* Re: key binding question
  2007-11-03  1:10 key binding question Drew Adams
  2007-11-03  1:35 ` Lennart Borgman (gmail)
@ 2007-11-03 14:12 ` Stefan Monnier
  2007-11-03 16:34   ` Drew Adams
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2007-11-03 14:12 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

> How can I, in Lisp, bind command `bar' to `foo's key, but with the Control
> and Meta modifiers added. So, for example, if `foo' = [S-iso-lefftab], then
> the code would bind `bar' to [C-M-S-iso-lefttab].

You first have to define what "add control and meta modifiers" mean when
applied not to a key but to a key-sequence.

Then you might be able to use something like

  (define-key map
              (apply 'vector (mapcar (lambda (k) (list 'meta 'control k)) foo))
              'bar)


-- Stefan

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

* RE: key binding question
  2007-11-03 14:12 ` Stefan Monnier
@ 2007-11-03 16:34   ` Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2007-11-03 16:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs-Devel

> > How can I, in Lisp, bind command `bar' to `foo's key, but with
> > the Control and Meta modifiers added. So, for example, if
> > `foo' = [S-iso-lefftab], then the code would bind `bar' to
> > [C-M-S-iso-lefttab].
>
> You first have to define what "add control and meta modifiers" mean when
> applied not to a key but to a key-sequence.

Apply them only to the first key of the sequence (in my case).

> Then you might be able to use something like
>
>   (define-key map
>       (apply 'vector
>              (mapcar (lambda (k)
>                         (list 'meta 'control k)) foo))
>       'bar)

Thank you. This seems to do it:

(define-key map
    (apply 'vector
           (let ((k (elt foo 0)))
             (cons (if (listp k)
                       `(control meta ,@k)
                     `(control meta ,k))
                   (mapcar #'identity (substring foo 1)))))
    'bar)

(It seems that any extra `control' and `meta' don't matter, so I didn't
bother to remove them.)

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

end of thread, other threads:[~2007-11-03 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-03  1:10 key binding question Drew Adams
2007-11-03  1:35 ` Lennart Borgman (gmail)
2007-11-03 14:12 ` Stefan Monnier
2007-11-03 16:34   ` Drew Adams

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