Subject: bug#66825: last-coding-system-used in basic-save-buffer

From: Juri Linkov <[email-masked]>
Date: Mon, 30 Oct 2023 19:20:19 +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?

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