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

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

[nongnu] elpa/reformatter 0da7241ca2 34/81: Actually check for broken re


From: ELPA Syncer
Subject: [nongnu] elpa/reformatter 0da7241ca2 34/81: Actually check for broken replace-buffer-contents
Date: Tue, 5 Sep 2023 04:03:34 -0400 (EDT)

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

    Actually check for broken replace-buffer-contents
    
    It's possible that 27.0.x versions of Emacs might contain the same
    broken implementation as 26.1, so it's best to avoid relying on the
    Emacs version.
    
    See https://github.com/jcollard/elm-mode/issues/156
---
 reformatter.el | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/reformatter.el b/reformatter.el
index 74cbd7a761..7bccaa4884 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -212,19 +212,27 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
 
        ,minor-mode-form)))
 
+(defconst reformatter--can-use-replace-buffer-contents
+  (when (fboundp 'replace-buffer-contents)
+    (with-temp-buffer
+      (insert "\u2666\nabc\n")
+      (let ((a (current-buffer)))
+        (with-temp-buffer
+          (insert "\u2666\naXbc\n")
+          (replace-buffer-contents a)
+          (string= (buffer-string) "\u2666\nabc\n")))))
+  "Non-nil if we have a working version of `replace-buffer-contents' in this 
Emacs.")
+
 (defun reformatter-replace-buffer-contents-from-file (file)
   "Replace the accessible portion of the current buffer with the contents of 
FILE."
-  (if (and (fboundp 'replace-buffer-contents)
-           ;; The initial version of `replace-buffer-contents' in 26.1 was 
very broken
-           (version<= "26.2" emacs-version))
-      (progn
-        (let ((tmp (generate-new-buffer " *temp*")))
-          (unwind-protect
-              (progn
-                (with-current-buffer tmp
-                  (insert-file-contents file nil nil nil t))
-                (replace-buffer-contents tmp))
-            (kill-buffer tmp))))
+  (if reformatter--can-use-replace-buffer-contents
+      (let ((tmp (generate-new-buffer " *temp*")))
+        (unwind-protect
+            (progn
+              (with-current-buffer tmp
+                (insert-file-contents file nil nil nil t))
+              (replace-buffer-contents tmp))
+          (kill-buffer tmp)))
     (insert-file-contents file nil nil nil t)))
 
 



reply via email to

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