unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* changing encoding of buffer
@ 2007-05-28 10:34 M G Berberich
  2007-05-28 20:21 ` Eli Zaretskii
       [not found] ` <mailman.1365.1180383723.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: M G Berberich @ 2007-05-28 10:34 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I have a newsreader that conforms to the standard and assumes ansi
encoding if none is declared. Microsoft does'n care about standards so
MS-products produce postings that are encoded in windows-125* without
a declaration. A real problem in non-englisch-speaking countries.

When I reply, my newsreader appends my UTF-8 signature and starts
emacs. Emacs reads the file and sets the coding-system to latin1,
displaying the posting correctly but garbling up my signature and
worse saving it as latin1 while the newsreader expects UTF-8.

I wrote this function to solve the problem:

(defun fix-ms-posting ()
  "Fixes newsposting that are garbled up by Microsoft-Software"
  (interactive)
  (let ((coding-system-for-write 'raw-text)
	(coding-system-for-read 'utf-8)
	(end (progn (end-of-buffer) (search-backward "\n-- \n"))))
    (revert-buffer-with-coding-system 'utf-8)
    (set-buffer-file-coding-system 'utf-8)
    (shell-command-on-region (point-min) end 
			     "recode windows-1252..utf-8" nil t)))

- Is there realy no other way to change the encoding of the buffer
  than doing a revert? Can't this be done in-place?

- revert-buffer-with-coding-system always ask if it should do so, can
  this be switched off?

- I moved the search-backward to the variables list of let to make it
  fail before harm is done if there is no signature. Is this the way
  to do it?

MfG
bmg

-- 
„Des is völlig wurscht, was heut beschlos- | M G Berberich
 sen wird: I bin sowieso dagegn!“          | berberic@fmi.uni-passau.de
(SPD-Stadtrat Kurt Schindler; Regensburg)  | www.fmi.uni-passau.de/~berberic

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-05-31 18:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-28 10:34 changing encoding of buffer M G Berberich
2007-05-28 20:21 ` Eli Zaretskii
     [not found] ` <mailman.1365.1180383723.32220.help-gnu-emacs@gnu.org>
2007-05-29 12:39   ` M G Berberich
2007-05-29 19:52     ` Eli Zaretskii
     [not found]     ` <mailman.1402.1180468336.32220.help-gnu-emacs@gnu.org>
2007-05-29 21:06       ` M G Berberich
2007-05-30  3:22         ` Eli Zaretskii
     [not found]         ` <mailman.1416.1180495357.32220.help-gnu-emacs@gnu.org>
2007-05-30  7:35           ` M G Berberich
2007-05-31 18:19       ` Giorgos Keramidas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).