Skip to content

Commit 9daacd1

Browse files
Condense project blacken check
1 parent fbb0a71 commit 9daacd1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

blacken.el

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,12 @@ Return black process the exit code."
121121
(list "--pyi"))
122122
'("-")))
123123

124-
(defun blacken-regex-in-file (regex file)
125-
"Reads a file and returns a list of lines in that file"
126-
(with-temp-buffer
127-
(insert-file-contents file)
128-
(re-search-forward regex nil t 1)))
129-
130124
(defun blacken-project-is-blackened (&optional display)
131125
"Whether the project has a pyproject.toml with [tool.black] in it."
132-
(let ((parent (locate-dominating-file default-directory "pyproject.toml")))
133-
(and parent
134-
(blacken-regex-in-file "^\\[tool.black\\]$" (concat parent "pyproject.toml")))))
126+
(when-let ((parent (locate-dominating-file default-directory "pyproject.toml")))
127+
(with-temp-buffer
128+
(insert-file-contents (concat parent "pyproject.toml"))
129+
(re-search-forward "^\\[tool.black\\]$" nil t 1))))
135130

136131
;;;###autoload
137132
(defun blacken-buffer (&optional display)

0 commit comments

Comments
 (0)