unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: ken <gebser@speakeasy.net>
To: help-gnu-emacs@gnu.org
Subject: Re: How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe?
Date: Mon, 19 Feb 2007 09:17:36 -0500	[thread overview]
Message-ID: <45D9B180.2040401@speakeasy.net> (raw)
In-Reply-To: <87zm7e8e7j.fsf@wivenhoe.staff8.ul.ie>


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

The below is not textbook elisp, but it works, is easily understandable,
and so too is easy to modify and add other "characters" to.  For
example, if you have a typical set of chars which signal the beginning
of paragraph (like "\n\n"), you could insert another replace-string line
to convert that to the appropriate LaTeX (or HTML or whatever) coding
for "paragraph".  Such a set of replacements might be better organized
into a separate (but similar) function however.  Open Source == Your Choice.

(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

  parent reply	other threads:[~2007-02-19 14:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-16 12:19 How to get rid of Microsoft dumb quotes, e.g. \222 for apostrophe? Endless Story
2007-02-16 12:44 ` Brendan Halpin
2007-02-16 16:02   ` ken
2007-02-16 16:14     ` Sebastian P. Luque
2007-02-17 11:04       ` ken
     [not found]   ` <mailman.4605.1171641752.2155.help-gnu-emacs@gnu.org>
2007-02-16 16:59     ` Brendan Halpin
2007-02-16 22:22       ` ken
2007-02-17  1:47   ` Stefan Monnier
2007-02-17 12:06     ` ken
     [not found]     ` <mailman.4653.1171713988.2155.help-gnu-emacs@gnu.org>
2007-02-17 17:29       ` Stefan Monnier
2007-02-19 14:17   ` ken [this message]
2007-02-19 16:28     ` Shanks N
2007-02-19 18:48       ` ken
     [not found]   ` <mailman.4721.1171894691.2155.help-gnu-emacs@gnu.org>
2007-02-20  2:00     ` Stefan Monnier
2007-02-20 10:45       ` ken
2007-02-20 10:56         ` Juanma Barranquero
2007-02-20 12:46           ` ken
2007-02-20 13:07             ` Juanma Barranquero
2007-02-21  9:29     ` Endless Story
2007-02-16 16:22 ` Stefan Monnier
2007-02-16 17:00   ` Endless Story
2007-02-16 22:00     ` Radamanthe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45D9B180.2040401@speakeasy.net \
    --to=gebser@speakeasy.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).