how to remove smart quotes in copy/paste?

I'm copying text from either Google Chrome or PDFs, and pasting into Emacs.

The original text has smart quotes. I don't want smart quotes in the output.

Is there a way, either on the Copying side or on the Pasting side, to automatically strip out the smart quotes?


How about:

(defun replace-smart-quotes (beg end)
  "Replace 'smart quotes' in buffer or region with ascii quotes."
  (interactive "r")
  (format-replace-strings '(("\x201C" . "\"")
                            ("\x201D" . "\"")
                            ("\x2018" . "'")
                            ("\x2019" . "'"))
                          nil beg end))

Put that in your ~/.emacs and you should be able to use M-x replace-smart-quotes to fix all quotes in the current buffer or selected region.

To avoid restarting Emacs for the ~/.emacs change to take effect, move your cursor to the end of the defun with M-C-e and evaluate it C-x C-e.

Update re comment:

To automatically do this when yanking (pasting), you could do something like the following:

(defun yank-and-replace-smart-quotes ()
  "Yank (paste) and replace smart quotes from the source with ascii quotes."
  (interactive)
  (yank)
  (replace-smart-quotes (mark) (point)))

If you then want to do that when you hit C-y, you can bind it using:

(global-set-key (kbd "C-y") 'yank-and-replace-smart-quotes)

It's probably a better idea to use another key however (maybe C-c y) as this will use some of the default yank functionality.