jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
276 stars 57 forks source link

Encoding prompt when creating HTML preview on Windows #112

Open morganwillcock opened 3 years ago

morganwillcock commented 3 years ago

When previewing a message on Windows it looks like the default text encoding can cause an encoding selection prompt to appear in the minibuffer. It is triggered by (write-file tmp-file) and displays the message:

These default coding systems were tried to encode text
in the buffer ‘org-msgrMOr2L.html’:
  (iso-latin-1-dos (9437 . 8211) (11129 . 8211) (12201 . 8217) (12393
  . 8217) (15096 . 8217) (16090 . 8211) (16111 . 8211) (16208 . 8211)
  (16231 . 8211) (23240 . 8211) (23261 . 8211))
However, each of them encountered characters it couldn’t encode:
  iso-latin-1-dos cannot encode these: – – ’ ’ ’ – – – – – ...

Click on a character (or switch to this window by ‘C-x o’
and select the characters by RET) to jump to the place it appears,
where ‘C-u C-x =’ will give information about it.

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  utf-8 big5 euc-jis-2004 euc-tw windows-1256 windows-1258 cp874
  iso-2022-jp-2004 windows-1255 windows-1253 adobe-standard-encoding
  next macintosh windows-1257 windows-1254 windows-1252 windows-1250
  windows-1251 koi8-t gb18030 gbk big5-hkscs utf-7 utf-16
  utf-16be-with-signature utf-16le-with-signature utf-16be utf-16le
  iso-2022-7bit utf-8-auto utf-8-with-signature georgian-academy
  georgian-ps japanese-shift-jis-2004 pt154 utf-7-imap utf-8-emacs
  prefer-utf-8

utf-8 is the default choice at the prompt and selecting it lets everything proceed as normal, but presumably something needs to set a compatible encoding before write-file is called to cover the case where the default encoding is not compatible?

obar commented 3 years ago

What do you see when you run C-h C RET? You probably want to change your default from iso-latin-1.

morganwillcock commented 3 years ago

It is using iso-latin-1:

Coding system for saving this buffer:
  Not set locally, use the default.
Default coding system (for new files):
  1 -- iso-latin-1-dos (alias: iso-8859-1-dos latin-1-dos)

But to my mind the default shouldn't have to be changed to accommodate saving a buffer that is created and edited by a package rather than by the user.

obar commented 3 years ago

For outputs that can be represented in iso-latin-1 I don't think you'd see that prompt. To me this seems like the correct behavior: the user wants a specific encoding to be used per their config, and when the output has characters that can't be encoded that way, the user is both shown the unrepresentable characters and is prompted for a different option. Is there anything inherently utf about email that the encoding should be forced by this package, ignoring the user preferences?

morganwillcock commented 3 years ago

I think we'll have to agree to disagree. I wouldn't say that the default encoding is meant to force all output to comply with that encoding or prompt the user. Other packages (such as Org mode) will create utf-8 buffers and write utf-8 encoded files without any prompts.

obar commented 3 years ago

That's a fair point, I didn't realize that org is doing its own thing with org-html-coding-system and assumed they were respecting the emacs default. Maybe it would make sense to make a similar defcustom for org-msg. @jeremy-compostella would you accept a pull request with that?