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 drag left/right commands should drag pairs inside maps and binding boxes #529

Closed
PEZ opened this issue Dec 20, 2019 · 8 comments
Closed
Labels
paredit Paredit and structural editing

Comments

@PEZ
Copy link
Collaborator

PEZ commented Dec 20, 2019

Issue Type: Feature Request

In Cursive Paredit, the drag commands have special behaviour inside maps and binding boxes. Example:

(let [a 10
      |b 11])

Dragging left will do this:

(let [|b 11
      a 10])

I think Calva should follow the Cursive way here.

Ping: @bdevel

Update with demo gif:

drag-pairs-in-binding-box

@PEZ PEZ added the paredit Paredit and structural editing label Dec 20, 2019
@PEZ
Copy link
Collaborator Author

PEZ commented Feb 7, 2021

Like so:

drag-pairs-in-maps

(The map gets a drag-by-pairs treatment.)

Now works continues with other binding lists... 😄

@PEZ PEZ mentioned this issue Feb 7, 2021
29 tasks
@PEZ
Copy link
Collaborator Author

PEZ commented Feb 7, 2021

And now in these binding boxes:

  • let
  • for
  • loop
  • binding
  • with-local-vars

Demo:

drag-pairs-in-binding-box

Questions for anyone stumbling across this:

  • What more binding boxes do you know about?
  • Similar treatments make sense in more scenarious, right? Thinking about things like cond and case.

@bdevel
Copy link

bdevel commented Feb 8, 2021

Bravo! That's awesome. Above and beyond expectations.

I scanned Clojure's core.clj for functions that have bindings similar to let. Here is what I found (in addition to the ones already mentioned)

(doseq [x [-1 0 1]
        y [1  2 3]] 
  (prn (* x y)))
;; with-redefs
(with-redefs [type (constantly java.lang.String)
              class (constantly 10)]
         (println (type []) " " (class [])))

Plenty of other macros have bindings but not in pairs or they use hashmaps.

For macros with "clauses" here's what I came up with:

case
cond
condp
cond->
cond->>

The oddball is condp which takes two arguments before the pairs:

(condp apply [2 3]
  = "eq"
  < "lt"
  > "gt")
;;=> "lt"

In general, and specifically for custom binding macros, it is difficult to automatically determine if the items need to be moved in pairs. You might assume that if there are multiple lines with sets of two on each, that they are binding pairs. That may be challenging to implement and in my opinion probably not worth it. It would be worse if you're moving in pairs and the user doesn't want that.

As an alternative, you could treat a selected region as a single s-expression. This would allow manually selecting two items to move them between other expressions. However, if I recall, there may have been an issue with the dragging with an active selection. Ideally the selection would be maintained.

@PEZ
Copy link
Collaborator Author

PEZ commented Feb 8, 2021

Thanks for helping with collecting these!

It seems that with the clausy forms both case and condp are oddballs in that they allow a single default form at the end.... My head starts to spin when trying to figure out how to deal with it. I think I might collect my wins with the map and binding boxes for now. 😄

@bpringe bpringe closed this as completed in f45c0f2 Feb 9, 2021
@muhajirdev
Copy link

muhajirdev commented Feb 27, 2021

how did you guys do the "drag"? what's the shortcut?

@PEZ
Copy link
Collaborator Author

PEZ commented Feb 27, 2021

@muhajirdev , search for ”Paredit drag” in the command palette. The commands and their shortcuts should appear. They are also listed here: https://calva.io/paredit/

That said, in the animation above, I use the default shortcuts:

  • Drag forwards: ctrl+alt+shift+f
  • Drag backwards: ctrl+alt+shift+b

I'm considering if we should change those shortcuts to something simpler. alt+down/up, maybe...

@bpringe
Copy link
Member

bpringe commented Feb 28, 2021

I'm considering if we should change those shortcuts to something simpler. alt+down/up, maybe...

Probably should be careful there since that maps to moving lines up and down by default, but of course in Clojure that action doesn't make a lot of sense. Not saying it shouldn't be overridden 🤷‍♂️

@PEZ
Copy link
Collaborator Author

PEZ commented Mar 1, 2021

That was my reasoning, actually. Moving lines up/down doesn't make much sense at all. And with @crispinb 's PR with inComment when contexts, #1030, we can keep the moving of lines happen there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
paredit Paredit and structural editing
Projects
None yet
Development

No branches or pull requests

4 participants