emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/reformatter b2963f5100 23/81: Narrow to region when replac


From: ELPA Syncer
Subject: [nongnu] elpa/reformatter b2963f5100 23/81: Narrow to region when replacing contents with reformatter output
Date: Tue, 5 Sep 2023 04:03:33 -0400 (EDT)

branch: elpa/reformatter
commit b2963f51009948d5e4885237a148695008d4ccbc
Author: Steve Purcell <steve@sanityinc.com>
Commit: Steve Purcell <steve@sanityinc.com>

    Narrow to region when replacing contents with reformatter output
---
 reformatter.el | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/reformatter.el b/reformatter.el
index a481fe850a..34baedefdb 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -180,10 +180,15 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
                    (special-mode))
                  (if (eq retcode 0)
                      (progn
-                       (insert-file-contents out-file nil nil nil t)
-                       ;; In future this might be made optional, or a 
user-provided
-                       ;; ":after" form could be inserted for execution
-                       (whitespace-cleanup))
+                       (save-restriction
+                         ;; This replacement method minimises
+                         ;; disruption to marker positions and the
+                         ;; undo list
+                         (narrow-to-region beg end)
+                         (insert-file-contents out-file nil nil nil t)
+                         ;; In future this might be made optional, or a 
user-provided
+                         ;; ":after" form could be inserted for execution
+                         (whitespace-cleanup)))
                    (if display-errors
                        (display-buffer error-buffer)
                      (message ,(concat (symbol-name name) " failed: see %s") 
(buffer-name error-buffer)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]