6

Sometimes, packages override a whole host of existing key bindings from other packages. The key bindings get associated with infrequently used functions, so I don't even want to rebind them. This is a frequent occurrence. For example, I just installed a package called olivetti-mode (which just centers buffer text), which took over a bind of factory key bindings from ref-tex and org. Is there a way to just disable all of the key binding for an entire package?

usepackage (which I have installed) has :bind directive. Maybe it's possible to use that somehow.

2 Answers 2

8

As Drew says, you cannot do this without knowing specifically which keymaps and bindings are being affected.

There are common cases in which all the bindings are liable to be in a single keymap (which is not normally modified after the library has been loaded), in which case you could clobber that keymap using something like:

(eval-after-load "olivetti"
  '(setq olivetti-mode-map (make-sparse-keymap)))

You can, of course, unbind specific keys from the keymap in question, allowing lower-priority keymaps to be processed for those keys instead.

(eval-after-load "olivetti"
  '(progn (define-key olivetti-mode-map (kbd "C-c [") nil)
          (define-key olivetti-mode-map (kbd "C-c ]") nil)))

In the case of minor modes, the keymap look-up and precedence is determined by the order of minor-mode-map-alist.

One consequence is that you can inhibit a minor mode's bindings by removing it from that list:

(eval-after-load "olivetti"
  '(assq-delete-all 'olivetti-mode minor-mode-map-alist))

A softer option (if the conflict is between minor modes) is to either load libraries which define minor modes in the order you want them to be loaded in1, or otherwise to manipulate the order of that list to achieve the same effect (for example I do the latter in an after-load-functions callback, in order to keep one particular minor mode at the head of the list at all times).

1 By default minor modes defined more recently will have precedence when bindings conflict; so if you were to (require 'olivetti) very early in your init, you may find the problem goes away.

1

There is no general answer to this, because it's not clear what key bindings, in what keymaps, a given package might make.

But if the package defines one or more keymaps and modes (major or minor) then you can empty those keymaps (but why?). And you can look at whatever key bindings the package makes and undo those as well.

Anything you do along these lines will require you to look at the package code: what it does to key bindings. A package is free to make or change any key bindings, in any keymaps. The bindings it affects are not necessarily encapsulated by the package in any way (e.g., in a mode).

I suggest you consider posing another, more-specific question about a particular package. As it stands, your question has no one-size-fits-all answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.