]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix test of whether to insert lexical-binding cookies in custom files
authorPo Lu <luangruo@yahoo.com>
Sat, 11 May 2024 14:24:23 +0000 (22:24 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sun, 12 May 2024 15:49:16 +0000 (17:49 +0200)
* lisp/cus-edit.el (custom-save-all): Test whether the buffer is
empty, not whether point is at EOB.

(cherry picked from commit 6d4179957a830fa03348c47067d9d5c1ae6e3eba)

lisp/cus-edit.el

index e94c7fa2376e08269486c2db555d4da31e074c64..c3dd2ef67148ce4292dbd2e629bb63d2b56feed5 100644 (file)
@@ -4995,12 +4995,20 @@ if only the first line of the docstring is shown."))
             ;; can cause problems when read back, so print them
             ;; readably.  (Bug#52554)
             (print-escape-control-characters t))
-        (atomic-change-group
-          (when (eobp)
-            (insert ";;; -*- lexical-binding: t -*-\n"))
-         (custom-save-variables)
-         (custom-save-faces)
-          (custom-save-icons)))
+        (save-restriction
+          (widen)
+          (atomic-change-group
+            ;; The previous test `eobp' was written with an appalling
+            ;; lack of forethought or testing, being easily misled if
+            ;; the user should have left point at eob in a buffer
+            ;; visiting the custom file.
+            (when (eq (point-min) (point-max))
+              (save-excursion
+                (goto-char (point-min))
+                (insert ";;; -*- lexical-binding: t -*-\n")))
+           (custom-save-variables)
+           (custom-save-faces)
+            (custom-save-icons))))
       (let ((file-precious-flag t))
        (save-buffer))
       (if old-buffer