Skip to content

Conversation

@jramosg
Copy link
Contributor

@jramosg jramosg commented Feb 3, 2026

What has changed?

When attempting to perform a "slurp backward" operation with a previous ignored/commented expression (using #_ ), the operation would produce incorrect results and throw and error.

  • The forwardSexp method in toker-cursor was treating #_ as a single token instead of treating #_(form) as a unified s-expression.
    Now forwardSexp always moves past the complete ignored form #_(form) as a single unit:
case 'ignore':
  // Always include the ignored form as part of this sexp
  this.next();                                              // Move past #_
  this.forwardSexp(skipComments, skipMetadata, skipIgnoredForms);  // Move past (form)
  if (skipIgnoredForms) {
    // When skipping, continue to the next non-ignored sexp
    break;
  }
  // When not skipping, stop here: the ignored form is the sexp we found
  if (stack.length <= 0) {
    return true;
  }
  break;
  • backwardSexp would position the cursor at the form being ignored rather than at the #_ marker itself when slurping.
  • After calling backwardSexp to find the previous form, we now check if it's preceded by an #_ ignore marker

Fixes #3025

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

Enhance the backward slurp functionality to include ignore markers
(#_) when navigating to previous sexps. This ensures that slurping
captures the ignored forms as part of the slurped content, improving
the handling of ignored expressions in the editing process.
Fixes Slurp backward with previous commented expr issue
Fixes BetterThanTomorrow#3025
Update the test case to correctly handle ignored forms when
skipIgnoredForms is false. This ensures that the cursor behaves
as expected when encountering ignored tokens in the input.
This commit introduces tests to verify the behavior of the
backward slurp operation when encountering forms with ignore
markers preceding empty lists. The tests ensure that the
slurping operation behaves correctly in these scenarios,
maintaining the integrity of the document structure.
Clarify comments in the forwardSexp method to enhance readability.
This change improves the understanding of the logic when skipping
ignored forms and when to stop at the found ignored form.
@netlify
Copy link

netlify bot commented Feb 3, 2026

Deploy Preview for calva-docs ready!

Name Link
🔨 Latest commit 9080594
🔍 Latest deploy log https://app.netlify.com/projects/calva-docs/deploys/698342fae8bf2500080d28db
😎 Deploy Preview https://deploy-preview-3026--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.

Copy link
Collaborator

@PEZ PEZ left a comment

Choose a reason for hiding this comment

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

Thanks!

@jramosg jramosg merged commit 82559cd into BetterThanTomorrow:dev Feb 4, 2026
1 check passed
@jramosg jramosg deleted the error-slurp-backward-commented-expresssions branch February 4, 2026 13:01
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