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

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

Re: Cant global map overwrite local maps?


From: Kevin Rodgers
Subject: Re: Cant global map overwrite local maps?
Date: Wed, 29 Mar 2006 14:08:21 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Pascal Bourguignon wrote:
"Florian Kaufmann" <sensorflo@gmail.com> writes:


Hello

Isn't it possible to bind a key to command such that this definition is
effective in all major & minor modes? In my particular case I'd like to
bind forward-char and backward-char to C-j and C-l respectively. But I
'd like to write this definition only once, and not for all minor and
major modes which overwrite the global map. For example currently in my
init.el I not only have to write

(global-set-key [(control j)] 'backward-char)
(global-set-key [(control l)] 'forward-char)

but disturbingly also

(add-hook 'c++-mode-hook
         '(lambda ()
            (define-key c++-mode-map [(control j)] 'backward-char)
            (define-key c++-mode-map [(control l)] 'forward-char) ))

And I also have to add lines for countless of other modes I intend to
use.


Yes, that's what you have to do. The mode shall decide what keybindings are good for you.

If you want to avoid it globally, the best that could be done is to
advice define-key and local-set-key, etc, to filter out unwanted mode
bindings.

Could he take advantage of minor-mode-overriding-map-alist, with a bogus
minor mode variable?  I found this in diff-mode.el:

  ;; Neat trick from Dave Love to add more bindings in read-only mode:
  (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
               (cons 'buffer-read-only diff-mode-shared-map))

So perhaps something like:

(defvar sensorflo-map
  (let ((map (make-sparse-keymap)))
    (define-key map [(control j)] 'backward-char)
    (define-key map [(control l)] 'forward-char)
    map))

(set (make-local-variable 'minor-mode-overriding-map-alist)
     (cons (cons 't sensorflo-map)
           minor-mode-overriding-map-alist))

--
Kevin Rodgers





reply via email to

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