From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#66825: last-coding-system-used in basic-save-buffer Date: Sun, 29 Oct 2023 21:27:19 +0200 Message-ID: <8334xtb560.fsf@gnu.org> References: <86v8apv3m7.fsf_-_@mail.linkov.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12573"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 66825@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 29 20:28:44 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qxBSm-00034o-P4 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 Oct 2023 20:28:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxBSe-000891-Tu; Sun, 29 Oct 2023 15:28:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxBSX-00088f-UJ for bug-gnu-emacs@gnu.org; Sun, 29 Oct 2023 15:28:30 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxBSX-0007It-MJ for bug-gnu-emacs@gnu.org; Sun, 29 Oct 2023 15:28:29 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qxBT4-0000wc-BK for bug-gnu-emacs@gnu.org; Sun, 29 Oct 2023 15:29:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Oct 2023 19:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66825 X-GNU-PR-Package: emacs Original-Received: via spool by 66825-submit@debbugs.gnu.org id=B66825.16986076953554 (code B ref 66825); Sun, 29 Oct 2023 19:29:02 +0000 Original-Received: (at 66825) by debbugs.gnu.org; 29 Oct 2023 19:28:15 +0000 Original-Received: from localhost ([127.0.0.1]:43396 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxBSJ-0000vG-G2 for submit@debbugs.gnu.org; Sun, 29 Oct 2023 15:28:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxBSH-0000v1-SR for 66825@debbugs.gnu.org; Sun, 29 Oct 2023 15:28:14 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxBRf-0007Ef-2t; Sun, 29 Oct 2023 15:27:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=0lQKF4QN97IV7gzErEIpXTfjGtHAIUunuD73qZ10esk=; b=aLQFv8zU+M4b qEyMEcVf6UblfB157oRQ/ITnlJwaDlTYLP9xqqpFregDJRc41ASg+wl9bUZBP9XwdufRGdg6VLPvA QFFp2zQI1qPRBIJH0s3NirJ/6uYLXff7/Q3DykruHCddQ47lxtcQEOfLJs2XryzP8zvUezA1grXAr jkf+/j7S1Ly2dZa3iSWYbxW/ot3ezAWaYP8ilYei1jQlN/bRyZ92odmx2uiAmmxhSETzJHwJ479Uk NjSfIYGXE9ssg9d/eBVkrSDEEjRGKiknS11Nqvu8boucETWEjdqKCuRn/yNJczGOlCfJuKycNFsSo sL4k3vPTVpeeXzFgiuOSNw==; In-Reply-To: <86v8apv3m7.fsf_-_@mail.linkov.net> (message from Juri Linkov on Sun, 29 Oct 2023 20:40:32 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273526 Archived-At: > From: Juri Linkov > Date: Sun, 29 Oct 2023 20:40:32 +0200 > > Indeed, the problem is in basic-save-buffer on the following line: > > (setq buffer-file-coding-system last-coding-system-used) > > It's hard to guess why this code relies on the value that > can be changed by other functions during saving the buffer. Because this is the protocol: functions that determine the encoding of buffer text dynamically set this variable, so it could later be used to reflect the detection in buffer-file-coding-system. > For example, > > (progn > (setq last-coding-system-used 'prefer-utf-8-unix) > (project-name (project-current)) > (message "%S" last-coding-system-used)) > > prints "raw-text-unix" because it enables 'flyspell-mode' > that calls: > > (defun ispell-buffer-local-parsing () > (ispell-send-string "!\n") > > where 'process-send-string' changes 'last-coding-system-used' > to "raw-text-unix" in: > > send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, > Lisp_Object object) > { > ... > Vlast_coding_system_used = CODING_ID_NAME (coding->id); > > A possible workaround would be to protect the value of > last-coding-system-used in 'project-mode-line-format': That's not a workaround, that's what we should do in such cases. Alternatively, the "important" setting of last-coding-system-used should be done later, after the inner functions already returned. > However, I noticed that occasionally this bug occurs even > when this function is not used. So the proper fix needed > in 'basic-save-buffer', but I don't know if it's intended > that some function should change 'last-coding-system-used' > during saving the buffer. Yes, it's intended: saving the buffer can change buffer-file-coding-system if it detects characters which cannot be encoded by the original buffer-file-coding-system.