On 2018-10-23 22:31, Nuno Silva wrote: > So far I did not find a way to change this on the mutt side, but I made > a new major mode for mutt messages in Emacs (the editor I use with > mutt), with a hook that changes the file encoding to latin1 if the file > was opened in a latin1 terminal and Emacs cannot detect a non-ASCII file > encoding. > > It appears to work here. I'm sure someone who is more versed in Emacs > than me would be able to come up with a more elegant solution, but I'm > sharing mine here just in case it is useful to somebody else someday: > > (define-derived-mode my-mutt-message-mode message-mode "MuttMSG") > (add-hook > 'my-mutt-message-mode-hook > (lambda () > (when (equal (terminal-coding-system) 'iso-latin-1-unix) > (let ((encoding (detect-coding-region (point-min) (point-max)))) > (when (or > (equal encoding '(undecided-unix)) > (equal encoding '(undecided))) > (setq buffer-file-coding-system 'iso-latin-1-unix)))))) > (add-to-list 'auto-mode-alist '("/mutt" . my-mutt-message-mode))
You could just hook message-mode-hook with a function that checks buffer-file-name, I think that would be a bit more straightforward than adding a new mode. Other possibilities: you could handle this still in Emacs, but after you finish writing, at the point you save the temporary file (with one of the write hooks). Or you can write a script that runs Emacs and then recodes the file outside of Emacs, using something like iconv(1). -- Please don't Cc: me privately on mailing lists and Usenet, if you also post the followup to the list or newsgroup. To reply privately _only_ on Usenet and on broken lists which rewrite From, fetch the TXT record for no-use.mooo.com.