From: Juri Linkov <juri@linkov.net>
Date: Tue, 31 Oct 2023 07:22:28 +0000 (+0200)
Subject: Fix project-mode-line-format breaking buffer-file-coding-system (bug#66825)
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dec79825baf9cbd07f9cf5e8533897f53c436a26;p=emacs.git

Fix project-mode-line-format breaking buffer-file-coding-system (bug#66825)

* lisp/progmodes/project.el (project-mode-line-format):
Let-bind 'last-coding-system-used' to prevent changing
'buffer-file-coding-system' in 'basic-save-buffer'.
---

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index bb44cfefa54..580394a22ed 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -2074,14 +2074,21 @@ is part of the default mode line beginning with Emacs 30."
 (defun project-mode-line-format ()
   "Compose the project mode-line."
   (when-let ((project (project-current)))
-    (concat
-     " "
-     (propertize
-      (project-name project)
-      'face project-mode-line-face
-      'mouse-face 'mode-line-highlight
-      'help-echo "mouse-1: Project menu"
-      'local-map project-mode-line-map))))
+    ;; Preserve the global value of 'last-coding-system-used'
+    ;; that 'write-region' needs to set for 'basic-save-buffer',
+    ;; but updating the mode line might occur at the same time
+    ;; during saving the buffer and 'project-name' can change
+    ;; 'last-coding-system-used' when reading the project name
+    ;; from .dir-locals.el also enables flyspell-mode (bug#66825).
+    (let ((last-coding-system-used last-coding-system-used))
+      (concat
+       " "
+       (propertize
+        (project-name project)
+        'face project-mode-line-face
+        'mouse-face 'mode-line-highlight
+        'help-echo "mouse-1: Project menu"
+        'local-map project-mode-line-map)))))
 
 (provide 'project)
 ;;; project.el ends here