all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* key binding question
@ 2003-04-06  5:05 Kevin Reeder
  2003-04-06 11:14 ` maierh
  2003-04-07 10:10 ` Jerome Besnard
  0 siblings, 2 replies; 12+ messages in thread
From: Kevin Reeder @ 2003-04-06  5:05 UTC (permalink / raw)


When using the python interpreter within emacs, I'd like to have the
up/down arrows echo previous commands. Can anyone give me the code for
this?

Kevin

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

* Re: key binding question
  2003-04-06  5:05 key binding question Kevin Reeder
@ 2003-04-06 11:14 ` maierh
  2003-04-07 10:10 ` Jerome Besnard
  1 sibling, 0 replies; 12+ messages in thread
From: maierh @ 2003-04-06 11:14 UTC (permalink / raw)


Kevin Reeder <avail@uponrequest.org> writes:

> When using the python interpreter within emacs, I'd like to have the
> up/down arrows echo previous commands. Can anyone give me the code for
> this?

The common philosophy on this subject is to use M-p and M-n because
with down and up or C-n and C-p you might move in the buffer. Anyway,
I don't know the python interpreter mode, but if it's derived from
comint then you can set in the interpreter mode hook the function
'comint-previous-input' and 'comint-next-input' to your favorite keys.

Here an example that sets in general for all comint modes new function
keys. But you can set this too only for a special mode such as
'shell-mode-hook' or maybe 'py-mode-hook' (?).

(add-hook 
 'comint-mode-hook 
 (lambda () 
   (interactive)
   (define-key comint-mode-map [up]   'comint-previous-input)
   (define-key comint-mode-map [down] 'comint-next-input)
   ))


Harald

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

* Re: key binding question
  2003-04-06  5:05 key binding question Kevin Reeder
  2003-04-06 11:14 ` maierh
@ 2003-04-07 10:10 ` Jerome Besnard
  2003-04-08  4:09   ` Kevin Reeder
  1 sibling, 1 reply; 12+ messages in thread
From: Jerome Besnard @ 2003-04-07 10:10 UTC (permalink / raw)


> When using the python interpreter within emacs, I'd like to have the
> up/down arrows echo previous commands. Can anyone give me the code for
> this?

The pyhton shell uses comint-mode (for input-output in shell-like modes). In
comint mode, previous commands are echoed via C-up and C-down.
But if you really prefer to have these with up/down arrows, you should set
comint-previous-command and comint-next-command to up/down.
Something (untested) like:
(define-key comint-mode-map [up] 'comint-previous-command)
(define-key comint-mode-map [down] 'comint-next-command)

should do the trick.
-- 
Jerome

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

* Re: key binding question
  2003-04-07 10:10 ` Jerome Besnard
@ 2003-04-08  4:09   ` Kevin Reeder
  0 siblings, 0 replies; 12+ messages in thread
From: Kevin Reeder @ 2003-04-08  4:09 UTC (permalink / raw)


On Mon, 07 Apr 2003 03:10:36 -0700, Jerome Besnard wrote:

>> When using the python interpreter within emacs, I'd like to have the
>> up/down arrows echo previous commands. Can anyone give me the code for
>> this?
> 
> The pyhton shell uses comint-mode (for input-output in shell-like
> modes). In comint mode, previous commands are echoed via C-up and
> C-down. But if you really prefer to have these with up/down arrows, you
> should set comint-previous-command and comint-next-command to up/down.
> Something (untested) like:
> (define-key comint-mode-map [up] 'comint-previous-command) (define-key
> comint-mode-map [down] 'comint-next-command)
> 
> should do the trick.

I'll try C-up/down and add make the change to my init file later if
necessary. It's second nature to hit up or down when I'm using the
shell, but adding the C- shouldn't take much getting used to.
Thanks.

Kevin

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

* key binding question
@ 2007-02-10 13:00 Hadron
  2007-02-12  4:42 ` Kevin Rodgers
       [not found] ` <mailman.4372.1171255378.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Hadron @ 2007-02-10 13:00 UTC (permalink / raw)
  To: help-gnu-emacs


Is it to add a new key binding to be local to a specific mode by adding
a hook e.g


(add-hook 'html-mode-hook
	  (lambda ()
	    (local-set-key [f10] 'myfunc)))


or to use define-key on the specific mode-map?e.g

(define-key html-mode-map [f11] 'myfunc)

(assume the html-mode-map variable is instantiated/inscope.

Or to ask another way, why would you choose one over the other and what
might the pitfalls be?

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

* Re: key binding question
  2007-02-10 13:00 Hadron
@ 2007-02-12  4:42 ` Kevin Rodgers
       [not found] ` <mailman.4372.1171255378.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2007-02-12  4:42 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron wrote:
> Is it to add a new key binding to be local to a specific mode by adding
> a hook e.g
> 
> 
> (add-hook 'html-mode-hook
> 	  (lambda ()
> 	    (local-set-key [f10] 'myfunc)))
> 
> 
> or to use define-key on the specific mode-map?e.g
> 
> (define-key html-mode-map [f11] 'myfunc)
> 
> (assume the html-mode-map variable is instantiated/inscope.
> 
> Or to ask another way, why would you choose one over the other and what
> might the pitfalls be?

I use the mode hook, because I have an aversion to keymap variable names
:-) and because it doesn't require the package to be loaded.

-- 
Kevin Rodgers
Denver, Colorado, USA

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

* Re: key binding question
       [not found] ` <mailman.4372.1171255378.2155.help-gnu-emacs@gnu.org>
@ 2007-02-12  9:11   ` Hadron
  2007-02-13  6:36     ` Kevin Rodgers
  0 siblings, 1 reply; 12+ messages in thread
From: Hadron @ 2007-02-12  9:11 UTC (permalink / raw)
  To: help-gnu-emacs

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

> Hadron wrote:
>> Is it to add a new key binding to be local to a specific mode by adding
>> a hook e.g
>>
>>
>> (add-hook 'html-mode-hook
>> 	  (lambda ()
>> 	    (local-set-key [f10] 'myfunc)))
>>
>>
>> or to use define-key on the specific mode-map?e.g
>>
>> (define-key html-mode-map [f11] 'myfunc)
>>
>> (assume the html-mode-map variable is instantiated/inscope.
>>
>> Or to ask another way, why would you choose one over the other and what
>> might the pitfalls be?
>
> I use the mode hook, because I have an aversion to keymap variable names
> :-) and because it doesn't require the package to be loaded.

Makes sense, and doesn't add it multiple times I assume :-;

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

* Re: key binding question
  2007-02-12  9:11   ` Hadron
@ 2007-02-13  6:36     ` Kevin Rodgers
  0 siblings, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2007-02-13  6:36 UTC (permalink / raw)
  To: help-gnu-emacs

Hadron wrote:
> Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> 
>> Hadron wrote:
>>> Is it to add a new key binding to be local to a specific mode by adding
>>> a hook e.g
>>>
>>>
>>> (add-hook 'html-mode-hook
>>> 	  (lambda ()
>>> 	    (local-set-key [f10] 'myfunc)))
>>>
>>>
>>> or to use define-key on the specific mode-map?e.g
>>>
>>> (define-key html-mode-map [f11] 'myfunc)
>>>
>>> (assume the html-mode-map variable is instantiated/inscope.
>>>
>>> Or to ask another way, why would you choose one over the other and what
>>> might the pitfalls be?
>> I use the mode hook, because I have an aversion to keymap variable names
>> :-) and because it doesn't require the package to be loaded.
> 
> Makes sense, and doesn't add it multiple times I assume :-;

No need to assume: C-h f add-hook

-- 
Kevin Rodgers
Denver, Colorado, USA

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

* 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; 12+ 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] 12+ messages in thread

* Re: 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
  1 sibling, 0 replies; 12+ 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] 12+ messages in thread

* Re: 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
  2007-11-03 16:34   ` Drew Adams
  1 sibling, 1 reply; 12+ 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] 12+ 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; 12+ 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] 12+ messages in thread

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

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-06  5:05 key binding question Kevin Reeder
2003-04-06 11:14 ` maierh
2003-04-07 10:10 ` Jerome Besnard
2003-04-08  4:09   ` Kevin Reeder
  -- strict thread matches above, loose matches on Subject: below --
2007-02-10 13:00 Hadron
2007-02-12  4:42 ` Kevin Rodgers
     [not found] ` <mailman.4372.1171255378.2155.help-gnu-emacs@gnu.org>
2007-02-12  9:11   ` Hadron
2007-02-13  6:36     ` Kevin Rodgers
2007-11-03  1:10 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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.