help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Preventing modes overriding global keys


From: Pascal Bourguignon
Subject: Re: Preventing modes overriding global keys
Date: Mon, 13 Jun 2005 00:17:36 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]