Skip to content

Fix for Issue #48: Changed the black executable from string to list … #59

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion blacken.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"Name of the executable to run."
:type 'string)

(defcustom blacken-executable-list '(blacken-executable)
"Command (with extra arguments) to invoke black"
:type '(repeat string))
Copy link
Member

Choose a reason for hiding this comment

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

We can turn this into an empty list and then concatenate the list with the executable below.

Copy link
Author

@sbroberg sbroberg Apr 5, 2024

Choose a reason for hiding this comment

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

I did it this way because "python -m black" is equivalent to "black" in that both invoke black with no parameters. Otherwise, to configure it as you suggest would require you to set blacken-executable to "python" and blacken-executable-list (or whatever we'd rename it to) to ("-m" "black"), which seems sort of weird to me.

Alternatively, we can leave "black" in blacken-executable alone and have this empty list precede it, like so:

:command `(,@blacken-python-startup-list ,blacken-executable ,@(blacken-call-args))

and have the user-visible config option the string blacken-python-command-for-invocation. If this string is not nil, we would set blacken-python-startup-list to (blacken-python-command-for-invocation "-m").

This would make it more clear to users what the purpose of this setting is for, even if the implementation is more fiddly. It also has the advantage of leaving people's config intact if for some reason they had previously overridden blacken-executable (although my implementation does as well).


(defcustom blacken-line-length nil
"Line length to enforce.

Expand Down Expand Up @@ -92,7 +96,7 @@ output to OUTPUT-BUFFER. Saving process stderr to ERROR-BUFFER.
Return black process the exit code."
(with-current-buffer input-buffer
(let ((process (make-process :name "blacken"
:command `(,blacken-executable ,@(blacken-call-args))
:command `(,@blacken-executable-list ,@(blacken-call-args))
:buffer output-buffer
:stderr error-buffer
:connection-type 'pipe
Expand Down