Skip to content

Conversation

@jramosg
Copy link

@jramosg jramosg commented Jan 20, 2026

What has changed?

This PR adds pair selecting behavior for cond forms

Implementation

  • Added conditionalForms constant to identify forms that have test/expr pairs
  • Added getConditionalFormPairOffset() function to handle offset requirements
  • Modified isInPairsList() to detect cond forms in lists
  • Updated currentSexpsRange() to use pairOffset when calculating pair indices
  • Added comprehensive tests for cond form pair selection

Status

Currently implemented:

  • cond - fully working with tests
  • case and condp should be included with other issue/PR because they can be different (defaults, result-expr or result-fn, etc.)

Why This Approach

Rather than hardcoding offset values directly in the pairing logic, we:

  1. Created a separate getConditionalFormPairOffset() function that determines the offset dynamically based on the form type. This makes easier to add more conditional forms in the future
  2. This keeps the main currentSexpsRange() logic clean and maintainable

Alternative Considered

Could have created separate functions for each form type, but this would duplicate logic. The offset approach is more maintainable.

Fixes #2991

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.)

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit a68823d
🔍 Latest deploy log https://app.netlify.com/projects/calva-docs/deploys/69707923d35fa0000878ad82
😎 Deploy Preview https://deploy-preview-2992--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.

This change introduces a test case that verifies the behavior of
growing selections to test/expr pairs in cond forms, specifically
when comments are present between the pairs. This ensures that
the paredit functionality handles such scenarios correctly.
Changed the export of conditionalForms to a constant to
encapsulate its usage within the module. This improves
encapsulation and prevents unintended modifications from
other modules.
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.

1 participant