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

[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: Shanks N
Subject: Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe?
Date: Mon, 19 Feb 2007 21:58:17 +0530
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (windows-nt)

ken <gebser@speakeasy.net> writes:

>> "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. 
>> 
>> ....
>

[...]

> (defun replace-garbage-chars ()
> "Replace goofy MS and other garbage characters with latin1 equivalents."
> (interactive)
> (save-excursion                               ;save the current point
>   (replace-string "—" "--" nil (point-min) (point-max)) ; multi-byte
>   (replace-string "‘" "`" nil (point-min) (point-max))
>   (replace-string "’" "'" nil (point-min) (point-max))
>   (replace-string "“" "``" nil (point-min) (point-max))
>   (replace-string "”" "''" nil (point-min) (point-max))
>   (replace-string "–" "--" nil (point-min) (point-max))
> ))
>
> Note that chars/strings within the first set of double-quotes in each
> pair of replace-string args appear in emacs as, e.g., "\221".  To enter
> these escaped numbers, e.g. "\221", do C-q 2 2 1 RETURN.
>
> Also, multi-byte strings such as the first should be toward
> the top of the list so that single-byte replacements don't
> cut them up, making subsequent searches for them impossible.
>
> To discover the code for a new (garbage) char to be replaced,
> put the point over it and do "C-x="; the first code returned in
> the minibuffer tells you the escaped number you want to replace.
>
> With this function in a file in directory in the emacs path and this in
> my ~/.emacs:
>
> (global-set-key "\C-cr" 'replace-garbage-chars)
>
> doing C-cr in an emacs buffer performs the replacements without moving
> the point... exactly what I was looking for.
>
>
> Enjoy,
> ken

Can this or one of the other solutions on this thread be posted on the
emacwiki site, if you have the time?  It'd help others.

regards,
Shanks

-- 





reply via email to

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