[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: recode-region.el --- correct incorrectly encoded text
From: |
Stefan Monnier |
Subject: |
Re: recode-region.el --- correct incorrectly encoded text |
Date: |
Mon, 29 Nov 2004 19:29:30 GMT |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) |
> (defun recode-string (string was-really interpreted-as)
> (decode-coding-string
> (encode-coding-string (string-make-unibyte string) interpreted-as)
^^^^^^^^^^^^^^^^^^^
> was-really))
The call to string-make-unibyte looks wrong since it throws away
information. Also encode-coding-string takes a multibyte string as input,
so I'd just use
(decode-coding-string (encode-coding-string string interpreted-as) was-really)
> (defun recode-region (start end was-really interpreted-as)
> (interactive "r
> zText was really in:
> zBut was interpreted as: ")
> (let ((the-text (buffer-substring start end)))
> (delete-region start end)
> (insert (recode-string the-text was-really interpreted-as))))
In Emacs-21, you can say:
(insert (recode-string (delete--and-extract-region start end)
was-really interpreted-as))
-- Stefan