From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 29 14:43:42 2023 Received: (at submit) by debbugs.gnu.org; 29 Oct 2023 18:43:42 +0000 Received: from localhost ([127.0.0.1]:43346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxAlC-00080p-Aa for submit@debbugs.gnu.org; Sun, 29 Oct 2023 14:43:42 -0400 Received: from lists.gnu.org ([2001:470:142::17]:39176) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxAl7-00080K-VP for submit@debbugs.gnu.org; Sun, 29 Oct 2023 14:43:38 -0400 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 1qxAkV-00014k-SF for bug-gnu-emacs@gnu.org; Sun, 29 Oct 2023 14:42:59 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxAkT-0007qy-KZ for bug-gnu-emacs@gnu.org; Sun, 29 Oct 2023 14:42:59 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 988E640005 for ; Sun, 29 Oct 2023 18:42:54 +0000 (UTC) From: Juri Linkov To: bug-gnu-emacs@gnu.org Subject: last-coding-system-used in basic-save-buffer Organization: LINKOV.NET Date: Sun, 29 Oct 2023 20:40:32 +0200 Message-ID: <86v8apv3m7.fsf_-_@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=217.70.183.194; envelope-from=juri@linkov.net; helo=relay2-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.3 (/) [Creating a separate bug report from bug#66317 since sometimes the bug occurs even when project-mode-line is nil] >> Ok, here is 100% reproducible minimal test case: >> 0. emacs-30 -Q >> 1. eval: >> (progn >> (require 'project) >> (setq project-mode-line t) >> (setq set-message-functions '(set-multi-message))) >> 2. in a temporary directory: M-! git init RET >> 3. C-x C-f .dir-locals.el RET >> 4. insert: ((fundamental-mode . ((mode . flyspell)))) >> 5. C-x C-s >> At this point even buffer-file-coding-system of .dir-locals.el >> is changed to 't' (raw-text-unix). The same happens when saving >> any file in that project. >> The problem doesn't occur when flyspell-mode is enabled from >> file-local variables, only from dir-locals. > > I can repro. But it's as weird a bug as they come. > > I guess it's a combination of using flyspell-mode and editing > .dir-locals.el? Or have you seen other buffers' b-f-c-s changed this way > too? > > If not, it might have something to do with flyspell-mode's use of > sit-for?.. But I'm only saying that because it's the only feature of this > mode that I'm regularly reminded of. > > I tried using a variable watcher: > > (add-variable-watcher > 'buffer-file-coding-system > (lambda (_sym value op where) > (message "%s %s %s" value op where) > (if (eq 'raw-text-unix value) (backtrace)) > )) > > but it just prints > > prefer-utf-8-unix set *temp*-925453 [2 times] > raw-text-unix set .dir-locals.el > backtrace() > (if (eq 'raw-text-unix value) (backtrace)) > (closure (t) (_sym value op where) (message "%s %s %s" value op where) > (if (eq 'raw-text-unix value) (backtrace)))(buffer-file-coding-system > raw-text-unix set #) > basic-save-buffer(t) > save-buffer(1) > funcall-interactively(save-buffer 1) > call-interactively(save-buffer nil nil) > command-execute(save-buffer) > > OTOH, the bug is very reliable to reproduce: add the aforementioned line to > dir-locals and save -> the coding system changes to raw-text. Delete the > line and save -> and it's prefer-utf-8 again. 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. 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': (defun project-mode-line-format () "Compose the project mode-line." (when-let ((project (project-current))) (let (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))))) 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. From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 29 15:28:15 2023 Received: (at 66825) by debbugs.gnu.org; 29 Oct 2023 19:28:15 +0000 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 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 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==; Date: Sun, 29 Oct 2023 21:27:19 +0200 Message-Id: <8334xtb560.fsf@gnu.org> From: Eli Zaretskii To: Juri Linkov In-Reply-To: <86v8apv3m7.fsf_-_@mail.linkov.net> (message from Juri Linkov on Sun, 29 Oct 2023 20:40:32 +0200) Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer References: <86v8apv3m7.fsf_-_@mail.linkov.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > 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. From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 04:10:31 2023 Received: (at 66825) by debbugs.gnu.org; 30 Oct 2023 08:10:31 +0000 Received: from localhost ([127.0.0.1]:44201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxNLy-0004ws-LB for submit@debbugs.gnu.org; Mon, 30 Oct 2023 04:10:31 -0400 Received: from relay8-d.mail.gandi.net ([2001:4b98:dc4:8::228]:59965) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxNLp-0004wH-Ra for 66825@debbugs.gnu.org; Mon, 30 Oct 2023 04:10:22 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 4386D1BF20B; Mon, 30 Oct 2023 08:09:41 +0000 (UTC) From: Juri Linkov To: Eli Zaretskii Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer In-Reply-To: <8334xtb560.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 Oct 2023 21:27:19 +0200") Organization: LINKOV.NET References: <86v8apv3m7.fsf_-_@mail.linkov.net> <8334xtb560.fsf@gnu.org> Date: Mon, 30 Oct 2023 09:56:27 +0200 Message-ID: <86bkcgy1oc.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> 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. Still it seems there is some flaw in the design when some functions change 'last-coding-system-used' intentionally, but some can change it unintentionally that causes this bug. >> 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. I don't understand this alternative. The mode line updating that uses 'project-mode-line-format' that unintentionally changes 'last-coding-system-used' is called from this line in 'basic-save-buffer-2': (write-region nil nil buffer-file-name nil t buffer-file-truename) because this call in 'write_region' updates the mode line: message_with_string ((NUMBERP (append) ? "Updated %s" : ! NILP (append) ? "Added to %s" : "Wrote %s"), visit_file, 1); >> 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. I see this detection happens in the same 'write_region': /* Decide the coding-system to encode the data with. We used to make this choice before calling build_annotations, but that leads to problems when a write-annotate-function takes care of unsavable chars (as was the case with X-Symbol). */ Vlast_coding_system_used = choose_write_coding_system (start, end, filename, append, visit, lockname, &coding); This means the value 'last-coding-system-used' should be preserved afterwards. Therefore I don't see how this could be fixed in 'basic-save-buffer' and 'write-region'. Ok, then let's fix this in 'project-mode-line-format': diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index bb44cfefa54..da89036160a 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -2074,14 +2121,17 @@ project-mode-line-format (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 original value of 'last-coding-system-used' + ;; that can break 'basic-save-buffer' (bug#66825) + (let ((last-coding-system-used nil)) + (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 From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 08:16:16 2023 Received: (at 66825) by debbugs.gnu.org; 30 Oct 2023 12:16:16 +0000 Received: from localhost ([127.0.0.1]:44460 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxRBn-0008NP-Op for submit@debbugs.gnu.org; Mon, 30 Oct 2023 08:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxRBh-0008N6-SF for 66825@debbugs.gnu.org; Mon, 30 Oct 2023 08:16:14 -0400 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 1qxRB1-0005dx-Rm; Mon, 30 Oct 2023 08:15:29 -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=JvQbHNShTwUcIXjjEXw6D8WMEsIBABOQ57XKi1ewm0U=; b=LxOINzu49GDq 2xXPn42vCfFeVrccq/klJzJrKBJgPN4OgSB6ewWhdVvVoFOEFPriGZVKB7RB1jAOoGWCSJfNUWwdP yAyY3w5/FlsHI1Eq6TKbFYiHgbn3qgGFkf2aO/rWkXgEkIVEvUXqGbXhA5NGDiDYGMyMzVojnpXls s7rBr6N5zPeB3pkoXBfgralE9FjFYURHb8fcW+vgfM8I+GrUhH4z8RJziMO9DbYNGfJaBPu/JDH4v AhRd4VCsURafQgxpwKErLXqqxlMZHaXXnhBsNCZnmAesQQj/nyoQ8oksM4GxUwgi6J7zCUPeTywjb z06zPCEd/MzJLV8GBpyBbw==; Date: Mon, 30 Oct 2023 14:15:08 +0200 Message-Id: <83wmv49uib.fsf@gnu.org> From: Eli Zaretskii To: Juri Linkov In-Reply-To: <86bkcgy1oc.fsf@mail.linkov.net> (message from Juri Linkov on Mon, 30 Oct 2023 09:56:27 +0200) Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer References: <86v8apv3m7.fsf_-_@mail.linkov.net> <8334xtb560.fsf@gnu.org> <86bkcgy1oc.fsf@mail.linkov.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Juri Linkov > Cc: 66825@debbugs.gnu.org > Date: Mon, 30 Oct 2023 09:56:27 +0200 > > I don't understand this alternative. The mode line updating > that uses 'project-mode-line-format' that unintentionally > changes 'last-coding-system-used' is called from this line > in 'basic-save-buffer-2': > > (write-region nil nil > buffer-file-name nil t buffer-file-truename) > > because this call in 'write_region' updates the mode line: > > message_with_string ((NUMBERP (append) > ? "Updated %s" > : ! NILP (append) > ? "Added to %s" > : "Wrote %s"), > visit_file, 1); How does message_with_string update the mode line? And why does last-coding-system-used get set to raw-text-unix in this scenario anyway? > + ;; Preserve the original value of 'last-coding-system-used' > + ;; that can break 'basic-save-buffer' (bug#66825) > + (let ((last-coding-system-used nil)) > + (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))))) I'm confused how this avoids the problem, probably because I don't understand the answers to the two questions above. From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 13:28:19 2023 Received: (at 66825) by debbugs.gnu.org; 30 Oct 2023 17:28:19 +0000 Received: from localhost ([127.0.0.1]:46649 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxW3m-00033T-QC for submit@debbugs.gnu.org; Mon, 30 Oct 2023 13:28:19 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:57995) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxW3g-00033B-Ls for 66825@debbugs.gnu.org; Mon, 30 Oct 2023 13:28:17 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 011FB1BF20B; Mon, 30 Oct 2023 17:27:31 +0000 (UTC) From: Juri Linkov To: Eli Zaretskii Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer In-Reply-To: <83wmv49uib.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 30 Oct 2023 14:15:08 +0200") Organization: LINKOV.NET References: <86v8apv3m7.fsf_-_@mail.linkov.net> <8334xtb560.fsf@gnu.org> <86bkcgy1oc.fsf@mail.linkov.net> <83wmv49uib.fsf@gnu.org> Date: Mon, 30 Oct 2023 19:20:19 +0200 Message-ID: <86pm0wb47g.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> I don't understand this alternative. The mode line updating >> that uses 'project-mode-line-format' that unintentionally >> changes 'last-coding-system-used' is called from this line >> in 'basic-save-buffer-2': >> >> (write-region nil nil >> buffer-file-name nil t buffer-file-truename) >> >> because this call in 'write_region' updates the mode line: >> >> message_with_string ((NUMBERP (append) >> ? "Updated %s" >> : ! NILP (append) >> ? "Added to %s" >> : "Wrote %s"), >> visit_file, 1); > > How does message_with_string update the mode line? I'm not know, some deeper function needs to update the mode line when the multi-line message resizes the echo area. > And why does last-coding-system-used get set to raw-text-unix in this > scenario anyway? Because send_process needs to set it to raw-text-unix for ispell: send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, Lisp_Object object) { Vlast_coding_system_used = CODING_ID_NAME (coding->id); Here is a backtrace: send_process process-send-string ispell-send-string ispell-buffer-local-parsing ispell-accept-buffer-local-defs flyspell-accept-buffer-local-defs flyspell--mode-on flyspell-mode hack-one-local-variable(mode flyspell) hack-local-variables-apply hack-dir-local-variables-non-file-buffer project--value-in-dir project-name project-mode-line-format eval((project-mode-line-format)) write-region basic-save-buffer-2 basic-save-buffer-1 basic-save-buffer save-buffer From debbugs-submit-bounces@debbugs.gnu.org Mon Oct 30 13:46:48 2023 Received: (at 66825) by debbugs.gnu.org; 30 Oct 2023 17:46:48 +0000 Received: from localhost ([127.0.0.1]:46661 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxWLf-0003bn-Ny for submit@debbugs.gnu.org; Mon, 30 Oct 2023 13:46:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50134) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxWLd-0003bZ-D8 for 66825@debbugs.gnu.org; Mon, 30 Oct 2023 13:46:46 -0400 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 1qxWL0-0001g2-3T; Mon, 30 Oct 2023 13:46:06 -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=DtGn17zpnAbN+YJhXheqsRxzMdZEJXZjfL0pc7sHTSU=; b=ifJRiFJ64Gov hdxte9mD5CDGCaeiIs8Jj0EAFfYcyXDfP60bB2kJ1dBPj4pvn4xXiV8IS26Nt8WXEU3BDk0p7XS6A 7hkOOiGrx18zMXVCukJdhxG67XMW+CrcRTtd8B2G4E+rIsKfSSDlBS15Tzo1AvdNPtOA/nBrSJsQA CqXqiG+UkSNKJWTp3ut5YBrP2iUwT3NbEuJnxXiX40+4B1JY7Ntnyi3s9TZ4EaBP+9PHadeb5fMyK pH6OrGC+KsR1WtOmIiA6bYQk4aq76Alt0qOxR1hwiw4ztHIYL2+rjFVbTh5rx8XY551GOp2OxIHhC utZ4ev4zb6bR8vAuacrq/w==; Date: Mon, 30 Oct 2023 19:45:53 +0200 Message-Id: <83sf5s9f72.fsf@gnu.org> From: Eli Zaretskii To: Juri Linkov In-Reply-To: <86pm0wb47g.fsf@mail.linkov.net> (message from Juri Linkov on Mon, 30 Oct 2023 19:20:19 +0200) Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer References: <86v8apv3m7.fsf_-_@mail.linkov.net> <8334xtb560.fsf@gnu.org> <86bkcgy1oc.fsf@mail.linkov.net> <83wmv49uib.fsf@gnu.org> <86pm0wb47g.fsf@mail.linkov.net> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Juri Linkov > Cc: 66825@debbugs.gnu.org > Date: Mon, 30 Oct 2023 19:20:19 +0200 > > >> message_with_string ((NUMBERP (append) > >> ? "Updated %s" > >> : ! NILP (append) > >> ? "Added to %s" > >> : "Wrote %s"), > >> visit_file, 1); > > > > How does message_with_string update the mode line? > > I'm not know, some deeper function needs to update the mode line > when the multi-line message resizes the echo area. I think it's because message_with_string eventually calls redisplay, and redisplay updates the mode line as part of its job. > > And why does last-coding-system-used get set to raw-text-unix in this > > scenario anyway? > > Because send_process needs to set it to raw-text-unix for ispell: > > send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, Lisp_Object object) > { > Vlast_coding_system_used = CODING_ID_NAME (coding->id); I think this happens because the string sent to the speller is a plain-ASCII string, and those are almost always unibyte strings. So I think the local binding of last-coding-system-used around the call to project-mode-line is TRT, it just needs a better comment to explain why it's needed. I think this should also teach us a lesson: calling arbitrary complex code from mode-line's :eval forms is in general risky business and should be avoided as much as possible. From debbugs-submit-bounces@debbugs.gnu.org Tue Oct 31 03:24:21 2023 Received: (at 66825) by debbugs.gnu.org; 31 Oct 2023 07:24:21 +0000 Received: from localhost ([127.0.0.1]:47365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxj6r-0000g7-37 for submit@debbugs.gnu.org; Tue, 31 Oct 2023 03:24:21 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:58039) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxj6p-0000fs-Ka; Tue, 31 Oct 2023 03:24:19 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 0D545E0002; Tue, 31 Oct 2023 07:23:38 +0000 (UTC) From: Juri Linkov To: Eli Zaretskii Subject: Re: bug#66825: last-coding-system-used in basic-save-buffer In-Reply-To: <83sf5s9f72.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 30 Oct 2023 19:45:53 +0200") Organization: LINKOV.NET References: <86v8apv3m7.fsf_-_@mail.linkov.net> <8334xtb560.fsf@gnu.org> <86bkcgy1oc.fsf@mail.linkov.net> <83wmv49uib.fsf@gnu.org> <86pm0wb47g.fsf@mail.linkov.net> <83sf5s9f72.fsf@gnu.org> Date: Tue, 31 Oct 2023 09:23:12 +0200 Message-ID: <86il6nuufz.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 66825 Cc: 66825@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) close 66825 30.0.50 quit > So I think the local binding of last-coding-system-used around the > call to project-mode-line is TRT, it just needs a better comment to > explain why it's needed. Ok, pushed the fix with a better comment. From unknown Wed Aug 20 05:17:24 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 28 Nov 2023 12:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator