drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Avy integration? #48

Open ethan-leba opened 2 years ago

ethan-leba commented 2 years ago

Giving switching over Symex from lispy another shot now that I've got a bit more free time. I'm having a hard time getting over the lack of avy bindings for navigation, as that's a major component of my lispy navigation strategy. I could add bindings for myself quite easily, but I was wondering if there was any sort of philosophical reason why avy isn't included? Otherwise, it might make sense to add some avy bindings to the default symex map.

countvajhula commented 2 years ago

There's no philosophical reason as such, mostly just that no one has brought it up before 🙂 . My first thought is, does this need a deep integration? Depending on how complex adding it would be, it could potentially be a simple Tip in the README to add a keybinding for avy to the symex evil map. Or doing it as an add-on package symex-avy may be another option, as that would avoid introducing a dependency.

I didn't immediately find docs for how avy works in Lispy. But based on vague recollections, is it something like, you press some keybinding and then it shows you a visual index for every subcomponent of the current expression, allowing you to jump to it directly? That is, the same as avy but constrained to the current expression? Is there any other functionality or is it just this one?

ethan-leba commented 2 years ago

There's no philosophical reason as such, mostly just that no one has brought it up before 🙂 .

I suppose you might not have a good answer to this if you don't use avy currently, but is there any sort of pre-existing symex feature that provides some roughly equivalent behavior? For example you could say evil-ex-search provides a rough analog for normal state

My first thought is, does this need a deep integration?

I don't know how the internals of symex work, but I wouldn't think so!

Or doing it as an add-on package symex-avy may be another option, as that would avoid introducing a dependency.

FWIW, it's already a dependency of lispy -- though I assume in the (distant) future you may want to choose a different backend

I didn't immediately find docs for how avy works in Lispy. But based on vague recollections, is it something like, you press some keybinding and then it shows you a visual index for every subcomponent of the current expression, allowing you to jump to it directly? That is, the same as avy but constrained to the current expression? Is there any other functionality or is it just this one?

Yep, the main cases are for jumping to any symbol contained in the current sexp, or jumping to any sub-expressions:

http://oremacs.com/lispy/#lispy-ace-symbol http://oremacs.com/lispy/#lispy-ace-paren

countvajhula commented 2 years ago

I suppose you might not have a good answer to this if you don't use avy currently, but is there any sort of pre-existing symex feature that provides some roughly equivalent behavior? For example you could say evil-ex-search provides a rough analog for normal state

There's not really an equivalent. Avy-style navigation is "search based", whereas probably everything that Symex provides right now is structural. I agree they are orthogonal and therefore not incompatible. The structural commands that can approximate this in some cases are the variations of f and b (traverse), or } and { (leap) or gj gk (line-based up and down). Branch memory also helps by preserving recent positions, so it's possible that in some cases when you are searching to return to where you were, that would not be necessary (in favor of just going back up -- or "down" if you have your axis flipped, as many users do). You can also use normal evil search / (or even avy itself!) while in Symex state, so that is probably a closer equivalent to avy.

Yep, the main cases are for jumping to any symbol contained in the current sexp, or jumping to any sub-expressions:

http://oremacs.com/lispy/#lispy-ace-symbol http://oremacs.com/lispy/#lispy-ace-paren

Thanks for the links. Oleh's got some great docs! Looking at the behavior there, I think for Symex it would need to operate a little differently. For the "symbol" feature, it need not highlight/select the symbol but instead simply jump to it as if we had navigated there, and the "paren" feature looks fine as is, though technically it shouldn't show targets within docstrings and comments, but that's a minor issue, probably not worth addressing.

But in the meantime, this config would add the above commands to the Symex minor mode map (usable in both Symex and Insert states), as you originally hinted at:

(define-key symex-mode-map (kbd "M-s") #'lispy-ace-symbol)
(define-key symex-mode-map (kbd "M-p") #'lispy-ace-paren)

(e.g. in the :config section of use-package)

FWIW, it's already a dependency of lispy -- though I assume in the (distant) future you may want to choose a different backend

In that case it could be fine to add avy support directly to Symex (PR welcome, if you are so moved!). There is a plan to organize the package in terms of dependencies down the line (#26 ), and it shouldn't add much additional work to decouple any avy-related functionality at that stage.

countvajhula commented 2 years ago

Btw @ethan-leba I owe you an update on the tree-sitter stuff. Long story short, all of us Symex contributors have had a lot going on and so the tree-sitter work has been ambling along at a slow and steady pace. I'm still committed to migrating a lot of the primitive functionality to tree-edit once the initial prototype is ready, and the other contributors are in agreement that that is the next step. For reference, the PR #47 is the latest one on the tree-sitter effort, and I think once that's in (criteria being minimal rather than comprehensive functionality) we will probably do a release and explore tree-edit as the next step, probably along with #26 . I'm looking forward to exploring a proper integration with tree-edit, and I hope it won't be too long now! Thanks for your patience 🙂

markgdawson commented 2 years ago

lispy-ace-symbol didn't quite work for me. It seemed to drop me at the end of the symbol, with the region active.

The following (a nasty hack) works well for me:

(defun symex-ace-symbol ()
  "Jump to any symbol in current symex."
  (interactive)
  (lispy-ace-symbol 100)
  (call-interactively 'lispy-different)
  (deactivate-mark))

Note: I've chosen to add the 100 argument to include 100 upward levels in the search (good enough to show all of the current top level sexp), but you may wish to do this differently.

Then do:

(define-key symex-mode-map (kbd "M-s") #'lispy-ace-symbol)