rejeep / drag-stuff.el

Drag stuff around in Emacs
233 stars 12 forks source link

Difficulty customizing keybindings in global minor mode #21

Closed ivanbrennan closed 7 years ago

ivanbrennan commented 7 years ago

I use drag-stuff-global-mode, and I prefer keybindings that are different from the ones defined in drag-stuff-define-keys.

If I use the local minor mode, I can customize drag-stuff-mode-map in a straightforward way, but in the global minor mode, my keybindings refuse to take hold unless I wrap them in a defun and add the resulting function to drag-stuff-mode-hook.

(defun ivan/bind-drag-stuff-keys ()
  ;; unset the defaults
  (define-key drag-stuff-mode-map (drag-stuff--kbd 'up) nil)
  (define-key drag-stuff-mode-map (drag-stuff--kbd 'down) nil)
  (define-key drag-stuff-mode-map (drag-stuff--kbd 'right) nil)
  (define-key drag-stuff-mode-map (drag-stuff--kbd 'left) nil)
  ;; apply my bindings
  (define-key drag-stuff-mode-map (kbd "C-M-k") 'drag-stuff-up)
  (define-key drag-stuff-mode-map (kbd "C-M-j") 'drag-stuff-down)
  (define-key drag-stuff-mode-map (kbd "C-M-l") 'drag-stuff-right)
  (define-key drag-stuff-mode-map (kbd "C-M-h") 'drag-stuff-left))

(add-hook 'drag-stuff-mode-hook
          'ivan/bind-drag-stuff-keys)

(drag-stuff-global-mode t)

Without resorting to the above use of hooks, my custom bindings get clobbered by drag-stuff-define-keys, though I don't yet understand why this is only an issue in the global mode.

I'm still learning elisp, but I'm under the impression that this workaround shouldn't be necessary. I've noticed that a lot of packages will provide a function like drag-stuff-define-keys but leave it up to the user to actually call it, as this provides more flexibility.

rejeep commented 7 years ago

I don't know why this would only be an issue in the global mode, as drag-stuff defines the key bindings when starting the mode (https://github.com/rejeep/drag-stuff.el/blob/master/drag-stuff.el#L343).

As you say, usually packages leave it up to the user to call it. This was one of my first packages I wrote and I guess I just didn't know better then and this is legacy from that time.

It may not be the best solution, but you could advise drag-stuff-define-keys to do nothing. I would also accept a pull request to remove the automatic bindings with an updated README for how to do it manually.

articuluxe commented 7 years ago

I also use the global mode, and I also configure the prefix keys separately from the defaults, but don't need to use hooks. You can simply do

(setq drag-stuff-modifier '(meta shift))

before the package is loaded. The defvar will not override an existing value, for reasons just such as this. I do this in the :init clause of a use-package declaration, but one could as easily do this before the require statement.

Then I just call (drag-stuff-global-mode 1). No need to do anything with drag-stuff-define-keys. Unless I'm missing something, doesn't this give you what you need?

On Nov 3, 2016, at 1:17 AM, Johan Andersson notifications@github.com wrote:

I don't know why this would only be an issue in the global mode, as drag-stuff defines the key bindings when starting the mode (https://github.com/rejeep/drag-stuff.el/blob/master/drag-stuff.el#L343).

As you say, usually packages leave it up to the user to call it. This was one of my first packages I wrote and I guess I just didn't know better then and this is legacy from that time.

It may not be the best solution, but you could advise drag-stuff-define-keys to do nothing. I would also accept a pull request to remove the automatic bindings with an updated README for how to do it manually.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ivanbrennan commented 7 years ago

@danrharms That would work if I was just trying to use a different modifier for drag-stuff bindings, but I actually want to use modified h, j, k, l rather than modified <left>, <down>, <up>, <right>.

rejeep commented 7 years ago

Closing via #22