I'm using drag-stuff, which defines a minor-mode (drag-stuff-mode), a corresponding keymap (drag-stuff-mode-map), and a globalized minor mode (drag-stuff-global-mode).

I want to make some changes to the default keybindings, and I'd like to use the globalized minor mode, but my changes to the keymap don't seem to affect the globalized minor mode.

For example, after turning on drag-stuff-global-mode, describing drag-stuff-mode-map shows:

 (M-left . drag-stuff-left)
 (M-right . drag-stuff-right)
 (M-down . drag-stuff-down)
 (M-up . drag-stuff-up))

I want to undefine M-left, so I evaluate:

(define-key drag-stuff-mode-map [M-left] nil)

but drag-stuff-mode-map remains unchanged, and I can confirm that M-left is still bound to drag-stuff-left.

If I use the regular (local) minor mode, everything behaves as expected, it's only when using the globalized minor mode that I run into this.

What's going on, and how can I achieve what I'm trying to do?


drag-stuff-mode is poorly behaved.

drag-stuff-define-keys sets/clobbers drag-stuff-mode-map, and it is called whenever the buffer-local drag-stuff-mode is enabled.

A 'globalized' minor mode is a global minor mode which controls a buffer-local minor mode, and it enables that buffer-local mode in every buffer to which it is applicable -- and will continue to call it as future applicable buffers are created.

As is usual, the minor mode's keymap is global, so your changes (which did work) were simply being undone again.

As a workaround you can use drag-stuff-mode-hook to do your own clobbering each time the buffer-local mode is enabled anywhere; but this is really a bug in the library, so you should raise an issue for it with the author.

(defun my-drag-stuff-mode-hook ()
  "Custom `drag-stuff-mode' behaviours."
  (define-key drag-stuff-mode-map (drag-stuff--kbd 'left) nil))

(add-hook 'drag-stuff-mode-hook 'my-drag-stuff-mode-hook)

n.b. Here I've used the helper function defined by the library in defining the key, but your own code was also functional.

  • Thanks, I was tearing my hair out over this. I'll raise an issue and maybe submit a PR to drag-stuff. – ivan Nov 1 '16 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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