From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Shanks N Newsgroups: gmane.emacs.help Subject: Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe? Date: Mon, 19 Feb 2007 21:58:17 +0530 Message-ID: References: <1171628373.417583.61410@k78g2000cwa.googlegroups.com> <87zm7e8e7j.fsf@wivenhoe.staff8.ul.ie> <45D9B180.2040401@speakeasy.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1171902562 11330 80.91.229.12 (19 Feb 2007 16:29:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 19 Feb 2007 16:29:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 19 17:29:16 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HJBO1-00039o-3T for geh-help-gnu-emacs@m.gmane.org; Mon, 19 Feb 2007 17:29:09 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HJBO0-0000ap-F2 for geh-help-gnu-emacs@m.gmane.org; Mon, 19 Feb 2007 11:29:08 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HJBNm-0000aZ-KU for help-gnu-emacs@gnu.org; Mon, 19 Feb 2007 11:28:54 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HJBNk-0000aN-8c for help-gnu-emacs@gnu.org; Mon, 19 Feb 2007 11:28:53 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HJBNk-0000aK-47 for help-gnu-emacs@gnu.org; Mon, 19 Feb 2007 11:28:52 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HJBNj-0003Lh-MO for help-gnu-emacs@gnu.org; Mon, 19 Feb 2007 11:28:51 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HJBNJ-0004aR-My for help-gnu-emacs@gnu.org; Mon, 19 Feb 2007 17:28:25 +0100 Original-Received: from 59.92.140.71 ([59.92.140.71]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 19 Feb 2007 17:28:25 +0100 Original-Received: from shanks.n by 59.92.140.71 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 19 Feb 2007 17:28:25 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 56 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 59.92.140.71 User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:EjmgZb56wjO87XZnOAxGWOc44iI= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:41316 Archived-At: ken writes: >> "Endless Story" 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 --