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

Add initial support for blacken-region #20

Closed
wants to merge 3 commits into from

Conversation

pinn3
Copy link

@pinn3 pinn3 commented Feb 21, 2019

Resolves #11

Hacked together this quick implementation of blacken-region, but also my first serious attempt at elisp aside from my personal emacs configuration.

This will only work with valid top-level python blocks, as it copies the region to a new buffer, with leading whitespaces and all.

Would be nice to handle it, as mentioned here, but frankly I don't know enough about elisp to implement it myself

Feel free to suggest improvements!

@proofit404
Copy link
Contributor

Hi, thanks for your contribution!

Should it dedent and reindent region before applying black to it?

@pinn3
Copy link
Author

pinn3 commented Feb 28, 2019

@proofit404 Did my best to implement dedent-/reindent-ing the region. It works pretty well with valid python blocks, however, when I run it on an invalid block, it doesn't actually abort when black fails. I tried catching the error from blacken-buffer using condition-case, but didn't get it to work properly. Any ideas?

@pinn3
Copy link
Author

pinn3 commented Feb 28, 2019

Tried something like

(condition-case err
  (blacken-buffer)
  (throw 'err err))

but it wouldn't cancel any of execution beneath it either way, could it be because blacken-buffer is run inside a let?

@proofit404
Copy link
Contributor

To be honest I have no idea either.

@pinn3
Copy link
Author

pinn3 commented Mar 9, 2019

@proofit404 Ait, gonna have another go at this soon-ish

@wbolster
Copy link

wbolster commented May 3, 2019

see #25 for a wider discussion about this

@pinn3 pinn3 closed this Mar 11, 2021
@pinn3 pinn3 deleted the feature/blacken-region branch March 11, 2021 11:59
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.

blacken-region
3 participants