Open TheBB opened 8 years ago
Original comment by Wouter Bolsterlee (Bitbucket: wbolster, GitHub: wbolster):
fwiw, i have a hack in place at https://github.com/wbolster/evil-text-object-python
Original comment by Wouter Bolsterlee (Bitbucket: wbolster, GitHub: wbolster):
thanks!
follow-up question: what is the preferred way for a package to define additional text objects that are major mode specific? i think an autoloaded setup function for the user to call makes sense, but what should it do? add a hook? and what should it do with possibly existing local maps? (i guess define-key does not initialize the map automatically.)
Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):
Something like
(define-key evil-operator-state-local-map "iw" 'my-inner-word)
(define-key evil-visual-state-local-map "iw" 'my-inner-word)
should work (from a major-mode hook). Alternatively you can create a buffer local keymap for both
(let ((m (make-sparse-keymap)))
(define-key evil-operator-state-local-map "i" m)
(define-key evil-visual-state-local-map "i" m)
(define-key m "w" 'my-inner-word))
These *-local-map keymaps have precedence over the other keymaps. This way only the specified binding are replaced, the rest is still accessible through the global maps.
I remember this previously not working, but it seems to work as expected now. Will double check it's not something in my config. Anyone had any issues with this?
(evil-define-key '(visual operator) emacs-lisp-mode-map
"iw" #'foo)
Originally reported by: Wouter Bolsterlee (Bitbucket: wbolster, GitHub: wbolster)
is it possible to specify (and bind) a major-mode specific text object, e.g. "inner-foo" when editing foo files?
it seems the inner and outer text object maps are not buffer-local. should i
(make-variable-buffer-local)
from a major mode hook?