Frage

On OS X, with a .emacs containing only the lines:

(require 'dired)

(add-hook 'dired-load-hook
      (function (lambda ()
              (load "dired-x"))))

dired-omit-mode in dired-x and ns-open-file-using-panel in ns-win fight over the keybinding M-o.

I understand the .emacs above as specifying that dired-x should be loaded just after dired—and hence the binding of M-o in dired-x should take over when emacs starts. This is not the case. For some reason the binding in ns-win wins.

How can I force the dired-x keybinding at startup?

Edit

(Following phils' suggestion) If my .emacs also loads the two other packages that define M-o

(require 'ns-win)
(require 'facemenu)
(require 'dired)

(add-hook 'dired-load-hook
      (function (lambda ()
              (load "dired-x"))))

even though dired is loaded last, the binding in facemenu still takes over.

War es hilfreich?

Lösung

First, load ns-win, so that it sets its binding. Then this:

(add-hook 
 'dired-mode-hook
 (lambda()
   (require 'dired-x)
   (define-key dired-mode-map (kbd "M-o") 'dired-omit-mode)))

The dired-mode-hook will override anything that was previously bound to M-o for dired-mode.

Andere Tipps

Edit: Ah, sorry, my answer wasn't relevant.

Firstly dired-x adds its bindings to the major mode map (dired-mode-map) and all minor mode maps take precedence over the major mode map.

Secondly, my assumption that your ns-win was using a minor mode may also be invalid. I really should have told you to link to that in the first place (you should always link to non-standard libraries).

Google suggests that its using the global keymap in which case it should never be overriding the dired map, but also that it's using super rather than meta as its modifier key, so I'm not at all sure I'm looking at the version you're using.

If your ns-win does provide a minor mode then the simplest option is probably to clobber the minor mode's binding with a custom function which checks the major mode and then either calls the original function or the dired-x function as appropriate.

You might use the Emacs key binding fallback approach to minimise the number of assumptions. Your test would be (eq major-mode 'dired-mode).


Original answer; not actually relevant to the question:

Minor mode map precedence is controlled by the order of the entries in minor-mode-map-alist, and that depends on the order in which libraries are loaded. The most recently loaded mode has the highest precedence (new entries are added at the front of the list).

See https://stackoverflow.com/a/5340797/324105 for one example of manipulating this alist in order to give a specific mode precedence (in your case you would likely want to use eval-after-load to perform the test, as it's a one-off).

Alternatively, you can just forcibly load/require both libraries in the desired sequence. Emacs takes fractionally longer to start up, but you don't need to worry about messing with the alist.

I'd just suggest using whichever approach you're comfortable with.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top