all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Preventing modes overriding global keys
@ 2005-06-12 20:39 Ian Crowther
  2005-06-14 18:07 ` Kevin Rodgers
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Crowther @ 2005-06-12 20:39 UTC (permalink / raw)


I'm trying to make emacs bind end-of-line to the tab key in all modes. 
Doing:

	(global-set-key (kbd "TAB") 'end-of-line)

doesn't have any effect. "C-h k <TAB>" shows:
	TAB runs the command lisp-indent-line

I assume my parameters to global-set-key are correct, as local-set-key 
works.
It looks like the lisp mode is defining the tab key. If I evaluate 
"(lisp-mode)" then
my binding made with local-set-key is disabled.

Is there a way to override the mode settings for the tab key? Or a way to 
prevent
modes overriding certain keys in the first place?

Thanks for any help. I'm really stuck on this one.

Ian

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

* Re: Preventing modes overriding global keys
       [not found] <mailman.4448.1118610019.25862.help-gnu-emacs@gnu.org>
@ 2005-06-12 22:17 ` Pascal Bourguignon
  0 siblings, 0 replies; 3+ messages in thread
From: Pascal Bourguignon @ 2005-06-12 22:17 UTC (permalink / raw)


"Ian Crowther" <i_crowther@hotmail.com> writes:

> I'm trying to make emacs bind end-of-line to the tab key in all
> modes. Doing:
>
> 	(global-set-key (kbd "TAB") 'end-of-line)
>
> doesn't have any effect. "C-h k <TAB>" shows:
> 	TAB runs the command lisp-indent-line
>
> I assume my parameters to global-set-key are correct, as local-set-key
> works.
> It looks like the lisp mode is defining the tab key. If I evaluate
> "(lisp-mode)" then
> my binding made with local-set-key is disabled.
>
> Is there a way to override the mode settings for the tab key? Or a way
> to prevent
> modes overriding certain keys in the first place?
>
> Thanks for any help. I'm really stuck on this one.

Modes and keys management in emacs is not declarative, it's
procedural, and state is spread between global and buffer local
variables.

Have a look at global-set-key, it only modifies the
(current-global-map),  not all the keymaps, and not the keymaps
installed in each buffer by the various modes.

Perhaps you want something like:
        
(defun set-key-everywhere (key command)
  (global-set-key key command)
  (dolist (buffer (buffer-list))
    (set-buffer buffer)
    (let ((map (current-local-map)))
      (when map
        (define-key map key command)))))

(set-key-everywhere (kbd "TAB") 'end-of-line)

But of course you'll have to re-execute this last s-expr everytime a
mode redefines a local map.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.

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

* Re: Preventing modes overriding global keys
  2005-06-12 20:39 Preventing modes overriding global keys Ian Crowther
@ 2005-06-14 18:07 ` Kevin Rodgers
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2005-06-14 18:07 UTC (permalink / raw)


Ian Crowther wrote:
 > I'm trying to make emacs bind end-of-line to the tab key in all modes.
 > Doing:
 >
 >     (global-set-key (kbd "TAB") 'end-of-line)
 >
 > doesn't have any effect. "C-h k <TAB>" shows:
 >     TAB runs the command lisp-indent-line
 >
 > I assume my parameters to global-set-key are correct, as local-set-key
 > works.  It looks like the lisp mode is defining the tab key. If I
 > evaluate "(lisp-mode)" then my binding made with local-set-key is
 > disabled.
 >
 > Is there a way to override the mode settings for the tab key?

Yes.  But you'll have to change the binding for each mode you use:

(add-hook 'lisp-mode-hook
	  (lambda () (local-set-key (kbd "TAB") 'end-of-line)))

 > Or a way to prevent modes overriding certain keys in the first place?

You might be able to fudge it by using key-translation-map to generate a
user-defined function key from (kbd "TAB") that you would map globally to
end-of-line.

-- 
Kevin Rodgers

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

end of thread, other threads:[~2005-06-14 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-12 20:39 Preventing modes overriding global keys Ian Crowther
2005-06-14 18:07 ` Kevin Rodgers
     [not found] <mailman.4448.1118610019.25862.help-gnu-emacs@gnu.org>
2005-06-12 22:17 ` Pascal Bourguignon

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.