Skip to content

Conversation

AndreasArvidsson
Copy link
Member

@AndreasArvidsson AndreasArvidsson commented Jan 26, 2025

Inside/interior today is a modifier and will stay so in the future, but we are also introducing interior as a scope type. This will allow us to do "take inside" when on a if statement, python function and so on.

It now takes the closest of the nearest tree-sitter interior or surrounding pair. This is most useful for Python; in other languages with {} statement-blocks, the braces would already be easy to target, but now "take inside" behaves intuitively there as well.

The scm syntax @scope.interior have been replaced by @interior as its own scope type.

Fixes #1046

Checklist

  • I have added tests
  • [/] I have updated the docs and cheatsheet
  • [/] I have not broken the cheatsheet

Release notes

You can now use "inside" to refer to the inside body of a language scope (function, if statement, etc). This is especially useful for Python, because previously you had to think about what scope you were targeting -- "take inside" now just works.

It also works nicely for targeting the inside of C-style statements that don't have {} braces, like single line conditionals or loops.

In Python, this also means that you can now target the inside of the function ("take inside") even while the cursor is in a related location (such as in its name). Note that this behavior currently only exists for Python; we plan to port it to other languages as well since it is useful.

@AndreasArvidsson AndreasArvidsson requested a review from a team as a code owner January 26, 2025 13:49
…andlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts
…andlers/SurroundingPairScopeHandler/InteriorScopeHandler.ts
- {type: interiorOnly}
usePrePhraseSnapshot: false
initialState:
documentContents: <div>content</div> (hello)
Copy link
Member

Choose a reason for hiding this comment

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

It would be neat if this would give you this:

<div>|</div> (|)

@phillco phillco enabled auto-merge January 30, 2025 17:59
@phillco phillco added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit 21d78d5 Jan 30, 2025
15 checks passed
@phillco phillco deleted the interiorScope branch January 30, 2025 18:33
cursorless-bot pushed a commit that referenced this pull request Jan 30, 2025
Inside/interior today is a modifier and will stay so in the future, but
we are also introducing interior as a scope type. This will allow us to
do `"take inside"` when on a if statement, python function and so on.

It now takes the closest of the nearest tree-sitter interior _or_
surrounding pair. This is most useful for Python; in other languages
with {} statement-blocks, the braces would already be easy to target,
but now "take inside" behaves intuitively there as well.

The scm syntax `@scope.interior` have been replaced by `@interior` as
its own scope type.

Fixes #1046

## Checklist

- [x] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [/] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [/] I have not broken the cheatsheet

## Release notes

You can now use "inside" to refer to the inside body of a language scope
(function, if statement, etc). This is especially useful for Python,
because previously you had to think about what scope you were targeting
-- "take inside" now just works.

It also works nicely for targeting the inside of C-style statements that
don't have `{}` braces, like single line conditionals or loops.

In Python, this also means that you can now target the inside of the
function ("take inside") even while the cursor is in a related location
(such as in its name). Note that this behavior currently only exists for
Python; we plan to port it to other languages as well since it is
useful.

---------

Co-authored-by: Phil Cohen <[email protected]>
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.

Add a proper scope type for "inside"

2 participants