[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode ef92acd96c 453/500: nix-format.el: Use replace-bu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode ef92acd96c 453/500: nix-format.el: Use replace-buffer-contents when available |
Date: |
Sat, 29 Jan 2022 08:27:55 -0500 (EST) |
branch: elpa/nix-mode
commit ef92acd96cce9ac5de3c5afc54b82c3f43c38f9f
Author: Aaron L. Zeng <me@bcc32.com>
Commit: Aaron L. Zeng <me@bcc32.com>
nix-format.el: Use replace-buffer-contents when available
`replace-buffer-contents`, introduced in Emacs 26.1, allows a buffer's
contents to be overwritten with another buffer's contents, but leaving
the destination buffer's state intact (point, scrolling, etc.). It
relocates point intelligently, and is designed precisely to be used
with reformatting functions like this.
---
nix-format.el | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/nix-format.el b/nix-format.el
index 1f97e8a086..8d66f88f8b 100644
--- a/nix-format.el
+++ b/nix-format.el
@@ -13,16 +13,22 @@
:group 'nix
:type 'string)
+(if (fboundp 'replace-buffer-contents)
+ (defun nix--replace-buffer-contents (src dst)
+ (with-current-buffer dst (replace-buffer-contents src)))
+ (defun nix--replace-buffer-contents (src dst)
+ (if (not (string= (with-current-buffer src (buffer-string))
+ (with-current-buffer dst (buffer-string))))
+ (with-current-buffer src
+ (copy-to-buffer dst (point-min) (point-max))))))
+
(defun nix--format-call (buf nixfmt-bin)
"Format BUF using nixfmt."
(with-current-buffer (get-buffer-create "*nixfmt*")
(erase-buffer)
(insert-buffer-substring buf)
(if (zerop (call-process-region (point-min) (point-max) nixfmt-bin t t
nil))
- (progn
- (if (not (string= (buffer-string) (with-current-buffer buf
(buffer-string))))
- (copy-to-buffer buf (point-min) (point-max)))
- (kill-buffer))
+ (nix--replace-buffer-contents (current-buffer) buf)
(error "Nixfmt failed, see *nixfmt* buffer for details"))))
(defun nix--find-nixfmt ()
- [nongnu] elpa/nix-mode d1ee0e1741 416/500: Use javascript-mode for nix-drv-mode, (continued)
- [nongnu] elpa/nix-mode d1ee0e1741 416/500: Use javascript-mode for nix-drv-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0cf1ea1e0e 390/500: Don’t pare nix completions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 25cd13349f 445/500: Linkify `nix-mode.org` in Readme, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c29b11b647 443/500: Add Package-Requires for dependency on "f", ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e4844f7a71 438/500: Fix nix-system in nix-2.4, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c016c5503d 473/500: nix-flake: Reuse the last flake when two C-u is given, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c2d96ced52 447/500: Fix wrong documentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1ac42cd103 465/500: Update lock file, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1789c83b83 454/500: nix-format.el: Properly escape string in error message, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e645310c88 458/500: Introduce `nix-store-show-path` command, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ef92acd96c 453/500: nix-format.el: Use replace-buffer-contents when available,
ELPA Syncer <=
- [nongnu] elpa/nix-mode ed00d8dff2 463/500: nix.el: Fix for Nix 2.5, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 327175e768 460/500: Merge pull request #138 from phikal/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b1257d3ea6 461/500: Merge branch 'master' into store-path, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ae1f5253be 478/500: nix-flake: Add documentation to README, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9d8dc3c8d8 495/500: Merge pull request #143 from akirak/fix-flake-switching, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e7bf2e4cc4 489/500: Merge pull request #140 from akirak/flake-transient, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1f922d78eb 291/500: Fix regex regression that caused the indent to indent too much, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9ebf7389eb 298/500: Merge branch 'etu-fix-issue-72', ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d5a53e2050 300/500: Indent using SMIE - initial working version., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8118355e81 306/500: Change smie indent functions in a cleaner (and correct) way., ELPA Syncer, 2022/01/29