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?

  • 2
  • The same problem occurs when copying from various text editors on OS X when the "use smart quotes" system preference is enabled. Specifically, I encountered this when copying from Evernote to a web form, which then stripped all the "smart" quote marks and apostrophes completely. The accepted answer provided a neat intermediate step to solve this.
    – TheBamf
    Aug 12, 2015 at 9:44

2 Answers 2


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

  • Thanks. But what about a function that will strip the quotes out during copy/paste? Kind of like "Paste and Match Formatting" with stripping out smart quotes. Jun 12, 2013 at 8:15
  • 2
    You can do that too, I've added an example. Don't forget to accept the answer if it solves your problem.
    – Tom
    Jun 13, 2013 at 23:45

From: https://readingworldmagazine.com/emacs/2020-02-20-emacs-enter-exit-appearance/

(defun replace-garbage-chars ()
"Replace non-rendering MS and other garbage characters with latin1 equivalents."
(save-excursion             ;save the current point
(replace-string "\221" "`" nil (point-min) (point-max))
(replace-string "\222" "'" nil (point-min) (point-max))
(replace-string "\226" "-" nil (point-min) (point-max))
(replace-string "\227" "--" nil (point-min) (point-max))
(replace-string "\223" "(" nil (point-min) (point-max))
(replace-string "\224" ")" nil (point-min) (point-max))
(replace-string "\205" "..." nil (point-min) (point-max))
(replace-string "\225" "-" nil (point-min) (point-max))
(replace-string "\344" "" nil (point-min) (point-max))
(replace-string "\374" "" nil (point-min) (point-max))
(replace-string "\337" "" nil (point-min) (point-max))
(replace-string "\366" "" nil (point-min) (point-max))
(replace-string "\247" "***" nil (point-min) (point-max))
(replace-string "\267" "****" nil (point-min) (point-max))
(replace-string "\351" " " nil (point-min) (point-max))
(replace-string "\347" " " nil (point-min) (point-max))
(replace-string "\352" " " nil (point-min) (point-max))
(replace-string "\342" " " nil (point-min) (point-max))
(replace-string "\307" " " nil (point-min) (point-max))
(replace-string "\340" " " nil (point-min) (point-max))
(replace-string "\340" " " nil (point-min) (point-max))
(replace-string "\364" " " nil (point-min) (point-max))
(replace-string "\353" " " nil (point-min) (point-max))
(replace-string "\243" " " nil (point-min) (point-max))
));end replace-garbage-characters
;bind-key replace-garbage-characters
(bind-key  "\C-cr"  'replace-garbage-chars)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.