Skip to content

Commit d6929cf

Browse files
dakraproofit404
authored andcommitted
Add option to use fill-column for line length (#14)
When `blacken-line-length` is `nil` it doesn't get passed as a command line argument. When it is the symbol `fill` it uses the `fill-column` variable.
1 parent 4806101 commit d6929cf

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

blacken.el

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
;;
3939
;;; Code:
4040

41+
(require 'cl-lib)
42+
4143

4244
(defgroup blacken nil
4345
"Reformat Python code with \"black\"."
@@ -48,9 +50,15 @@
4850
:type 'string)
4951

5052
(defcustom blacken-line-length nil
51-
"Line length to enforce."
52-
:type 'number
53-
:safe 'numberp)
53+
"Line length to enforce.
54+
55+
It must be an integer, nil or `fill'.
56+
If `fill', the `fill-column' variable value is used."
57+
:type '(choice :tag "Line Length Limit"
58+
(const :tag "Use default" nil)
59+
(const :tag "Use fill-column" fill)
60+
(integer :tag "Line Length"))
61+
:safe 'integerp)
5462

5563
(defcustom blacken-allow-py36 nil
5664
"Allow using Python 3.6-only syntax on all input files."
@@ -95,7 +103,10 @@ Return black process the exit code."
95103
"Build black process call arguments."
96104
(append
97105
(when blacken-line-length
98-
(list "--line-length" (number-to-string blacken-line-length)))
106+
(list "--line-length"
107+
(number-to-string (cl-case blacken-line-length
108+
('fill fill-column)
109+
(t blacken-line-length)))))
99110
(when blacken-allow-py36
100111
(list "--py36"))
101112
(when blacken-fast-unsafe

0 commit comments

Comments
 (0)