Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paredit: support "raise" and "splice" #68

Closed
pesterhazy opened this issue Jul 23, 2017 · 9 comments
Closed

Paredit: support "raise" and "splice" #68

pesterhazy opened this issue Jul 23, 2017 · 9 comments

Comments

@pesterhazy
Copy link

Fantastic to see expand-region (Cmd-[ and Cmd-]) in maria - it's one of the most intuitive selection primitives.

It would be great to have also paredit shortcuts that allow you to splice a form into its parent.

Paredit usually supports three variants:

  • paredit-splice-sexp-killing-forward
  • paredit-splice-sexp-killing-backward
  • paredit-raise-sexp

Raise is the most useful variant IMO, but paredit-splice-sexp-killing-forward can help as well, e.g. when removing a let.

@mhuebert
Copy link
Owner

mhuebert commented Aug 8, 2017

Tracking these now in #50

@mhuebert mhuebert closed this as completed Aug 8, 2017
@mhuebert
Copy link
Owner

@pesterhazy in the dev channel, some new paren-related behaviour has been introduced:

  1. splice via Option/Alt-S or by pressing backspace in front of an opening paren. (eg. (|a) + backspace = |a - took some inspiration from parinfer here)
  2. Hold Command/Control and use the arrow keys to expand the selection left/right/up; the down arrow returns the selection step-by-step to the starting point. Add the shift key to select the top level form.

Example doc: https://dev.maria.cloud/gist/7b46a1be3c6e2c25766148e255719220

Feedback welcome!

@pesterhazy
Copy link
Author

Nice! Some feedback:

  • expand-region is intuitive and command+arrow keys are great keybindings for it. However, Mac users may be used to seeing Cmd+left and Cmd+right to for HOME/END (although ^A/^E still works). But I have to say your version is even better than expand-region, because it allows you to expand both ways!
  • not sure about splice. I know this under the name unwrap. I tend to use raise more often than unwrapping.
  • really like backspace to unwrap
  • in the example :b doesn't seem to be recognized as a symbol when using Cmd-left and right

@mhuebert
Copy link
Owner

mhuebert commented Sep 1, 2017 via email

@pesterhazy
Copy link
Author

Right, my point was that it would be great if :keyword was always treated as an atomic token, rather than composed of : and foo - it felt as if they were separated when I was experimenting.

FWIW I did a presentation about structural editing earlier this year: https://youtu.be/ubcERtDyLDw?t=10m52s with my attempt at explaining splicing/raising after the 18m mark.

@mhuebert
Copy link
Owner

mhuebert commented Sep 1, 2017

Ah, I can see how it would feel that way, depending on where the cursor starts:

sep-01-2017 20-07-08

but again, I'm not sure this is ideal. maybe it makes sense to grow the selection to the whole token before expanding out to the right.

Thanks for the link to the presentation. I'd like to think about which commands would most need their own shortcut, vs. being easy/fast to achieve using selections with copy/paste. Since M1 (command/control) both selects the form & is also combined with C and V for copy/paste, one can do a lot of manipulation with very few keys to memorize -- eg. Raise:

While holding Command/Ctrl...
     - C (copies form)
     - Up x2 (selects outer bounds of parent form)
     - V (pastes form)

Not quite as fast as a dedicated command, but after learning Command + arrow keys, one could discover manipulations like this intuitively without ever needing to know the special names or bindings.

@pesterhazy
Copy link
Author

All good points. One last point in favor of raise is that it neatly corresponds to a logical operation, for a lack of a better word. For example

(if condition? (foo) (bar))

If you realize that condition? is always true, you can just raise (foo), eliminating the conditional in a single operation.

@jackrusher
Copy link
Collaborator

One way to think of the difference between paredit, which has many special commands for different actions, and this selection-based approach is like the difference between an object with many special purpose methods and a data structure with a small number of composable functions. If we can discover a good set of interaction primitives here, there's simply much less to learn/memorize/practice to reach a high level of ability in structural editing.

Also, once we have this basic set of orthogonal actions, it should be trivial to support an extension mechanism that allows on to combine them into single commands that can be bound to keys by those who want them. (For example, a raise function could be added as a user defined function that calls select current form, select-up, select-up, paste-replace).

@mhuebert
Copy link
Owner

mhuebert commented Sep 5, 2017

I like this idea of giving nice names to these primitives & making it a simple matter to combine them into bind-able commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants