fix(format): update missing values & set buffer modification
This prevents apheleia complaining about the editing buffer being killed. Co-authored-by: Wang Liao <lwlw1988@gmail.com>
This commit is contained in:
parent
e47accb773
commit
7920b0d46c
1 changed files with 4 additions and 3 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
(defun +format-region (start end &optional callback)
|
(defun +format-region (start end &optional callback)
|
||||||
"Format from START to END with `apheleia'."
|
"Format from START to END with `apheleia'."
|
||||||
(when-let* ((command (apheleia--get-formatter-command
|
(when-let* ((command (apheleia--get-formatters
|
||||||
(if current-prefix-arg
|
(if current-prefix-arg
|
||||||
'prompt
|
'prompt
|
||||||
'interactive)))
|
'interactive)))
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
;; Ensure this temp buffer seems as much like the origin buffer as
|
;; Ensure this temp buffer seems as much like the origin buffer as
|
||||||
;; possible, in case the formatter is an elisp function, like `gofmt'.
|
;; possible, in case the formatter is an elisp function, like `gofmt'.
|
||||||
(cl-loop for (var . val)
|
(cl-loop for (var . val)
|
||||||
in (cl-remove-if-not #'listp (buffer-local-variables origin-buffer))
|
in (cl-remove-if-not #'listp (buffer-local-variables cur-buffer))
|
||||||
;; Making enable-multibyte-characters buffer-local causes an
|
;; Making enable-multibyte-characters buffer-local causes an
|
||||||
;; error.
|
;; error.
|
||||||
unless (eq var 'enable-multibyte-characters)
|
unless (eq var 'enable-multibyte-characters)
|
||||||
|
@ -45,7 +45,8 @@
|
||||||
;; restore indentation without affecting new
|
;; restore indentation without affecting new
|
||||||
;; indentation
|
;; indentation
|
||||||
(indent-rigidly (point-min) (point-max)
|
(indent-rigidly (point-min) (point-max)
|
||||||
(max 0 (- indent (+format--current-indentation))))))
|
(max 0 (- indent (+format--current-indentation)))))
|
||||||
|
(set-buffer-modified-p nil))
|
||||||
(with-current-buffer cur-buffer
|
(with-current-buffer cur-buffer
|
||||||
(delete-region start end)
|
(delete-region start end)
|
||||||
(insert-buffer-substring-no-properties formatted-buffer)
|
(insert-buffer-substring-no-properties formatted-buffer)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue