help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

changing encoding of buffer


From: M G Berberich
Subject: changing encoding of buffer
Date: Mon, 28 May 2007 12:34:47 +0200
User-agent: slrn/0.9.8.1pl2 (Debian)

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!“          | address@hidden
(SPD-Stadtrat Kurt Schindler; Regensburg)  | www.fmi.uni-passau.de/~berberic


reply via email to

[Prev in Thread] Current Thread [Next in Thread]