From: Po Lu Date: Sat, 11 May 2024 14:24:23 +0000 (+0800) Subject: Fix test of whether to insert lexical-binding cookies in custom files X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a295bd0e804a52c94a7c1e34f045829117c47287;p=emacs.git Fix test of whether to insert lexical-binding cookies in custom files * lisp/cus-edit.el (custom-save-all): Test whether the buffer is empty, not whether point is at EOB. (cherry picked from commit 6d4179957a830fa03348c47067d9d5c1ae6e3eba) --- diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index e94c7fa2376..c3dd2ef6714 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -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