3

For a given document (buffer), I would like use left double quotation mark (U+201C) and right double quotation mark (U+201D) instead of the ordinary double quote " (U+0022). I want to surround strings and sentences with these, and I want to do it as effortless as possible.

I post my first attempt as an answer below, since it works somehow..

Is this a recommended approach? I am looking for feedback and alternatives.

  • 3
    In emacs 25, C-x 8 { and C-x 8 } will insert those. – Kaushal Modi Jul 18 '15 at 15:23
2

Typoel will insert the appropriate quotes for you. From its README.md:

“He said, ‘leave me alone,’ and closed the door.”

All quotation marks in this sentence were added by hitting the " key exactly once each. typo.el guessed the correct glyphs to use from context. If it gets it wrong, you can just repeat hitting the " key until you get the quotation mark you wanted.

1

As an option, Emacs 25 has electric-quote-mode. See documentation for the function for more information. In short, it replaces ``something'' with “something” on the fly.


I don't use this, I have my own hacks to insert any character I want in 5 key stokes or so, including ◊≡∫∑«» any symbols and quotes. For quotes it even has wrapping functionality and other nifty tricks. This is not distributed as a package and I don't know if you're interested in such a solution.

0

The following seems to work somehow. When pressing " the function determines which of the two types it should insert.

;; Insert quotes “ and ”
(defun my-insert-quote ()
  (interactive)
  (let ((char (preceding-char)))
    (if (or (char-equal char 0)
            (char-equal char ?\s)
            (char-equal char ?\n)
            (char-equal char ?\t))
        (insert "“")
      (insert "”"))))

(global-set-key (kbd "\"") #'my-insert-quote)

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.