unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* (global-set-key) vs (define-key)
@ 2015-06-25 18:05 Daniel Corbe
  2015-06-25 18:14 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Daniel Corbe @ 2015-06-25 18:05 UTC (permalink / raw)
  To: help-gnu-emacs


I'm trying to extend eshell so I can use it to manage routers and
switches.  This necessitates changing a few important key-bindings that
equipment manufacturers tend to use.

The problem with the code below is ? works; however, both Ctrl-Z and TAB
stay bound to their original key bindings.

If I use global-set-key instead, TAB and Ctrl-Z do what they're supposed
to do.

I have a suspicion that (define-key) is not allowed to override global
bindings.  Is that true?  If so, what should I be using instead?

(define-derived-mode router-mode eshell-mode "Router"
  "Some key bindings and tools to make dealing with routers/switches easier."

  (define-key eshell-mode-map "?" 'router-mode-help-key)
  (define-key eshell-mode-map (kbd "C-z") 'router-mode-end-key)
  (define-key eshell-mode-map (kbd "TAB") 'self-insert-command))

(defun router-mode-help-key ()
  "Defines what happens when a user hits the ? key."
  (interactive)
  (insert "?")
  (eshell-send-input nil nil t))

(defun router-mode-end-key ()
  "This sends Ctrl-Z along to the shell."
  (interactive)
  (eshell-kill-input)
  (insert "end")
  (eshell-send-input))



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

* RE: (global-set-key) vs (define-key)
  2015-06-25 18:05 (global-set-key) vs (define-key) Daniel Corbe
@ 2015-06-25 18:14 ` Drew Adams
  2015-06-25 19:11 ` Michael Heerdegen
       [not found] ` <mailman.5675.1435259510.904.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2015-06-25 18:14 UTC (permalink / raw)
  To: Daniel Corbe, help-gnu-emacs

> I have a suspicion that (define-key) is not allowed to override
> global bindings.  Is that true?

No.  `define-key' binds a key in the keymap you provide it as a
parameter.  `global-set-key' binds a key in the keymap that is
the value of variable `global-map'.

So these are equivalent:

(global-set-key KEY COMMAND)
(define-key global-map KEY COMMAND)

(`C-h f' is your friend, as is `C-h r i...')



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

* Re: (global-set-key) vs (define-key)
  2015-06-25 18:05 (global-set-key) vs (define-key) Daniel Corbe
  2015-06-25 18:14 ` Drew Adams
@ 2015-06-25 19:11 ` Michael Heerdegen
       [not found] ` <mailman.5675.1435259510.904.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Heerdegen @ 2015-06-25 19:11 UTC (permalink / raw)
  To: help-gnu-emacs

Daniel Corbe <corbe@corbe.net> writes:

> I have a suspicion that (define-key) is not allowed to override global
> bindings.  Is that true?  If so, what should I be using instead?

What do you mean with "global-bindings"?  Probably not bindings in
`global-map', because `define-key' can of course bind keys in
`global-map'.


> (define-derived-mode router-mode eshell-mode "Router"
>   "Some key bindings and tools to make dealing with routers/switches
> easier."
>
>   (define-key eshell-mode-map "?" 'router-mode-help-key)
>   (define-key eshell-mode-map (kbd "C-z") 'router-mode-end-key)
>   (define-key eshell-mode-map (kbd "TAB") 'self-insert-command))

This will modify `eshell-mode-map', the map used by eshell-mode.  This
is probably not what you want.  Better use a separate map, it set
`eshell-mode-map' as parent map to inherit from it.


Michael.




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

* Re: (global-set-key) vs (define-key)
       [not found] ` <mailman.5675.1435259510.904.help-gnu-emacs@gnu.org>
@ 2015-06-25 20:28   ` Daniel Corbe
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Corbe @ 2015-06-25 20:28 UTC (permalink / raw)
  To: help-gnu-emacs


Michael Heerdegen <michael_heerdegen@web.de> writes:

> Daniel Corbe <corbe@corbe.net> writes:
>>
>>   (define-key eshell-mode-map "?" 'router-mode-help-key)
>>   (define-key eshell-mode-map (kbd "C-z") 'router-mode-end-key)
>>   (define-key eshell-mode-map (kbd "TAB") 'self-insert-command))
>
> This will modify `eshell-mode-map', the map used by eshell-mode.  This
> is probably not what you want.  Better use a separate map, it set
> `eshell-mode-map' as parent map to inherit from it.

Thanks.  This fixed my issue.  The key bindings work perfectly now.

>
>
> Michael.


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

end of thread, other threads:[~2015-06-25 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25 18:05 (global-set-key) vs (define-key) Daniel Corbe
2015-06-25 18:14 ` Drew Adams
2015-06-25 19:11 ` Michael Heerdegen
     [not found] ` <mailman.5675.1435259510.904.help-gnu-emacs@gnu.org>
2015-06-25 20:28   ` Daniel Corbe

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