Endless Parentheses

Concise ramblings on Emacs productivity.

Support on Gratipay
profile for Malabarba on Stack Exchange

Prettify your Apostrophes

Typography post series

Now that you’ve started your journey on the Typography Express by using round double quotes, take a seat and extend that to your apostrophes as well. This snippet binds a round apostrophe to the ' key, but also inserts a pair of single round quotes with a prefix.

Finally, like the previous one, it also falls back on self-insert-command inside a code block.

(define-key org-mode-map "'" #'endless/apostrophe)
;; (eval-after-load 'markdown-mode
;; '(define-key markdown-mode-map "'"
;; #'endless/apostrophe))

(defun endless/apostrophe (opening)
"Insert ’ in prose or `self-insert-command' in code.
With prefix argument OPENING, insert ‘’ instead and
leave point in the middle.
Inside a code-block, just call `self-insert-command'."

(interactive "P")
(if (and (derived-mode-p 'org-mode)
(org-in-block-p '("src" "latex" "html")))
(call-interactively #'self-insert-command)
(if (looking-at "['’][=_/\\*]?")
(goto-char (match-end 0))
(if (null opening)
(insert "’")
(insert "‘’")
(forward-char -1)))))

Tags: writing, keybind, org-mode, init.el, emacs

Support on Gratipay
comments powered by Disqus