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

feature request: ignore patterns to send to formatter #665

Open
1 task done
kanghengliu opened this issue Mar 3, 2025 · 1 comment
Open
1 task done

feature request: ignore patterns to send to formatter #665

kanghengliu opened this issue Mar 3, 2025 · 1 comment
Labels
enhancement New feature or request P2 Not a priority. PRs welcome

Comments

@kanghengliu
Copy link

kanghengliu commented Mar 3, 2025

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

For injected formatter, add a lua match pattern variable to match and filter out some input_lines, as they break formatter.

Quick and dirty proof of concept:
kanghengliu@30568d6

This commit hard codes the matching patterns. Also it does not paste back the matched lines after formatting.

update: added a filter for python only and allow matching for multiple lines.
kanghengliu@ca99f29

Provide background

When editing a markdown file, ipython magic commands and shell commands will prevent python formatters from functioning.
Example1:

%%time
print("hello")

Example2:

!pip install randomstuff

Black will break, since this is not a valid python chunk, however, modern linters will highlight the chunk just fine.
Both chunks are valid in jupyter notebook with IPython.

What is the significance of this feature?

strongly desired

Additional details

I've attempted to instruct the formatters to ignore certain patterns, however it is reasonably out of scope for code formatters to handle "broken" formats. Many formatters that i've found will not support this, and it makes sense for them to do so.

For additional use cases, see my issue at molten.nvim where I attempt to lint and format a chunk with cell magic.

@kanghengliu kanghengliu added the enhancement New feature or request label Mar 3, 2025
@stevearc
Copy link
Owner

stevearc commented Mar 5, 2025

I would review a PR for this. I think I would prefer a more general approach, as expressing all of the possible changes someone might want to make as some key-value pattern-match DSL will be a challenge. We're already doing some modification of the text chunks; we could also pass them to a user-provided function for additional modification. This would likely happen around remove_surrounding and restore_surrounding

@stevearc stevearc added the P2 Not a priority. PRs welcome label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 Not a priority. PRs welcome
Projects
None yet
Development

No branches or pull requests

2 participants