diff --git a/lisp/org-entities.el b/lisp/org-entities.el index 8b5b3f3..ee54abc 100644 --- a/lisp/org-entities.el +++ b/lisp/org-entities.el @@ -47,6 +47,14 @@ in backends where the corresponding character is not available." :version "24.1" :type 'boolean) +(defcustom org-smart-quotes nil + "Non-nil means display ' and \" characters as Unicode \"smart\" quotes. +Org-mode will try to figure out if a quote character is opening or closing. + +Note: this does not affect export, only on-screen appearance." + :group 'org-entities + :type 'boolean) + (defcustom org-entities-user nil "User-defined entities used in Org-mode to produce special characters. Each entry in this list is a list of strings. It associates the name diff --git a/lisp/org.el b/lisp/org.el index 05f5375..213490e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5926,6 +5926,7 @@ needs to be inserted at a specific position in the font-lock sequence.") '(1 'org-archived prepend)) ;; Specials '(org-do-latex-and-special-faces) + '(org-smartify-quotes) '(org-fontify-entities) '(org-raise-scripts) ;; Code @@ -5948,6 +5949,33 @@ needs to be inserted at a specific position in the font-lock sequence.") '(org-font-lock-keywords t nil nil backward-paragraph)) (kill-local-variable 'font-lock-keywords) nil)) +(defconst org-smart-quotes-regex + ;; ' is a word character, " is punctuation. + "\\(\"\\<\\)\\|\\>\\s.*\\(\"\\)\\|\\(?:\\W\\|^\\)\\('\\)\\|\\w\\s.*\\('\\)") + + +(defun org-smartify-quotes (limit) + "Make 'smart quotes' out of straight quotes." + (let* (start end subst k) + (when org-smart-quotes + (catch 'match + (while (re-search-forward org-smart-quotes-regex + limit t) + (cond ((match-string 1) + (setq k 1 subst "“")) + ((match-string 2) + (setq k 2 subst "”")) + ((match-string 3) + (setq k 3 subst "‘")) + ((match-string 4) + (setq k 4 subst "’"))) + (add-text-properties (match-beginning k) (match-end k) + (list 'font-lock-fontified t)) + (compose-region (match-beginning k) (match-end k) subst nil) + (backward-char 1) + (throw 'match t)) + nil)))) + (defun org-toggle-pretty-entities () "Toggle the composition display of entities as UTF8 characters." (interactive)