Skip to content

add squeeze paredit action #2893

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

conao3
Copy link
Contributor

@conao3 conao3 commented Jul 13, 2025

What has changed?

  • Add Paredit Squeeze Action inspired by puni-squeeze.

Fixes #2892

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Made sure there is an issue registered with a clear problem statement that this PR addresses, (created the issue if it was not present).
    • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tests
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

Copy link

netlify bot commented Jul 13, 2025

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 967da18
🔍 Latest deploy log https://app.netlify.com/projects/calva-docs/deploys/6873daf681741300086c832f
😎 Deploy Preview https://deploy-preview-2893--calva-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

isMulti: boolean,
onRange: (doc: EditableDocument, range: [number, number]) => Promise<void> = async () => {}
) {
// TODO: support multi-cursor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, our squeeze function don't support multi-cursor like killLeft

@@ -2690,6 +2696,11 @@
"key": "ctrl+alt+r ctrl+alt+q",
"when": "calva:keybindingsEnabled && editorLangId == clojure && editorTextFocus && paredit:keyMap =~ /original|strict/"
},
{
"command": "paredit.squeeze",
"key": "ctrl+alt+r ctrl+alt+r",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default shortcuts is hard. But we do have defaults for almost (maybe all) Paredit commands. I'm thinking that since there is a cut in there, maybe ctrl+alt+r ctrl+alt+x. Though I also note the ctrl+alt+x is free. The default for splice is ctrl+alt+s, this is sort of splice + cut. So maybe ctrl+alt+x ctrl+alt+s. If we don't see any other “... + cut” on the horizon, then just ctrl+alt+x may do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you liked ctrl+alt+r ctrl+alt+r... but apparently not.
#2892 (comment)

IMO, ctrl+alt+x or ctrl+alt+c are quite awkward to press, so I prefer either ctrl+alt+r ctrl+alt+r or ctrl+alt+r ctrl+alt+k.
r stands as a two-key shortcut for generic rewrap. k comes from "kill," though it may no longer actually perform a kill operation. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could go without binding it to something default, and users can bind it to whatever is convenient for them.

Comment on lines +757 to +781
export async function squeezeSexpr(
doc: EditableDocument,
onRange: (doc: EditableDocument, range: [number, number]) => Promise<void>,
start = doc.selections[0].active
) {
const startC = doc.getTokenCursor(start);

startC.backwardList();
if (startC.backwardUpList()) {
const outerStart = startC.offsetStart;

const endC = doc.getTokenCursor(startC.offsetStart);
endC.forwardSexp();
const outerEnd = endC.offsetStart;
endC.previous();
const innerEnd = endC.offsetStart;

startC.downList();
const innerStart = startC.offsetStart;

await onRange(doc, [innerStart, innerEnd]);

return doc.model.edit([new ModelEdit('changeRange', [outerStart, outerEnd, ''])], {});
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider sharing the code for finding the text to replace with spliceSexp? I'm not saying we should, but it may be a good idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! I try it.

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

Successfully merging this pull request may close these issues.

2 participants