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

Use replace-buffer-contents to update formatting #45

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions blacken.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ If `fill', the `fill-column' variable value is used."
:type 'boolean
:safe 'booleanp)

(defcustom blacken-replace-buffer-contents-max-secs nil
"Max number of seconds for replacing buffer contents. See
`replace-buffer-contents' for more information."
:type 'float)

(defun blacken-call-bin (input-buffer output-buffer error-buffer)
"Call process black.

Expand Down Expand Up @@ -137,8 +142,6 @@ Return black process the exit code."
Show black output, if black exit abnormally and DISPLAY is t."
(interactive (list t))
(let* ((original-buffer (current-buffer))
(original-point (point))
(original-window-pos (window-start))
(tmpbuf (get-buffer-create "*blacken*"))
(errbuf (get-buffer-create "*blacken-error*")))
;; This buffer can be left after previous black invocation. It
Expand All @@ -150,10 +153,7 @@ Show black output, if black exit abnormally and DISPLAY is t."
(if (not (zerop (blacken-call-bin original-buffer tmpbuf errbuf)))
(error "Black failed, see %s buffer for details" (buffer-name errbuf))
(unless (eq (compare-buffer-substrings tmpbuf nil nil original-buffer nil nil) 0)
(with-current-buffer tmpbuf
(copy-to-buffer original-buffer (point-min) (point-max)))
(goto-char original-point)
(set-window-start (selected-window) original-window-pos))
(replace-buffer-contents tmpbuf blacken-replace-buffer-contents-max-secs))
(mapc 'kill-buffer (list tmpbuf errbuf)))
(error (message "%s" (error-message-string err))
(when display
Expand Down