noctuid / lispyville

lispy + evil = lispyville
GNU General Public License v3.0
315 stars 23 forks source link

Make evil text object bindings buffer local #52

Closed yuhan0 closed 5 years ago

yuhan0 commented 5 years ago

Defines two new keymaps which are bound to "i" and "a" in buffer-local visual and operator states when lispyville-mode is activated, and unbound when deactivated.

noctuid commented 5 years ago

I need to look into this further. Mode-local text objects don't work correctly with evil-define-key (they won't override defaults). In the past, I've been using hooks and buffer-local definitions as a workaround, but it looks like using evil-define-minor-mode-key may work correctly. I think using that would be a better approach if possible. For example, if another mode wanted to bind i and a locally for text objects like this, there would be a conflict.

yuhan0 commented 5 years ago

Hmm, I didn't think of other modes binding "i" and "a" buffer-locally, do you know of any which do that? Do you mean using evil-define-minor-mode-key like this:

(evil-define-minor-mode-key '(visual operator)
  'lispyville-mode
  "i"  'lispyville-inner-text-objects-map
  "a"  'lispyville-outer-text-objects-map)

I tried it and it ends up overshadowing the regular inner/outer text object maps entirely.

noctuid commented 5 years ago

Hmm, I didn't think of other modes binding "i" and "a" buffer-locally, do you know of any which do that?

I'm guessing that there aren't any other package that do this, but my concern is that no two packages could use this solution, and this is a problem that any minor mode that wants to have text objects for only its mode will have.

I meant something like this:

(evil-define-minor-mode-key '(operator visual) 'lispyville-mode
  "il" #'lispyville-inner-list)

But using the prefix maps should still work:

(evil-define-minor-mode-key '(visual operator)
  'lispyville-mode
  "i"  lispyville-inner-text-objects-map
  "a"  lispyville-outer-text-objects-map)

I think you had quoted them accidentally.

The other alternative would be to bind il, al, etc. locally using lispyville-mode-hook, which is what I've been using elsewhere, but that's much less ideal.

yuhan0 commented 5 years ago

Closing this PR because it turns out that I preferred having these text objects available in non-lispyville modes after all, so making them buffer-local was a loss in functionality. Feel free to copy my code/documentation edits if you do decide to implement this in the future :)