Skip to content

Commit

Permalink
Format buffer when no region is active.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbartlensky committed Jul 10, 2021
1 parent 47378ff commit 34f0ef7
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions rustic-rustfmt.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,20 @@ This operation requires a nightly version of rustfmt.
(unless (or (eq major-mode 'rustic-mode)
(eq major-mode 'rustic-macro-expansion-mode))
(error "Not a rustic-mode buffer."))
(let* ((buf (current-buffer))
(file (buffer-file-name buf))
(r-begin)
(r-end))
(cond ((region-active-p)
(setq r-begin begin)
(setq r-end end))
(t
(setq r-begin (region-beginning))
(setq r-end (region-end))))
(let ((start (+ 1 (count-lines 1 r-begin)))
(len (- (count-lines r-begin r-end) 1)))
(rustic-compilation-process-live t)
(rustic-format-start-process
'rustic-format-file-sentinel
:buffer buf
:command
(append (list rustic-cargo-bin "+nightly" "fmt" "--")
(rustic-compute-rustfmt-file-lines-args file
start
(+ start len)))))))
(if (not (region-active-p)) (rustic-format-buffer)
(let* ((buf (current-buffer))
(file (buffer-file-name buf)))
(let ((start (+ 1 (count-lines 1 begin)))
(len (- (count-lines begin end) 1)))
(rustic-compilation-process-live t)
(rustic-format-start-process
'rustic-format-file-sentinel
:buffer buf
:command
(append (list rustic-cargo-bin "+nightly" "fmt" "--")
(rustic-compute-rustfmt-file-lines-args file
start
(+ start len))))))))

;;;###autoload
(defun rustic-format-buffer ()
Expand Down

0 comments on commit 34f0ef7

Please sign in to comment.