From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ken Newsgroups: gmane.emacs.help Subject: Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe? Date: Fri, 16 Feb 2007 11:02:23 -0500 Message-ID: <45D5D58F.2050900@speakeasy.net> References: <1171628373.417583.61410@k78g2000cwa.googlegroups.com> <87zm7e8e7j.fsf@wivenhoe.staff8.ul.ie> 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 1171641774 13399 80.91.229.12 (16 Feb 2007 16:02:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Feb 2007 16:02:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 16 17:02:47 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 1HI5Xn-0000ew-Ry for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Feb 2007 17:02:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HI5Xn-0003DE-IM for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Feb 2007 11:02:43 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HI5Xb-0003D9-Sd for help-gnu-emacs@gnu.org; Fri, 16 Feb 2007 11:02:31 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HI5Xa-0003Cx-9T for help-gnu-emacs@gnu.org; Fri, 16 Feb 2007 11:02:30 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HI5Xa-0003Cu-7O for help-gnu-emacs@gnu.org; Fri, 16 Feb 2007 11:02:30 -0500 Original-Received: from mail2.sea5.speakeasy.net ([69.17.117.4]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HI5XZ-00014O-FI for help-gnu-emacs@gnu.org; Fri, 16 Feb 2007 11:02:29 -0500 Original-Received: (qmail 6645 invoked from network); 16 Feb 2007 16:02:27 -0000 Original-Received: from dsl093-011-017.cle1.dsl.speakeasy.net (HELO [192.168.0.27]) (gebser@[66.93.11.17]) (envelope-sender ) by mail2.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 16 Feb 2007 16:02:27 -0000 User-Agent: Thunderbird 1.5.0.9 (X11/20061206) In-Reply-To: <87zm7e8e7j.fsf@wivenhoe.staff8.ul.ie> X-Enigmail-Version: 0.94.1.1 OpenPGP: id=45796D04 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:41257 Archived-At: On 02/16/2007 07:44 AM somebody named Brendan Halpin wrote: > "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. > > 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