[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe?
From: |
ken |
Subject: |
Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe? |
Date: |
Fri, 16 Feb 2007 11:02:23 -0500 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20061206) |
On 02/16/2007 07:44 AM somebody named Brendan Halpin wrote:
> "Endless Story" <usable.thought@gmail.com> writes:
>
>> I have just started seeing lots of nasty stuff like \222 instead of
>> apostrophes in working on text files in Emacs on XP, then trying to
>> reformat these files for LaTeX.
>
> Something like this might work:
>
> (while (re-search-forward "[-]" nil t)
> (let ((mschar (buffer-substring-no-properties
> (match-beginning 0) (match-end 0))))
> (cond
> ((string= mschar "") (replace-match "`" ))
> ((string= mschar "") (replace-match "'" ))
> ((string= mschar "") (replace-match "``"))
> ((string= mschar "") (replace-match "''"))
> ((string= mschar "") (replace-match "--")))))
>
> Obviously, the list of matches can be extended.
>
> Brendan
Thanks much for this. To make better use, I added a bit of code to the
above:
(defun replace-garbage-chars ()
"Replace goofy MS and other garbage characters with latin1 equivalents."
(interactive)
(save-excursion ;save the current point
(goto-char (point-min)) ;go to begin of buffer
(while (re-search-forward "[Â-Â]" nil t)
(let ((mschar (buffer-substring-no-properties
(match-beginning 0) (match-end 0))))
(cond
((string= mschar "Â") (replace-match "`" ))
((string= mschar "Â") (replace-match "'" ))
((string= mschar "Â") (replace-match "``"))
((string= mschar "Â") (replace-match "''"))
((string= mschar "—") (replace-match "--'"))
((string= mschar "Â") (replace-match "--")))))))
This allows, or should allow, the binding of the function to a key
chord. But something is not right. Can anyone tell where the problem
is. Running this function I get no errors, but the garbage/mschars are
not replaced.
tia,
ken
Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe?, ken, 2007/02/19