noctuid/lispyville

Set text objects only in lispyville-mode

meliache opened this issue · 2 comments

I started using the evil-textobj-treesitter package and use it to bind the f to the treesitter function textobject. But treesitter has no emacs lisp support, so there I still rely on the lispyville text objects. Both packages modify the global evil-inner-text-objects-map and evil-outer-text-objects-map maps, so I run into conflicts when using both.

I looked into lispyville.el and found the comment (by @noctuid from 2018):

         ;; TODO only define in `lispyville-mode-map'

So I guess it is a known issue. Any idea how to go about it? I guess this is an issue that every package that adds custom textobjects to emacs which only work in certain major modes has and I'd be interested if anyone has a solution. My idea would be to have custom textobject maps that are toggle via minor modes, but then one should somehow make evil respect those custom maps.

I created an equivalent issue for evil-textobj-treesitter here.

There is not a perfect solution for this since evil only provides the global text object maps. I have an issue open on some repo or some notes somewhere where I evaluated different workarounds, but I can't seem to find it. I will continue looking. Maybe I could create a lispyville-inner-text-objects-map, for example, that inherits from evil-inner-text-objects-map and bind that in 'operator lispyville-mode-map. I will try that and see if it works. The workaround for now would be to bind the keys yourself to a menu item that selects a different text object depending on whether lispyville-mode is enabled. You can use general-predicate-dispatch to simplify this (it is a small macro you can copy if you do not use general.el).

Thanks for the tipps and looking into this, this general.el feature looks useful, just now I noticed that you're the dev. So far I've only used general.el occasionally within use-package (mostly via :general) when the built-in :bind wasn't enough and I wanted to configure bindings for specific evil states only, but I'm only aware of a small subset of its features.